openai-agents-python/examples/mcp/filesystem_example
Carmen(Jia) Liu e827dfe75f
Fix: Correct the trace path in examples (#395)
### What changed?
The trace URL was using the wrong path format:
- Old: `/traces/{trace_id}`
- Fixed: `/traces/trace?trace_id={trace_id}`

<img width="781" alt="Screenshot 2025-03-30 at 5 54 11 pm"
src="https://github.com/user-attachments/assets/982fbb1d-7163-4438-b237-493e3100b5c7"
/>
2025-04-01 11:51:52 -04:00
..
sample_files [3/n] Add an MCP stdio example 2025-03-25 13:24:18 -04:00
main.py Fix: Correct the trace path in examples (#395) 2025-04-01 11:51:52 -04:00
README.md Hotfix mcp example (#365) 2025-03-27 13:05:30 -04:00

MCP Filesystem Example

This example uses the filesystem MCP server, running locally via npx.

Run it via:

uv run python examples/mcp/filesystem_example/main.py

Details

The example uses the MCPServerStdio class from agents.mcp, with the command:

npx -y "@modelcontextprotocol/server-filesystem" <samples_directory>

It's only given access to the sample_files directory adjacent to the example, which contains some sample data.

Under the hood:

  1. The server is spun up in a subprocess, and exposes a bunch of tools like list_directory(), read_file(), etc.
  2. We add the server instance to the Agent via mcp_agents.
  3. Each time the agent runs, we call out to the MCP server to fetch the list of tools via server.list_tools().
  4. If the LLM chooses to use an MCP tool, we call the MCP server to run the tool via server.run_tool().