Call FastMCP servers from the OpenAI API
list_tools
endpoint and exposes those functions to the AI agent. Other MCP features like resources and prompts are not currently supported.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:
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.
New in version: 2.6.0
The Responses API can include headers to authenticate the request, which means you don’t have to worry about your server being publicly accessible.
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
header with the Bearer
scheme: