symfonic.tools.mcp.provider¶
provider ¶
MCPToolProvider -- bridge between MCP servers and LangChain tools.
Connects to one or more MCP servers, discovers their tools, and converts them to LangChain StructuredTools for use in agent graphs.
Optional dependencies: - httpx>=0.27 required for JSONRPCMCPConnection HTTP transport - langchain-core required for to_langchain_tools()
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/provider.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/provider.py
close
async
¶
Release connection state and close the pooled HTTP client.
Source code in src/symfonic/tools/mcp/provider.py
list_tools
async
¶
Send tools/list request and parse response.
Returns:
| Type | Description |
|---|---|
list[MCPToolDefinition]
|
List of MCPToolDefinition objects for each tool the server exposes. |
Source code in src/symfonic/tools/mcp/provider.py
MCPToolProvider ¶
Bridge that connects to MCP servers and provides LangChain-compatible tools.
Registers one or more MCPServerConnection instances, discovers their tools, and routes tool calls to the correct server.
Usage::
provider = MCPToolProvider()
provider.add_server("legal", JSONRPCMCPConnection("http://localhost:3000"))
definitions = await provider.discover_tools()
lc_tools = provider.to_langchain_tools()
# Later, invoke a tool directly:
result = await provider.call_tool("search", {"query": "breach of contract"})
# Cleanup:
await provider.close_all()
Source code in src/symfonic/tools/mcp/provider.py
add_server ¶
Register an MCP server connection under a logical name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logical label for this server (used in log messages). |
required |
connection
|
MCPServerConnection
|
Any object satisfying MCPServerConnection protocol. |
required |
Source code in src/symfonic/tools/mcp/provider.py
call_tool
async
¶
Execute a previously discovered tool by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
Name of the tool to invoke. |
required |
arguments
|
dict[str, Any]
|
Arguments to pass to the tool. |
required |
Returns:
| Type | Description |
|---|---|
MCPToolResult
|
MCPToolResult. If |
MCPToolResult
|
error result without raising. |
Source code in src/symfonic/tools/mcp/provider.py
close_all
async
¶
Close all registered server connections.
discover_tools
async
¶
Discover all tools from all registered servers.
Failed servers are skipped with a warning — partial discovery is preferred over a hard failure when one server is unavailable.
Returns:
| Type | Description |
|---|---|
list[MCPToolDefinition]
|
Flat list of MCPToolDefinition from all reachable servers. |
Source code in src/symfonic/tools/mcp/provider.py
to_langchain_tools ¶
Convert discovered MCP tools to LangChain StructuredTools.
Each tool's name and description from the MCP server are mapped
to the StructuredTool. Invocations are delegated back through
MCPToolProvider.call_tool.
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of LangChain StructuredTool instances, or an empty list |
list[Any]
|
if langchain-core is not installed. |