Class: MCPClient::ServerHTTP
- Inherits:
-
ServerBase
- Object
- ServerBase
- MCPClient::ServerHTTP
- Defined in:
- lib/mcp_client/server_http.rb
Overview
Implementation of MCP server over HTTP JSON-RPC
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#retry_backoff ⇒ Object
readonly
Returns the value of attribute retry_backoff.
Instance Method Summary collapse
-
#call_tool(tool_name, parameters) ⇒ Object
Call a tool with given parameters.
-
#call_tool_streaming(tool_name, parameters) ⇒ Enumerator
Streaming is not supported over simple HTTP transport; fallback to single response.
-
#initialize(base_url:, headers: {}, read_timeout: 30, retries: 0, retry_backoff: 1, logger: nil) ⇒ ServerHTTP
constructor
A new instance of ServerHTTP.
-
#list_tools ⇒ Array<MCPClient::Tool>
List available tools.
Methods inherited from ServerBase
Constructor Details
#initialize(base_url:, headers: {}, read_timeout: 30, retries: 0, retry_backoff: 1, logger: nil) ⇒ ServerHTTP
Returns a new instance of ServerHTTP.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mcp_client/server_http.rb', line 20 def initialize(base_url:, headers: {}, read_timeout: 30, retries: 0, retry_backoff: 1, logger: nil) super() @base_url = base_url @headers = headers @read_timeout = read_timeout @max_retries = retries @retry_backoff = retry_backoff @logger = logger || Logger.new($stdout, level: Logger::WARN) @request_id = 0 end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
12 13 14 |
# File 'lib/mcp_client/server_http.rb', line 12 def base_url @base_url end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/mcp_client/server_http.rb', line 12 def headers @headers end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/mcp_client/server_http.rb', line 12 def logger @logger end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
12 13 14 |
# File 'lib/mcp_client/server_http.rb', line 12 def max_retries @max_retries end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
12 13 14 |
# File 'lib/mcp_client/server_http.rb', line 12 def read_timeout @read_timeout end |
#retry_backoff ⇒ Object (readonly)
Returns the value of attribute retry_backoff.
12 13 14 |
# File 'lib/mcp_client/server_http.rb', line 12 def retry_backoff @retry_backoff end |
Instance Method Details
#call_tool(tool_name, parameters) ⇒ Object
Call a tool with given parameters
47 48 49 50 51 52 53 54 |
# File 'lib/mcp_client/server_http.rb', line 47 def call_tool(tool_name, parameters) request_json = jsonrpc_request('tools/call', { 'name' => tool_name, 'arguments' => parameters }) send_request(request_json) rescue MCPClient::Errors::MCPError raise rescue StandardError => e raise MCPClient::Errors::ToolCallError, "Error calling tool '#{tool_name}': #{e.}" end |
#call_tool_streaming(tool_name, parameters) ⇒ Enumerator
Streaming is not supported over simple HTTP transport; fallback to single response
60 61 62 63 64 |
# File 'lib/mcp_client/server_http.rb', line 60 def call_tool_streaming(tool_name, parameters) Enumerator.new do |yielder| yielder << call_tool(tool_name, parameters) end end |
#list_tools ⇒ Array<MCPClient::Tool>
List available tools
33 34 35 36 37 38 39 40 41 |
# File 'lib/mcp_client/server_http.rb', line 33 def list_tools request_json = jsonrpc_request('tools/list', {}) result = send_request(request_json) (result['tools'] || []).map { |td| MCPClient::Tool.from_json(td) } rescue MCPClient::Errors::MCPError raise rescue StandardError => e raise MCPClient::Errors::ToolCallError, "Error listing tools: #{e.}" end |