Guides
Serve agents over MCP
By the end of this page your registered agents will appear as tools inside Claude Desktop and Cursor, and you will know how to host the same server as a remote HTTP endpoint — standalone or embedded in an existing FastAPI app.
--host/--port.REPLICATE_API_TOKEN exported, and Claude Desktop or Cursor installed for the client steps.The Model Context Protocol (MCP) is the wire format clients like Claude Desktop
use to discover and call external tools. The core idea of this page: every registered agent
becomes an MCP tool. The server walks the agent registry at startup, turns each
AgentMetadata record into a tool definition (the safe_name becomes the tool
name, the description and input_schema travel with it), and also exposes a
models://list resource that returns every agent with its model path, tags, and live
routing statistics. Two default agents ship pre-registered so the server is never empty:
llama3_chat (meta/meta-llama-3-70b-instruct) and flux_pro
(black-forest-labs/flux-1.1-pro).
Steps
-
Run the server over stdio
The default transport — the client launches the process and talks over stdin/stdout.
-
Register with Claude Desktop and Cursor
One JSON entry tells the client how to launch
replicate-mcp-serverand which env vars to pass. -
Host it remotely over HTTP
--transport sseorstreamable-httpturns the same server into a network endpoint. -
Load workflows at startup
--workflows-fileregisters declarative YAML workflows before the server accepts connections.
1. Run the server over stdio
Stdio is the right transport for desktop clients: the client owns the process lifecycle, so there is no port, no daemon, and nothing to clean up. Run it once by hand to confirm it starts:
replicate-agent serve --transport stdio
--transport stdio is the default, so plain replicate-agent serve does the
same thing. If you instead see ⚠ REPLICATE_API_TOKEN is not set. Tool calls will fail until it
is exported., the server still starts — discovery works, but every tool call will return an
error until the token is present. The process now waits for a client on stdin; press
Ctrl+C to exit. The package also installs a second executable,
replicate-mcp-server, which is the stdio entrypoint without the CLI wrapper — that is
the one desktop clients launch in the next step.
2. Register with Claude Desktop
Add this entry to ~/.config/claude/mcp_config.json (create the file if it does not
exist):
{
"mcpServers": {
"replicate-agent": {
"command": "poetry",
"args": ["run", "replicate-mcp-server"],
"env": {
"REPLICATE_API_TOKEN": "${REPLICATE_API_TOKEN}"
}
}
}
}
The example uses poetry run for a source checkout; if you installed from PyPI into a
plain virtualenv, set command to the absolute path of the
replicate-mcp-server script instead. Restart Claude Desktop and open the tool palette —
you should see llama3_chat and flux_pro listed, plus any agents your own
modules register.
Cursor uses the same server definition. Point Cursor's MCP settings at the
identical command/args/env trio; the protocol and the
executable are unchanged, only the location of the config differs by client.
3. Host it remotely over HTTP
For a shared or cloud-hosted endpoint, switch the transport. sse serves the
established Server-Sent Events transport; streamable-http is the modern MCP 1.x
successor with bidirectional streaming over a single connection. Both require
uvicorn (pip install uvicorn).
replicate-agent serve --transport sse --host 0.0.0.0 --port 8080
The defaults are --host 0.0.0.0 and --port 8080; add
--mount-path to prefix the SSE endpoint URL and --log-level info to tune
uvicorn's verbosity. For Streamable HTTP, the shape is the same:
replicate-agent serve --transport streamable-http --host 0.0.0.0 --port 9090. The same
three deployments exist as Python entry points in replicate_mcp.server —
serve_http(host, port, mount_path, log_level) for SSE,
serve_streamable_http(host, port, log_level), and get_asgi_app() when you
want the ASGI application object instead of a running process:
from fastapi import FastAPI
from replicate_mcp.server import get_asgi_app
app = FastAPI()
mcp_app = get_asgi_app(transport="sse", mount_path="/mcp")
app.mount("/mcp", mcp_app)
4. Load workflows at startup
If you have declarative workflows in YAML (covered in Agents & workflows), pass the file at serve time and they are registered before the first client connects:
replicate-agent serve --transport sse --workflows-file workflows.yaml
Verification
You're done when
- Claude Desktop's tool palette lists
llama3_chatandflux_proafter a full restart. replicate-agent agents listshowsllama3_chatwith modelmeta/meta-llama-3-70b-instruct.- For HTTP transports, the console shows
Uvicorn running on http://0.0.0.0:8080and a client can connect to the endpoint.
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
| Tools never appear in Claude Desktop | Config saved to the wrong path, malformed JSON, or the app was not fully restarted | Confirm the file is ~/.config/claude/mcp_config.json, validate the JSON, then quit and relaunch the app — not just the window |
Tools appear, but every call returns {"error": "REPLICATE_API_TOKEN environment variable is not set."} |
The GUI app did not inherit your shell's export, and the config's env block resolved to nothing |
Put the token in the env block of the server entry (or launch the app from an environment where it is set), then restart |
[Errno 98] address already in use on startup |
Another process is bound to port 8080 | Pick another port with --port 8081, or find the holder with lsof -i :8080 and stop it |
Next steps
- Agents & workflows — register your own agents so they show up as MCP tools, and compose them into pipelines.
- CLI reference — every
serveflag, plus theagents,workflows, andauditsub-commands. - Distributed execution — scale beyond one host with worker nodes and a coordinator.