Give the agent the tools of an MCP server. MicrosoftAgentFrameworkPlugin(mcp_clients={"echo": ...}) registers the server on the Worker. TemporalMCPToolProvider("echo") in Agent(context_providers=[...]) lists the server's tools before each run and turns each call into an Activity:
| Activity | When it runs |
|---|---|
temporalio.mcp.echo.list-tools |
Before each agent.run, because cache_tools defaults to False |
temporalio.mcp.echo.call-tool |
Each time the model calls a tool of the server |
The included echo_mcp_server.py is a one-tool server built on the MCP Python SDK's MCPServer. The Worker starts it over stdio with sys.executable on the first MCP Activity and keeps the connection for 5 minutes of idleness. Swap in any MCP server by changing the factory in run_worker.py.
This sample is its own uv project. The plugin's MCP support needs MCP Python SDK 2, and other samples in this repository still pin SDK 1, so the two cannot share one lock file.
MicrosoftAgentFrameworkPlugin(mcp_clients=...)with a factory that returns anmcp.ClientTemporalMCPToolProvideras a context provider, with a 30-second start-to-close timeout for its list and call Activities and the plugin's default 10-second heartbeat timeout; the Activities heartbeat every 5 seconds while they run- The model sees the server's tool schema; the server's connection never leaves the Worker
Prerequisites: Python 3.11 or later, OPENAI_API_KEY in the Worker's environment, and a Temporal dev server (temporal server start-dev). Change to this directory first:
cd microsoft_agent_framework_plugin/mcp
uv sync# Terminal 1
uv run run_worker.py
# Terminal 2
uv run run_workflow.pyThe Worker spawns the server itself. The starter prints the agent's answer, and the Workflow microsoft-agent-framework-mcp shows one temporalio.mcp.echo.list-tools, two microsoft_agent_framework.invoke_model and one temporalio.mcp.echo.call-tool Activity.
uv run poe test runs the Workflow against the plugin's scripted chat client and the real echo server, with no API key. uv run poe lint runs ruff and mypy.
| File | Description |
|---|---|
echo_mcp_server.py |
MCPServer with one echo tool, served over stdio |
workflow.py |
MCPWorkflow with TemporalMCPToolProvider("echo") |
run_worker.py |
Registers the chat client and the MCP server factories, starts the Worker |
run_workflow.py |
Executes the Workflow and prints the result |
tests/mcp_test.py |
Asserts on the model and MCP Activities in the history |