Class: McpToolkit::Gateway::Proxy
- Inherits:
-
Object
- Object
- McpToolkit::Gateway::Proxy
- 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
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
-
#bearer_token ⇒ Object
readonly
Returns the value of attribute bearer_token.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#tool_name ⇒ Object
readonly
Returns the value of attribute tool_name.
Instance Method Summary collapse
- #call(arguments) ⇒ Object
-
#initialize(app_key:, tool_name:, account_id: nil, bearer_token: nil, config: McpToolkit.config) ⇒ Proxy
constructor
A new instance of Proxy.
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 = account_id @bearer_token = bearer_token @config = config end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
17 18 19 |
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 17 def account_id @account_id end |
#app_key ⇒ Object (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_token ⇒ Object (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 |
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/mcp_toolkit/gateway/proxy.rb', line 17 def config @config end |
#tool_name ⇒ Object (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 |