Using MCP Tools with the OpenAI Agents SDK
Connect Model Context Protocol (MCP) servers seamlessly into the OpenAI Agents SDK for Python to power autonomous agent workflows with standardized tools.
Published on • September 11, 2026
AI Assistant

The OpenAI Agents SDK for Python provides a lightweight, ergonomic framework for building multi-agent systems with handoffs, guardrails, and tracing. By integrating Model Context Protocol (MCP) tools into the OpenAI Agents SDK, developers can plug any standard MCP tool server—databases, file systems, GitHub integrations, or web search APIs—directly into OpenAI-powered agents.
In this guide, we show how to connect MCP tool servers to agents using the OpenAI Agents SDK.
Architecture Overview
The OpenAI Agents SDK natively supports external function tools. An MCP adapter bridges the gap by discovering advertised tools on an MCP server and converting them into OpenAI function schemas that agents can execute during reasoning loops.
[OpenAI Agent Engine]
|-- Reasoning Loop (GPT-4o / GPT-4o-mini)
|-- MCP Tool Adapter
|--(JSON-RPC over Stdio or SSE)--> [MCP Server]
Step-by-Step Implementation
1. Installation
pip install openai-agents mcp
2. Wiring MCP Tools into OpenAI Agents
import asyncio
from openai_agents import Agent, Runner, FunctionTool
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def fetch_mcp_tools(session: ClientSession) -> list[FunctionTool]:
"""Discover tools from MCP session and adapt to OpenAI FunctionTools"""
mcp_tools = await session.list_tools()
openai_tools = []
for tool in mcp_tools.tools:
# Create an async wrapper function for the OpenAI Agents SDK
async def make_tool_call(ctx, **kwargs):
result = await session.call_tool(tool.name, kwargs)
return "\n".join([c.text for c in result.content if c.type == "text"])
# Construct FunctionTool with schema
function_tool = FunctionTool(
name=tool.name,
description=tool.description or "MCP External Tool",
parameters=tool.inputSchema,
execute=make_tool_call
)
openai_tools.append(function_tool)
return openai_tools
async def main():
# Define parameters for local or remote MCP server
server_params = StdioServerParameters(
command="python",
args=["-m", "my_mcp_server"]
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# Adapt MCP tools to OpenAI format
mcp_tools = await fetch_mcp_tools(session)
# Define OpenAI Agent equipped with MCP tools
research_agent = Agent(
name="MCP Research Assistant",
instructions="You are an assistant equipped with external enterprise MCP tools.",
tools=mcp_tools
)
# Run agent query
result = await Runner.run(
research_agent,
"Fetch active service metrics and summarize health status."
)
print("Final Result:", result.final_output)
if __name__ == "__main__":
asyncio.run(main())
Key Benefits of Combining OpenAI Agents SDK with MCP
- Framework Portability: MCP tools built for your OpenAI agents can be reused immediately across LangGraph, CrewAI, or ADK agents without rewriting tool code.
- Unified Tracing: Function executions flowing through the OpenAI Agents SDK automatically produce detailed spans in OpenTelemetry and OpenAI tracing dashboards.
- Safe Sandboxing: MCP servers run in isolated processes, ensuring that database drivers or heavy dependencies don’t pollute your core agent application context.
For more details on agent handoffs, guardrails, and session persistence, check out the official OpenAI Agents SDK Documentation.