Create a Server
First, create a FastMCP server with the tools you want to expose. For this example, weβll create a server with a single tool that rolls dice.server.py
Deploy the Server
Your server must be deployed to a public URL in order for Anthropic to access it. The MCP connector supports both SSE and Streamable HTTP transports. For development, you can use tools likengrok 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:
Call the Server
To use the Messages API with MCP servers, youβll need to install the Anthropic Python SDK (not included with FastMCP):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.
Authentication
The MCP connector supports OAuth authentication through authorization tokens, which means you can secure your server while still allowing Anthropic to access it.Server Authentication
The simplest way to add authentication to the server is to use a bearer token scheme. For this example, weβll quickly generate our own tokens with FastMCPβsRSAKeyPair utility, but this may not be appropriate for production use. For more details, see the complete server-side Token Verification documentation.
Weβll start by creating an RSA key pair to sign and verify tokens.
JWTVerifier to authenticate the server.
server.py
Client Authentication
If you try to call the authenticated server with the same Anthropic code we wrote earlier, youβll get an error indicating that the server rejected the request because itβs not authenticated.authorization_token parameter in your MCP server configuration:

