You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Summary:
Spins up a stdio server with some local files, then asks the model
questions.
### Test Plan:
Run the example, see it work.
---
[//]: # (BEGIN SAPLING FOOTER)
* #324
* __->__ #322
* #336
The [Model context protocol](https://modelcontextprotocol.io/introduction) (aka MCP) is a way to provide tools and context to the LLM. From the MCP docs:
4
+
5
+
> MCP is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.
6
+
7
+
The Agents SDK has support for MCP. This enables you to use a wide range of MCP servers to provide tools to your Agents.
8
+
9
+
## MCP servers
10
+
11
+
Currently, the MCP spec defines two kinds of servers, based on the transport mechanism they use:
12
+
13
+
1.**stdio** servers run as a subprocess of your application. You can think of them as running "locally".
14
+
2.**HTTP over SSE** servers run remotely. You connect to them via a URL.
15
+
16
+
You can use the [`MCPServerStdio`][agents.mcp.server.MCPServerStdio] and [`MCPServerSse`][agents.mcp.server.MCPServerSse] classes to connect to these servers.
17
+
18
+
For example, this is how you'd use the [official MCP filesystem server](https://www.npmjs.com/package/@modelcontextprotocol/server-filesystem).
MCP servers can be added to Agents. The Agents SDK will call `list_tools()` on the MCP servers each time the Agent is run. This makes the LLM aware of the MCP server's tools. When the LLM calls a tool from an MCP server, the SDK calls `call_tool()` on that server.
33
+
34
+
```python
35
+
36
+
agent=Agent(
37
+
name="Assistant",
38
+
instructions="Use the tools to achieve the task",
39
+
mcp_servers=[mcp_server_1, mcp_server_2]
40
+
)
41
+
```
42
+
43
+
## Caching
44
+
45
+
Every time an Agent runs, it calls `list_tools()` on the MCP server. This can be a latency hit, especially if the server is a remote server. To automatically cache the list of tools, you can pass `cache_tools_list=True` to both [`MCPServerStdio`][agents.mcp.server.MCPServerStdio] and [`MCPServerSse`][agents.mcp.server.MCPServerSse]. You should only do this if you're certain the tool list will not change.
46
+
47
+
If you want to invalidate the cache, you can call `invalidate_tools_cache()` on the servers.
48
+
49
+
## End-to-end example
50
+
51
+
View complete working examples at [examples/mcp](https://github.com/openai/openai-agents-python/tree/main/examples/mcp).
0 commit comments