Why turn an agent into an MCP server?
Exposing your mcp-agent app as an MCP server lets any MCP-compatible client (Claude Desktop, Cursor, VS Code, custom tooling) call your workflows over the standard protocol. It is the easiest way to:- Reuse an agent from multiple clients without rewriting logic
- Chain agents together (one agent can call another as a server)
- Deploy long-running workflows on dedicated infrastructure
examples/mcp_agent_server/asyncio– in-memory execution, great for local testingexamples/mcp_agent_server/temporal– durable execution backed by Temporal
Execution modes
- Asyncio – Runs entirely in-memory with minimal setup. Perfect for local development, demos, or lightweight agents.
- Temporal – Uses the Temporal orchestration engine for durable, resumable workflows with retries and pause/resume.
execution_engine setting.
Prerequisites
Before running the examples you will need:- Python 3.10+
- uv for dependency management
- API keys for the model providers referenced in the example (OpenAI / Anthropic)
- A copy of the example secrets file:
Quick start (asyncio)
examples/mcp_agent_server/asyncio/main.py
examples/mcp_agent_server/asyncio directory):
- Populate
mcp_agent.secrets.yaml(or export environment variables) with your provider keys. - Run
uv run main.pyto start the server. - Run
uv run client.pyto invoke the tools and watch status updates.
@app.toolexposes a synchronous MCP tool. The client gets the final result immediately.@app.async_toolis designed for long-running work. It starts a workflow in the background, returnsworkflow_id/run_id, and the client pollsworkflows-get_statusuntil completion.- Under the hood you can launch any
Workflow(see the Workflow class documentation) from inside an async tool.
client.py shows how to call your server with gen_client, and the README covers Claude Desktop / MCP Inspector connections.
Temporal variant
Use the Temporal example when you need durable execution, pause/resume, or production-grade retries. It follows the same pattern as above but usescreate_temporal_worker_for_app to run workflows on a Temporal cluster. See examples/mcp_agent_server/temporal for setup instructions. In short:
- Start a Temporal server locally (
temporal server start-dev). - Run
uv run run_worker.pyto start the worker that hosts your workflows. - In another terminal run
uv run main.pyto expose the MCP endpoint. - Connect using
uv run client.pyor any MCP client.
Predefined Tools
When you callcreate_mcp_server_for_app(app) the server registers:
- Every
@app.tool/@app.async_tooldefined on the app - Workflow entry points (e.g.
workflows-<Workflow>-run) for explicit@app.workflowclasses - A set of management tools that every MCP client can rely on:
workflows-list– discover available workflows, parameter schemas, and tool names.workflows-run– start a workflow synchronously and receiveworkflow_id/run_id.workflows-get_status– poll for status, outputs, or errors.workflows-cancel– terminate a running workflow.workflows-resume– resume paused workflows (useful with Temporal + signals).
Connecting from MCP clients
- Claude Desktop – add an entry in
~/.claude-desktop/config.jsonpointing touv run main.py(the asyncio example README includes a copy-paste snippet). - MCP Inspector – run
npx @modelcontextprotocol/inspectorand point it at your server command. - Custom code – reuse the
gen_clientexample provided in each folder.
Deployment options
- Run locally via
uv run - Package and deploy the command anywhere you can run Python
- Use
uv run mcp-agent deploy …to publish to mcp-agent cloud (the example README outlines the CLI flow)
Connecting from common MCP clients
Claude Desktop
Update~/.claude-desktop/config.json with a command that starts your server:
mcp-remote plus your SSE endpoint and bearer token, as shown in the example README.
MCP Inspector
grade_story, grade_story_async, workflows-list, etc.) so you can interactively test them.
Programmatic access (gen_client)
Next steps
- Browse the asyncio and Temporal READMEs for end-to-end workflows, screenshots, and configuration details.
- Review Server Authentication if your server needs API keys or OAuth.
- Combine agent servers with other agents to build multi-agent ecosystems over MCP.
