Skip to main content
Every other page in this section points an agent at an MCP server. This one makes an agent into one. Once it is served, any MCP client can call it as a tool: another Swarms agent, Claude Desktop, Cursor, or a script in another language.

Prerequisites

MCPDeployer needs mcp 2.0.0 or newer.

Build it

1

Write the server

The agent you want to share is an ordinary Agent. agent_description becomes the tool description the calling model reads, so write it for a reader with no other context.
server.py
The tool is named after the agent: Market-Analyst becomes market_analyst.
2

Run it

It prints a banner with the URL and keeps serving. Leave it running.
3

Check it from a second terminal

/health is public:
The MCP endpoint is not. A request with no key, or the wrong one, gets 401:
4

Call it from another agent

The client is an ordinary agent too. MCPConnection carries the URL and the key.
client.py
The portfolio manager discovers market_analyst, calls it with the question as task, and summarises what the analyst returned. The server terminal logs each request.

What just happened

  1. MCPDeployer wrapped analyst as one MCP tool with the schema task: str, img: str | None.
  2. Every request to /mcp went through the auth layer first. The key can arrive as x-api-key or as Authorization: Bearer, which is what MCPConnection sends.
  3. The tool call ran analyst.run(task) on a worker thread and returned its answer as the tool result.

Variations

Keys from the environment instead of the code. api_key_env reads a comma-separated list, so you can rotate keys without a code change:
Run the server inside your own script. start() and stop(), or a with block, run it on a background thread:
Reachable from other machines. Bind to all interfaces and put TLS in front of it:
Launched by an MCP host. Claude Desktop and similar hosts start servers as subprocesses over stdio. There are no HTTP headers on stdio, so the host itself is the security boundary:

Next

Serve a team from one server

Several agents, a workflow, and a function, each its own tool.

MCPDeployer reference

Every parameter, auth mode, and method.