Class: MCPClient::ServerBase
- Inherits:
-
Object
- Object
- MCPClient::ServerBase
- Defined in:
- lib/mcp_client/server_base.rb
Overview
Base class for MCP servers - serves as the interface for different server implementations
Direct Known Subclasses
Instance Method Summary collapse
-
#call_tool(tool_name, parameters) ⇒ Object
Call a tool with the given parameters.
-
#cleanup ⇒ Object
Clean up the server connection.
-
#connect ⇒ Boolean
Initialize a connection to the MCP server.
-
#list_tools ⇒ Array<MCPClient::Tool>
List all tools available from the MCP server.
-
#on_notification {|method, params| ... } ⇒ void
Register a callback to receive JSON-RPC notifications.
-
#ping(params = {}) ⇒ Object
Ping the MCP server to check connectivity.
-
#rpc_notify(method, params = {}) ⇒ void
Send a JSON-RPC notification (no response expected).
-
#rpc_request(method, params = {}) ⇒ Object
Send a JSON-RPC request and return the result.
Instance Method Details
#call_tool(tool_name, parameters) ⇒ Object
Call a tool with the given parameters
22 23 24 |
# File 'lib/mcp_client/server_base.rb', line 22 def call_tool(tool_name, parameters) raise NotImplementedError, 'Subclasses must implement call_tool' end |
#cleanup ⇒ Object
Clean up the server connection
27 28 29 |
# File 'lib/mcp_client/server_base.rb', line 27 def cleanup raise NotImplementedError, 'Subclasses must implement cleanup' end |
#connect ⇒ Boolean
Initialize a connection to the MCP server
8 9 10 |
# File 'lib/mcp_client/server_base.rb', line 8 def connect raise NotImplementedError, 'Subclasses must implement connect' end |
#list_tools ⇒ Array<MCPClient::Tool>
List all tools available from the MCP server
14 15 16 |
# File 'lib/mcp_client/server_base.rb', line 14 def list_tools raise NotImplementedError, 'Subclasses must implement list_tools' end |
#on_notification {|method, params| ... } ⇒ void
This method returns an undefined value.
Register a callback to receive JSON-RPC notifications
58 59 60 |
# File 'lib/mcp_client/server_base.rb', line 58 def on_notification(&block) @notification_callback = block end |
#ping(params = {}) ⇒ Object
Ping the MCP server to check connectivity
51 52 53 |
# File 'lib/mcp_client/server_base.rb', line 51 def ping(params = {}) rpc_request('ping', params) end |
#rpc_notify(method, params = {}) ⇒ void
This method returns an undefined value.
Send a JSON-RPC notification (no response expected)
44 45 46 |
# File 'lib/mcp_client/server_base.rb', line 44 def rpc_notify(method, params = {}) raise NotImplementedError, 'Subclasses must implement rpc_notify' end |
#rpc_request(method, params = {}) ⇒ Object
Send a JSON-RPC request and return the result
36 37 38 |
# File 'lib/mcp_client/server_base.rb', line 36 def rpc_request(method, params = {}) raise NotImplementedError, 'Subclasses must implement rpc_request' end |