Convert from openai-agents fork to an extension.
Resolves feedback from https://github.com/openai/openai-agents-python/issues/23 and https://github.com/openai/openai-agents-python/pull/40
Installation
bash
uv add openai-agents-mcp
bash
pip install openai-agents-mcp
Quick Start
> [!TIP]
> The [`examples`](/examples) directory has several example applications to get started with.
> To run an example, clone this repo, then:
>
> bash
> 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 example
>
In order to use Agents SDK with MCP, simply replace the following import:
diff
- from agents import Agent
+ from agents_mcp import Agent
With that you can instantiate an Agent with `mcp_servers` in addition to `tools` (which continue to work like before).
python
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:
yaml
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](./examples) directory to see MCP servers in action with Agents SDK.
Demo
https://github.com/user-attachments/assets/1d2a843d-2f99-41f2-8671-4c7940ec48f5
More details and nuances below.