symfonic.tools.mcp.connection¶
connection ¶
JSONRPCMCPConnection -- the MCP wire protocol over HTTP.
Split from :mod:symfonic.tools.mcp.provider so each module holds one class.
The transport is sound and was not implicated in T4.2.2's findings; the
provider on top of it was, which is exactly why they are worth reading apart.
Optional dependency: httpx>=0.27, via pip install symfonic-core[mcp].
JSONRPCMCPConnection ¶
MCP server connection via JSON-RPC 2.0 over HTTP.
Implements the MCP wire protocol: - tools/list โ discover available tools - tools/call โ invoke a tool by name
Requires httpx::
pip install symfonic-core[mcp]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_url
|
str
|
Full HTTP(S) URL to the MCP server endpoint. |
required |
Example::
conn = JSONRPCMCPConnection("http://localhost:3000/mcp")
tools = await conn.list_tools()
result = await conn.call_tool("search", {"query": "force majeure"})
Source code in src/symfonic/tools/mcp/connection.py
call_tool
async
¶
Send tools/call request and return parsed result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
Name of the tool to invoke. |
required |
arguments
|
dict[str, Any]
|
Arguments matching the tool's input schema. |
required |
Returns:
| Type | Description |
|---|---|
MCPToolResult
|
MCPToolResult with concatenated text content from the response. |
Source code in src/symfonic/tools/mcp/connection.py
close
async
¶
Release connection state and close the pooled HTTP client.
Source code in src/symfonic/tools/mcp/connection.py
list_tools
async
¶
Send tools/list request and parse response.
A row without a usable name is skipped with a warning rather than
raising. tool_data["name"] used to be an unguarded index, and since
MCPToolProvider.discover_tools catches per server, a single
malformed entry discarded every other tool that server advertised.
Returns:
| Type | Description |
|---|---|
list[MCPToolDefinition]
|
List of MCPToolDefinition objects for each well-formed tool the |
list[MCPToolDefinition]
|
server exposes. |