cai/examples/mcp/filesystem_example
@uayucar a723b9cd45 chore: sync repository with cai-public-staging snapshot
Replace entire working tree with contents of /Users/unai/cai-public-staging.
This is a wholesale overwrite reflecting the current public staging state.

Co-Authored-By: Claude (claude-opus-4-7) <noreply@anthropic.com>
2026-06-05 12:50:21 +02:00
..
sample_files [3/n] Add an MCP stdio example 2025-03-25 13:24:18 -04:00
README.md chore: sync repository with cai-public-staging snapshot 2026-06-05 12:50:21 +02:00
main.py [5/n] MCP tracing 2025-03-25 19:28:48 -04:00

README.md

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_servers=[...].
  3. Each time the agent runs, we call out to the MCP server to fetch the list of tools via server.list_tools(). The result can be cached when configured.
  4. If the LLM chooses to use an MCP tool, the runtime calls the server via server.call_tool().