Convert from openai-agents fork to an extension.
Resolves feedback from openai#23 and openai#40
Installation
uv add openai-agents-mcppip install openai-agents-mcpQuick Start
Tip
The examples directory has several example applications to get started with.
To run an example, clone this repo, then:
cd examples
cp mcp_agent.secrets.yaml.example mcp_agent.secrets.yaml # Update API keys if needed
uv run hello_world_mcp.py # Or any other exampleIn order to use Agents SDK with MCP, simply replace the following import:
- from agents import Agent
+ from agents_mcp import AgentWith that you can instantiate an Agent with mcp_servers in addition to tools (which continue to work like before).
from agents_mcp import Agent
# Create an agent with specific MCP servers you want to use
# These must be defined in your mcp_agent.config.yaml file
agent = Agent(
name="MCP Agent",
instructions="""You are a helpful assistant with access to both local/OpenAI tools and tools from MCP servers. Use these tools to help the user.""",
# Local/OpenAI tools
tools=[get_current_weather],
# Specify which MCP servers to use
# These must be defined in your mcp_agent config
mcp_servers=["fetch", "filesystem"],
)Then define an mcp_agent.config.yaml, with the MCP server configuration:
mcp:
servers:
fetch:
command: npx
args: ["-y", "@modelcontextprotocol/server-fetch"]
filesystem:
command: npx
args: ["-y", "@modelcontextprotocol/server-filesystem", "."]That's it! The rest of the Agents SDK works exactly as before.
Head over to the examples directory to see MCP servers in action with Agents SDK.
Demo
openai_agents_mcp.mov
More details and nuances below.