Skip to main content
Everything else in this section connects to somebody else’s server. This one is the other half: putting your functions behind MCP so any agent — or any MCP client, in any language, on any machine — can call them. The reason to do this rather than pass Python functions to 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

Build it

1

Write the server

A FastMCP server 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.
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.
2

Run it

It serves on http://localhost: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. MCPManager is the class the agent uses internally:
If 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, and tools_list_dictionary (or tools=[...]) adds your own:

An agent as a tool

The most interesting server in the examples folder wraps a whole swarms Agent as a single MCP tool, so another agent — or any MCP client — can spawn and run it remotely:
That is how you compose swarms across process or machine boundaries: the calling agent does not know or care that the tool it invoked is itself an agent.

Writing tools an agent can use well

Next