MCPTool¶
Connects to a Model Context Protocol (MCP) server via JSON-RPC 2.0.
See also: Expose an Agent or Chain as an MCP Server — the complement that lets Claude Desktop / Cursor / Continue / Zed call your fastaiagent agents as tools. Same protocol, opposite direction.
Basic Usage¶
from fastaiagent import MCPTool
file_search = MCPTool(
name="file_search",
description="Search files in the codebase",
server_url="http://localhost:3000/mcp",
tool_name="search_files",
auth_token="my-token", # Optional Bearer token
parameters={
"type": "object",
"properties": {
"query": {"type": "string"},
"file_pattern": {"type": "string"},
},
"required": ["query"],
},
)
result = await file_search.aexecute({"query": "authentication", "file_pattern": "*.py"})
Replay safety. Pass
replay_class="read_only" | "idempotent" | "side_effecting"to mark how Agent Replay treats this tool — defaultside_effecting, never auto-inferred. See Replay safety.
Discovering MCP Tools¶
List available tools on an MCP server:
tools = await file_search.discover_tools()
for t in tools:
print(f"{t['name']}: {t.get('description', '')}")
Next Steps¶
- FunctionTool — Wrap Python functions as tools
- RESTTool — Call HTTP APIs as tools
- Schema Drift Detection — Detect when tool responses change
- Tools Overview — All tool types at a glance