mcp
langroid/agent/tools/mcp/init.py
FastMCPClient(server)
¶
A client for interacting with a FastMCP server.
Provides async context manager functionality to safely manage resources.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server
|
str | FastMCP[Any] | ClientTransport
|
FastMCP server or path to such a server |
required |
Source code in langroid/agent/tools/mcp/fastmcp_client.py
connect()
async
¶
close()
async
¶
get_langroid_tool(tool_name)
async
¶
Create a Langroid ToolMessage subclass from the MCP Tool
with the given tool_name
.
Source code in langroid/agent/tools/mcp/fastmcp_client.py
get_langroid_tools()
async
¶
Get all available tools as Langroid ToolMessage classes,
handling nested schemas, with handle_async
methods
Source code in langroid/agent/tools/mcp/fastmcp_client.py
get_mcp_tool_async(name)
async
¶
Find the "original" MCP Tool (i.e. of type mcp.types.Tool) on the server
matching name
, or None if missing. This contains the metadata for the tool:
name, description, inputSchema, etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the tool to look up. |
required |
Returns:
Type | Description |
---|---|
Optional[Tool]
|
The raw Tool object from the server, or None. |
Source code in langroid/agent/tools/mcp/fastmcp_client.py
call_mcp_tool(tool_name, arguments)
async
¶
Call an MCP tool with the given arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_name
|
str
|
Name of the tool to call. |
required |
arguments
|
Dict[str, Any]
|
Arguments to pass to the tool. |
required |
Returns:
Type | Description |
---|---|
str | List[str] | None
|
The result of the tool call. |
Source code in langroid/agent/tools/mcp/fastmcp_client.py
mcp_tool(server, tool_name)
¶
Decorator: declare a ToolMessage class bound to a FastMCP tool.
Usage
@fastmcp_tool("/path/to/server.py", "get_weather") class WeatherTool: def pretty(self) -> str: return f"Temp is {self.temperature}"