Agent(tools=[...]) is process boundaries. A tool that needs a database credential, a GPU, or a private network can live where those things are, and agents reach it over HTTP.
Prerequisites
mcp 2.x renamed FastMCP to MCPServer and moved it to mcp.server.mcpserver. On mcp 1.x, import from mcp.server.fastmcp import FastMCP instead; the decorator and run() call below are the same. The swarms client works with both.Build it
1
Write the server
An Return a string, and make errors part of that string. An agent can reason about “Could not find data for bitcion”; it cannot reason about a traceback.
MCPServer is a Python module with decorated functions. The decorator’s name and description are what the model sees, so write them for a reader who has no other context.2
Run it
http://127.0.0.1:8000/mcp. Leave it running.3
Point an agent at it
In a second terminal:Identical to every hosted-server example in this section — only the URL differs.
4
Inspect the server without an agent
When a tool call misbehaves, take the model out of the loop. If
MCPManager is the class the agent uses internally:call_tool returns what you expect and the agent still gets it wrong, the problem is the description or the prompt — not the server.Tuning a connection to a local server
MCPConnection gives you per-server timeouts and headers:
MCP tools plus your own Python tools
The two coexist on one agent — MCP tools come from the server, andtools_list_dictionary (or tools=[...]) adds your own:
An agent as a tool
To serve a swarmsAgent, or a whole swarm, as an MCP tool, you do not need to write a server by hand. MCPDeployer wraps it, puts an auth layer in front, and serves it:
Writing tools an agent can use well
Sources: examples/mcp/servers/ and examples/mcp/client/
Next
- MCPManager API — the full client surface: async calls, multi-server routing, caching.
- Model Context Protocol (MCP) — transports, OAuth, and error handling in depth.