Skip to content

Commit 4c0a775

Browse files
committed
Update README
1 parent 230522c commit 4c0a775

File tree

3 files changed

+169
-25
lines changed

3 files changed

+169
-25
lines changed

README.md

Lines changed: 163 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# OpenAI Agents SDK
1+
# OpenAI Agents SDK (MCP Compatible)
2+
3+
!!!
4+
**This is a fork of the OpenAI Agents SDK with MCP compatibility using [mcp-agent](https://github.com/lastmile-ai/mcp-agent)**
5+
!!!
6+
27

38
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
49

@@ -10,6 +15,7 @@ The OpenAI Agents SDK is a lightweight yet powerful framework for building multi
1015
2. [**Handoffs**](https://openai.github.io/openai-agents-python/handoffs/): Allow agents to transfer control to other agents for specific tasks
1116
3. [**Guardrails**](https://openai.github.io/openai-agents-python/guardrails/): Configurable safety checks for input and output validation
1217
4. [**Tracing**](https://openai.github.io/openai-agents-python/tracing/): Built-in tracking of agent runs, allowing you to view, debug and optimize your workflows
18+
5. [**MCP**](#using-with-mcp-model-context-protocol): Supports using MCP servers with the Agent abstraction
1319

1420
Explore the [examples](examples) directory to see the SDK in action, and read our [documentation](https://openai.github.io/openai-agents-python/) for more details.
1521

@@ -166,17 +172,42 @@ make lint # run linter
166172

167173
## Using with MCP (Model Context Protocol)
168174

169-
The OpenAI Agents SDK can be integrated with the Model Context Protocol ([MCP](https://modelcontextprotocol.github.io/)) to seamlessly use tools from MCP servers. This integration allows you to:
175+
The OpenAI Agents SDK can be integrated with the Model Context Protocol ([MCP](https://modelcontextprotocol.github.io/)) to seamlessly use tools from MCP servers. The integration allows agents to leverage tools from MCP servers alongside native OpenAI Agent SDK tools:
170176

171177
1. Use tools from MCP servers directly in your agents
172178
2. Configure MCP servers using standard configuration files
173179
3. Combine local tools with tools from MCP servers
174180

175-
### Setting up MCP Integration
181+
### Using MCP servers in Agents SDK
182+
183+
#### `mcp_servers` property on Agent
176184

177-
1. Create an `mcp_agent.config.yaml` file in your project directory that defines your MCP servers:
185+
You can specify the names of MCP servers to give an Agent access to by
186+
setting its `mcp_servers` property.
187+
188+
The Agent will then automatically aggregate tools from the servers, as well as
189+
any `tools` specified, and create a single extended list of tools. This means you can seamlessly
190+
use local tools, MCP servers, and other kinds of Agent SDK tools through a single unified syntax.
191+
192+
```python
193+
194+
agent = Agent(
195+
name="MCP Assistant",
196+
instructions="You are a helpful assistant with access to MCP tools.",
197+
tools=[your_other_tools], # Regular tool use for Agent SDK
198+
mcp_servers=["fetch", "filesystem"] # Names of MCP servers from your config file (see below)
199+
)
200+
```
201+
202+
#### MCP Configuration File
203+
204+
Configure MCP servers by creating an `mcp_agent.config.yaml` file. You can place this file in your project directory or any parent directory.
205+
206+
Here's an example configuration file that defines three MCP servers:
178207

179208
```yaml
209+
$schema: "https://raw.githubusercontent.com/lastmile-ai/mcp-agent/main/schema/mcp-agent.config.schema.json"
210+
180211
mcp:
181212
servers:
182213
fetch:
@@ -185,35 +216,148 @@ mcp:
185216
filesystem:
186217
command: "npx"
187218
args: ["-y", "@modelcontextprotocol/server-filesystem", "."]
219+
slack:
220+
command: "npx"
221+
args: ["-y", "@modelcontextprotocol/server-slack"]
222+
```
223+
224+
For servers that require sensitive information like API keys, you can:
225+
1. Define them directly in the config file (not recommended for production)
226+
2. Use a separate `mcp_agent.secrets.yaml` file (more secure)
227+
3. Set them as environment variables
228+
229+
### Methods for Configuring MCP
230+
231+
The OpenAI Agents SDK supports several ways to configure MCP servers:
232+
233+
#### 1. Automatic Discovery (Recommended)
234+
235+
The simplest approach lets the SDK automatically find your configuration file if it's named `mcp_agent.config.yaml` and `mcp_agent.secrets.yaml`:
236+
237+
```python
238+
from agents import Agent, Runner
239+
240+
# Create an agent that references MCP servers
241+
agent = Agent(
242+
name="MCP Assistant",
243+
instructions="You are a helpful assistant with access to MCP tools.",
244+
mcp_servers=["fetch", "filesystem"] # Names of servers from your config file
245+
)
246+
247+
# The context object will be automatically populated
248+
class AgentContext:
249+
pass
250+
251+
result = await Runner.run(agent, input="Hello world", context=AgentContext())
252+
```
253+
254+
#### 2. Explicit Config Path
255+
256+
You can explicitly specify the path to your config file:
257+
258+
```python
259+
class AgentContext:
260+
def __init__(self, mcp_config_path=None):
261+
self.mcp_config_path = mcp_config_path # Will be used to load the config
262+
263+
context = AgentContext(mcp_config_path="/path/to/mcp_agent.config.yaml")
188264
```
189265

190-
2. Create a context object and specify which MCP servers to use with your agent:
266+
#### 3. Programmatic Configuration
267+
268+
You can programmatically define your MCP settings:
191269

192270
```python
193-
from agents import Agent, Run, function_tool
271+
from mcp_agent.config import MCPSettings, MCPServerSettings
272+
273+
# Define MCP config programmatically
274+
mcp_config = MCPSettings(
275+
servers={
276+
"fetch": MCPServerSettings(
277+
command="uvx",
278+
args=["mcp-server-fetch"]
279+
),
280+
"filesystem": MCPServerSettings(
281+
command="npx",
282+
args=["-y", "@modelcontextprotocol/server-filesystem", "."]
283+
)
284+
}
285+
)
194286
195-
# Create a simple context class that will hold the MCP server registry
196287
class AgentContext:
197-
def __init__(self, mcp_config_path=None, mcp_config=None):
198-
self.mcp_config_path = mcp_config_path # Optional specific path to config file
199-
self.mcp_config = mcp_config # Optional programmatic setting of MCP server settings
288+
def __init__(self, mcp_config=None):
289+
self.mcp_config = mcp_config
200290
201-
# Create an agent that specifies which MCP servers to use
291+
context = AgentContext(mcp_config=mcp_config)
292+
```
293+
294+
#### 4. Custom Server Registry
295+
296+
You can create and configure your own MCP server registry:
297+
298+
```python
299+
from mcp_agent.mcp_server_registry import ServerRegistry
300+
from mcp_agent.config import get_settings
301+
302+
# Create a custom server registry
303+
settings = get_settings("/path/to/config.yaml")
304+
server_registry = ServerRegistry(config=settings)
305+
306+
# Create an agent with this registry
307+
agent = Agent(
308+
name="Custom Registry Agent",
309+
instructions="You have access to custom MCP servers.",
310+
mcp_servers=["fetch", "filesystem"],
311+
mcp_server_registry=server_registry # Use custom registry
312+
)
313+
```
314+
315+
### Examples
316+
317+
#### Basic Hello World
318+
319+
A simple example demonstrating how to create an agent that uses MCP tools:
320+
321+
```python
322+
# Create an agent with MCP servers
202323
agent = Agent(
203324
name="MCP Assistant",
204-
instructions="You are a helpful assistant.",
205-
tools=[your_local_tool], # Local tools you define
206-
mcp_servers=["fetch", "filesystem"], # MCP servers to use (must be in config)
325+
instructions="You are a helpful assistant with access to tools.",
326+
tools=[get_current_weather], # Local tools
327+
mcp_servers=["fetch", "filesystem"], # MCP servers
328+
)
329+
330+
# Run the agent
331+
result = await Runner.run(
332+
agent,
333+
input="What's the weather in Miami? Also, can you fetch the OpenAI website?",
334+
context=AgentContext(),
207335
)
208336
209-
# Run the agent - tools from specified MCP servers will be automatically loaded
210-
result = await Run.run(
211-
starting_agent=agent,
212-
input="Print the first paragraph of https://openai.github.io/openai-agents-python/", # uses MCP fetch server
213-
context=AgentContext(), # Server registry loads automatically
337+
print(result.response.value)
338+
```
339+
340+
See [hello_world.py](examples/mcp/basic/hello_world.py) for the complete example.
341+
342+
#### Streaming Responses
343+
344+
To stream responses instead of waiting for the complete result:
345+
346+
```python
347+
result = Runner.run_streamed( # Note: No await here
348+
agent,
349+
input="Print the first paragraph of https://openai.github.io/openai-agents-python/",
350+
context=context,
214351
)
352+
353+
# Stream the events
354+
async for event in result.stream_events():
355+
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
356+
print(event.data.delta, end="", flush=True)
215357
```
216358

359+
See [hello_world_streamed.py](examples/mcp/basic/hello_world_streamed.py) for the complete example.
360+
217361
For more details, read the [MCP examples README](examples/mcp/README.md) and try out the [examples/mcp/basic/hello_world.py](examples/mcp/basic/hello_world.py) for a complete working example.
218362

219363
## Acknowledgements

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[project]
2-
name = "openai-agents"
2+
name = "openai-agents-mcp"
33
version = "0.0.3"
4-
description = "OpenAI Agents SDK"
4+
description = "MCP-compatible fork of OpenAI Agents SDK"
55
readme = "README.md"
66
requires-python = ">=3.10"
77
license = "MIT"
88
authors = [
9-
{ name = "OpenAI", email = "[email protected]" },
9+
{ name = "Sarmad Qadri", email = "[email protected]" },
1010
]
1111
dependencies = [
1212
"openai>=1.66.2",
@@ -32,8 +32,8 @@ classifiers = [
3232
]
3333

3434
[project.urls]
35-
Homepage = "https://github.com/openai/openai-agents-python"
36-
Repository = "https://github.com/openai/openai-agents-python"
35+
Homepage = "https://github.com/saqadri/openai-agents-mcp"
36+
Repository = "https://github.com/saqadri/openai-agents-mcp"
3737

3838
[dependency-groups]
3939
dev = [

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)