Call FastMCP servers from the Anthropic API
list_tools
endpoint and exposes those functions to Claude. Other MCP features like resources and prompts are not currently supported. You can read more about the MCP connector in the Anthropic documentation.ngrok
to temporarily expose a locally-running server to the internet. We’ll do that for this example (you may need to install ngrok
and create a free account), but you can use any other method to deploy your server.
Assuming you saved the above code as server.py
, you can run the following two commands in two separate terminals to deploy your server and expose it to the internet:
ANTHROPIC_API_KEY
environment variable. Consult the Anthropic SDK documentation for more information.
https://your-server-url.com
with the actual URL of your server. In addition, we use /mcp/
as the endpoint because we deployed a streamable-HTTP server with the default path; you may need to use a different endpoint if you customized your server’s deployment. At this time you must also include the extra_headers
parameter with the anthropic-beta
header.
New in version: 2.6.0
The MCP connector supports OAuth authentication through authorization tokens, which means you can secure your server while still allowing Anthropic to access it.
RSAKeyPair
utility, but this may not be appropriate for production use. For more details, see the complete server-side Bearer Auth documentation.
We’ll start by creating an RSA key pair to sign and verify tokens.
RSAKeyPair
utility is for development and testing only.BearerAuthProvider
to authenticate the server.
authorization_token
parameter in your MCP server configuration: