Model Context Protocol (MCP) is an open standard for connecting language models to external tools and data sources through a unified interface. Instead of writing a custom function for every external service and routing each call through your backend, you point the model at an MCP server and it handles tool discovery, invocation, and response handling directly. The result is less infrastructure to maintain, lower latency, and a consistent pattern regardless of which services you connect to.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openai/openai-cookbook/llms.txt
Use this file to discover all available pages before exploring further.
Why MCP matters
Traditional function calling works well for simple cases, but it introduces friction at scale. Every external API requires a wrapper function, a relay server to forward calls, and custom error handling. When you chain multiple services — for example, fetching data from Sentry and opening a GitHub issue in a single workflow — you end up with glue code that is hard to maintain and easy to break. MCP solves this by acting as a centralized tool host. The model connects directly to one or more MCP servers, imports their tool lists, and invokes tools without touching your backend. You configure the server once; the model handles the rest.Commerce and payments
Add items to a Shopify cart, generate Stripe payment links, or query order status — all in a single conversation turn without custom wrapper functions.
Dev-ops and code quality
Ask Sentry for the latest error in a file, then open a GitHub issue with a suggested fix in the same agent run.
Messaging and notifications
Fetch morning headlines via web search and send a Twilio SMS summary — two different APIs, zero backend glue.
Databases and file systems
Query databases, read from the local file system, or interact with cloud storage using MCP servers built for those services.
How MCP works in the Responses API
When you add an MCP block to thetools array, the Responses API runtime:
Detects the transport
The runtime identifies whether the server uses streamable HTTP or the older HTTP-over-SSE protocol, and uses the appropriate transport.
Imports the tool list
The runtime calls
tools/list on the server, passing any auth headers you provide. The results are written to an mcp_list_tools item in the model’s context. As long as this item is present, the list is not fetched again — this gives you caching at the conversation level.Calls and approves tools
When the model decides to invoke a tool, it emits an
mcp_tool_call item. By default, the stream pauses for your explicit approval. Once you trust a server, you can set require_approval: "never" to allow automatic execution.Connecting to an MCP server
The following example connects to a public MCP server that exposes documentation search for thetiktoken library. The model can query it directly without any wrapper code on your side.
Using MCP tools in the Agents SDK
The OpenAI Agents SDK supports MCP servers as first-class tool providers. You can mix MCP tools with regular Python function tools in the same agent.Filtering tools to control scope
Remote MCP servers often expose many tools. Including all of them adds tokens to the context, increases latency, and can confuse the model. Useallowed_tools to limit which tools the model can see and call.
Managing latency and caching
MCP tool discovery adds latency on the first call because the runtime fetches the server’s tool list. On subsequent turns, themcp_list_tools item is already in context, so the fetch is skipped. Use previous_response_id to carry this item forward across turns.
Common MCP integrations
| Category | Example servers |
|---|---|
| Code and documentation | GitHub, GitMCP, Sentry |
| Commerce and payments | Shopify, Stripe |
| File systems and storage | Local filesystem, S3, Google Drive |
| Databases | PostgreSQL, SQLite, Supabase |
| Communication | Twilio, Slack, email |
| Search and knowledge | Web search, Exa, Brave |
Next steps
OpenAI Agents SDK
Build agents that use MCP servers alongside Python function tools.
Function calling
Understand the underlying tool-call pattern that MCP builds on.