Responses API
OpenAIβs Responses API supports MCP servers as remote tool sources, allowing you to extend AI capabilities with custom functions.The Responses API is a distinct API from OpenAIβs Completions API or Assistants API. At this time, only the Responses API supports MCP.
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 OpenAI to access it. 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 Responses API, youβll need to install the OpenAI Python SDK (not included with FastMCP):OPENAI_API_KEY environment variable. Consult the OpenAI 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.
Authentication
The Responses API can include headers to authenticate the request, which means you donβt have to worry about your server being publicly accessible.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 OpenAI code we wrote earlier, youβll get an error like this:Authorization header with the Bearer scheme:

