Class: McpToolkit::Gateway::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_toolkit/gateway/proxy.rb

Overview

Proxies a namespaced upstream tool call (<app>__<tool>) to its upstream MCP server.

The account selector is forwarded as _meta[config.account_meta_key] when an account_id is supplied. The caller passes the already-resolved account id (a scalar), not a domain object — resolving the tenant is the consumer's job.

Error mapping is deliberately thin and transport-agnostic:

* an unregistered `app_key` raises McpToolkit::Gateway::UnknownUpstream;
* an upstream call failure is re-raised as McpToolkit::Gateway::UpstreamCallError
carrying the upstream's `jsonrpc_error` / `http_status`.

Neither is mapped to a JSON-RPC/protocol error class here — the consuming dispatcher does that at its call site.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_key:, tool_name:, account_id: nil, bearer_token: nil, config: McpToolkit.config) ⇒ Proxy

Returns a new instance of Proxy.



19
20
21
22
23
24
25
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 19

def initialize(app_key:, tool_name:, account_id: nil, bearer_token: nil, config: McpToolkit.config)
  @app_key = app_key
  @tool_name = tool_name
  @account_id = 
  @bearer_token = bearer_token
  @config = config
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



17
18
19
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 17

def 
  @account_id
end

#app_keyObject (readonly)

Returns the value of attribute app_key.



17
18
19
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 17

def app_key
  @app_key
end

#bearer_tokenObject (readonly)

Returns the value of attribute bearer_token.



17
18
19
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 17

def bearer_token
  @bearer_token
end

#configObject (readonly)

Returns the value of attribute config.



17
18
19
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 17

def config
  @config
end

#tool_nameObject (readonly)

Returns the value of attribute tool_name.



17
18
19
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 17

def tool_name
  @tool_name
end

Instance Method Details

#call(arguments) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 27

def call(arguments)
  upstream = config.upstreams.find(app_key)
  raise McpToolkit::Gateway::UnknownUpstream, "Unknown application: #{app_key}" if upstream.nil?

  client = McpToolkit::Gateway::Client.new(upstream:, bearer_token:, config:)
  client.tools_call(name: tool_name, arguments:, meta:)
rescue McpToolkit::Gateway::Client::Error => e
  relay_upstream_error(e)
end