Using the FastMCP Client to Call MCP Servers
Connect to local or remote servers from Python, call tools, read resources and handle results and errors.
Read articleHow the STDIO and HTTP transports differ, when to use each and how to switch between them with a single argument.

/mcp endpoint for remote clients.transport="http" or the --transport flag.A transport is the channel that carries MCP messages between client and server. FastMCP supports both the local and the remote options, and switching between them requires changing a single argument. This guide explains how each one works, when to choose it and what to configure before you go live.
MCP messages are JSON-RPC requests and responses. The protocol defines what those messages contain; the transport decides how they travel. Your tools, resources and prompts are identical whichever transport you use, which is why FastMCP can switch between them without code changes elsewhere.
FastMCP offers three values for the transport setting:
stdio – the default, for local processes;http – Streamable HTTP, for remote access and the recommended choice for new network deployments;sse – Server-Sent Events, a legacy option kept for older clients.With STDIO, the client starts your server as a child process and the two exchange messages through standard input and standard output. Nothing listens on a network port.
if __name__ == "__main__":
mcp.run() # STDIO is the defaultUse STDIO when a desktop AI application or an IDE runs the server on the same machine. Each client gets its own process, which keeps things simple and isolated, and there is no port to secure.
Most MCP host applications describe local servers with a JSON configuration containing an mcpServers section. Each entry names the command that starts the server:
{
"mcpServers": {
"notes": {
"command": "uv",
"args": ["run", "--directory", "/path/to/notes-server", "fastmcp", "run", "my_server.py"]
}
}
}Running through uv run ensures the server starts with its own environment, regardless of how the host application was launched. Check your host’s documentation for the exact location of its configuration file.
print() for logging in a STDIO server. Write to standard error, or use the context object’s logging methods instead.The HTTP transport runs your server as a web service. Clients send requests to a single endpoint, /mcp by default, and responses can stream back to them.
if __name__ == "__main__":
mcp.run(transport="http", host="0.0.0.0", port=8000)The endpoint is then http://localhost:8000/mcp. Choose HTTP when several clients share one server, when the server runs on another machine or when you deploy to the cloud. If /mcp clashes with an existing route, change the path:
mcp.run(transport="http", port=8000, path="/api/mcp")mcp.run() starts its own event loop, so it must not be called from inside an async function. Use the awaitable variant there:
await mcp.run_async(transport="http", port=8000)For production, you may prefer to create an ASGI app and serve it with Uvicorn, which gives you control over workers and middleware:
app = mcp.http_app()uvicorn app:app --host 0.0.0.0 --port 8000The FastMCP CLI accepts the same choice as flags, so one file can serve both purposes without edits:
fastmcp run my_server.py # STDIO
fastmcp run my_server.py --transport http --port 8000 # HTTP
fastmcp run my_server.py -t http --host 0.0.0.0 --path /api/mcp| Flag | Purpose | Default |
|---|---|---|
--transport, -t | Choose stdio, http or sse | stdio |
--host | Network address to bind to | 127.0.0.1 |
--port, -p | Port to listen on | 8000 |
--path | URL path of the endpoint | /mcp |
--stateless | Run without sessions | Off |
--log-level, -l | Set verbosity, from DEBUG to CRITICAL | – |
--reload | Restart when files change | Off |
Note that the CLI binds to 127.0.0.1 by default, which accepts connections only from the same machine. Use --host 0.0.0.0 inside containers or when other machines must connect.
| STDIO | HTTP | |
|---|---|---|
| Where it runs | Same machine as the client | Anywhere reachable over a network |
| Who starts it | The client launches the process | You run it as a service |
| Clients per server | One | Many |
| Authentication | Usually unnecessary | Strongly recommended |
| Scaling | One process per client | Workers and load balancers |
| Typical use | Desktop apps, IDEs, personal tools | Team services, cloud deployments |
The FastMCP client infers the transport from what you pass it. A path to a Python file starts a local STDIO process; a URL connects over HTTP; a server object connects in memory, which is ideal for tests.
from pathlib import Path
from fastmcp import Client
local = Client(Path("my_server.py")) # STDIO
remote = Client("https://example.com/mcp") # HTTP
in_memory = Client(mcp) # same processThe CLI can even bridge the two worlds: fastmcp run https://example.com/mcp starts a local proxy for a remote server, so a STDIO-only host can reach it.
print() calls.127.0.0.1 is unreachable from other machines.proxy_buffering off in nginx.The deployment guide covers the remote checklist in detail.
Only for older clients that require it. The FastMCP documentation recommends the HTTP transport for new projects, and SSE does not support the CLI's reload mode.
Yes. The same code runs with either transport. Choose at launch time with mcp.run() arguments or the --transport flag, so local and remote use need no separate versions.
The CLI binds to 127.0.0.1 by default, which accepts local connections only. Use --host 0.0.0.0, and check firewalls and container port mappings.
Something is writing to standard output, which carries the protocol messages. Remove print() calls and log through the context object or to standard error instead.
Connect to local or remote servers from Python, call tools, read resources and handle results and errors.
Read articleProtect remote servers with JWT verification, token introspection or OAuth, and adopt habits that keep secrets safe.
Read articleRun your server over HTTP, add health checks, scale with stateless mode and put it behind systemd and nginx.
Read article