trading_agent.backends.claude_tool_bridge
¶
Hands a desk's tools to Claude Code as an in-process MCP server.
Claude Code calls each tool through the MCP protocol, but the call never leaves this process: the handler runs the call through the desk's ToolCallExecutor, so Claude's calls get the same loop guard, argument checks, time limit and output cap as Gemma's.
Typical usage example:
bridge = ClaudeToolBridge(executor) server = bridge.build_server() bridge.current_trigger = trigger
ClaudeToolHandler
¶
The handler Claude Code calls for one tool.
Creates the handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bridge
|
ClaudeToolBridge
|
The bridge that knows the current trigger and the executor. |
required |
tool_name
|
str
|
The tool's name in the registry. |
required |
Source code in src/trading_agent/backends/claude_tool_bridge.py
__call__
async
¶
Runs the tool call and returns the result in MCP's shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
dict[str, Any]
|
The arguments Claude sent. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
{"content": [{"type": "text", "text": ...}], "is_error": ...}. |
Source code in src/trading_agent/backends/claude_tool_bridge.py
ClaudeToolBridge
¶
Builds the MCP server and remembers which trigger the current turn belongs to.
Attributes:
| Name | Type | Description |
|---|---|---|
executor |
What runs each call. |
|
current_trigger |
Trigger | None
|
The trigger of the turn in progress, set by the turn runner before each turn. |
Creates the bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executor
|
ToolCallExecutor
|
What runs each call. |
required |
Source code in src/trading_agent/backends/claude_tool_bridge.py
build_server
¶
Builds the in-process MCP server holding every tool in the registry.
Returns:
| Type | Description |
|---|---|
McpSdkServerConfig
|
The server, for ClaudeAgentOptions.mcp_servers. |
Source code in src/trading_agent/backends/claude_tool_bridge.py
claude_tool_names
¶
The names Claude Code knows the tools by.
Returns:
| Type | Description |
|---|---|
list[str]
|
Each tool's name as "mcp__trading_agent__ |