Skip to main content
MCPContextProvider wraps a single MCP server as a context provider. Instructions for the sub-agent are built dynamically from the server’s list_tools() response at connect time, so the calling agent never sees stale tool docs.
mcp_server.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

4

Run the example

Save the code above as mcp_server.py, then run:
Full source: cookbook/12_context/06_mcp_server.py