FastMCP client
Recommended. Keep your existing Messages API loop and control exactly when MCP tools are refreshed.
Anthropic tool runner
Let Anthropic’s Python SDK run the tool-use loop while your application owns the MCP connection.
Hosted MCP connector
The shortest integration, but Anthropic may cache MCP tool definitions across requests and chats.
Which approach should I use?
- Use the FastMCP client if you already have a custom agent harness or need fresh tool definitions after users authenticate. This is the recommended production approach.
- Use the Anthropic tool runner if you want a customer-managed MCP connection but do not already have a tool-use loop.
- Use the hosted MCP connector for the smallest proof of concept, when delayed tool-definition refreshes are acceptable.
anthropic.beta.messages.tool_runner is part of the regular anthropic Python SDK. It is not the Claude Agent SDK. The tool runner is a client-side convenience wrapper around repeated Messages API calls; the Agent SDK is a separate, higher-level agent harness with built-in tools, hooks, permissions, and subagents.Common authentication
All three approaches below use a bearer token that packs the Caylex Navigator API key, end-user email, and chat session ID into one string:- Token =
base64url(JSON{"api_key": "...", "user_email": "...", "session_id": "..."})(padding optional) api_keyanduser_emailare required.session_idis optional but strongly encouraged. It groups a chat’s tool calls into one session in Caylex history and analytics.- Send the result as
Authorization: Bearer <token>.
Group tool calls by chat session
Generate one UUID when a chat begins and reuse it for every request in that chat:Prerequisites
- Python 3.10+
- A Caylex Navigator Instance with an API key (create one here)
- Users authenticated with your project’s servers (set up auth links)
- These environment variables:
System prompt and conversation messages
Anthropic accepts the system prompt through the top-levelsystem parameter. Do not add a message with role: "system" — the messages array contains only user and assistant turns.
conversation_messages and append the new user message. The examples below show one user turn plus any tool-use iterations it triggers.
FastMCP client (recommended)
This approach uses FastMCP’s lightweight client-only package to calltools/list and tools/call directly. You pass the freshly discovered tools to the regular Messages API and keep control of your existing agent loop.
Using a coding agent? Grab the Agent Skill
A ready-made SKILL.md for Claude Code, Cursor, and similar coding agents that implements this integration in your existing Messages API harness.
main.py
Refresh after authentication
The tool definitions passed to one Claude tool loop remain fixed for that loop. Ifget_authentication_status_and_link returns a link and the user authenticates:
- Finish the current agent turn after presenting the link.
- Before the user’s next turn, call
mcp.list_tools()again. - Rebuild
claude_toolsfrom the returned list. - Continue with the same
chat_session_idand conversation history.
suggest_tools description and authenticated-server list without relying on a third-party MCP catalog cache.
Anthropic tool runner
This option also owns the MCP connection, but uses Anthropic’s beta tool runner to execute the tool-use loop automatically. It is convenient if you do not already have a custom loop. Install:main.py
async_mcp_tool copies each MCP tool’s name, description, and input schema into an Anthropic tool, then forwards Claude’s calls to ClientSession.call_tool(). The tool runner appends results and repeats Messages API calls until Claude returns a final answer.
This still uses Anthropic’s regular Python SDK and Messages API. It does not install or invoke the Claude Agent SDK. Because the tool runner owns the inner tool loop, applications with custom retries, streaming, approvals, or persistence may prefer the FastMCP approach above.
Anthropic hosted MCP connector
Anthropic’s hosted MCP connector performs MCP discovery and execution inside Anthropic’s infrastructure. It requires the least code because your application does not run an MCP client. Install:main.py
The hosted connector requires
client.beta.messages.create, an mcp_toolset, and the mcp-client-2025-11-20 beta header. Its tool events use mcp_tool_use / mcp_tool_result; customer-managed integrations use ordinary tool_use / tool_result blocks.Troubleshooting
The server list or authentication tool is stale
The server list or authentication tool is stale
If you use Anthropic’s hosted connector, the model-facing MCP catalog may be cached across requests or chats. There is currently no supported force-refresh parameter. Switch to a customer-managed MCP client, or wait for Anthropic’s catalog cache to refresh.With FastMCP, call
mcp.list_tools() before each user turn and rebuild the Anthropic tool definitions. With the tool runner, start the next turn with a fresh list_tools() result.Invalid request parameters at initialize
Invalid request parameters at initialize
Authentication likely failed. Confirm that the token decodes to the correct
api_key, user_email, and UUID session_id, and that the API key belongs to the same environment as the Navigator URL.Tool calls to a server fail with an auth error
Tool calls to a server fail with an auth error
The
user_email packed into the token must exactly match the email the user authenticated with through an Auth Link.Tool calls from one chat appear as separate sessions
Tool calls from one chat appear as separate sessions
Generate one UUID when the chat begins and include it as
session_id in every bearer token for that chat. Do not generate a new UUID for each MCP request.An extra argument I sent was ignored
An extra argument I sent was ignored
The Navigator ignores unknown top-level arguments instead of failing the whole call. It reports them in response
_meta under caylex/ignored_arguments, including the field names and reason.Further reading
- Claude API Agent Skill — a SKILL.md for coding agents that implements the FastMCP approach
- FastMCP client-only package
- FastMCP Client
- FastMCP client transports
- Anthropic tool runner
- Anthropic hosted MCP connector
- Claude Agent SDK
- Connecting Your Agent
- Server Authentication