FastMCP Transports: STDIO vs HTTP

How the STDIO and HTTP transports differ, when to use each and how to switch between them with a single argument.

Diagram comparing a local STDIO connection with a remote HTTP connection to a FastMCP server

Key takeaways

  • STDIO is the default and suits local desktop hosts.
  • HTTP serves a single /mcp endpoint for remote clients.
  • Switch with transport="http" or the --transport flag.
  • Remote servers need authentication, HTTPS and, with several workers, stateless mode.

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.

What a Transport Does

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.

STDIO: Local Processes

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 default

Use 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.

Configuring a desktop host

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.

Because standard output carries protocol messages, never use print() for logging in a STDIO server. Write to standard error, or use the context object’s logging methods instead.

HTTP: Remote Access

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")

Inside async code

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)

As an ASGI application

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 8000

Switching from the Command Line

The 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
FlagPurposeDefault
--transport, -tChoose stdio, http or ssestdio
--hostNetwork address to bind to127.0.0.1
--port, -pPort to listen on8000
--pathURL path of the endpoint/mcp
--statelessRun without sessionsOff
--log-level, -lSet verbosity, from DEBUG to CRITICAL–
--reloadRestart when files changeOff

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.

Side-by-Side Comparison

STDIOHTTP
Where it runsSame machine as the clientAnywhere reachable over a network
Who starts itThe client launches the processYou run it as a service
Clients per serverOneMany
AuthenticationUsually unnecessaryStrongly recommended
ScalingOne process per clientWorkers and load balancers
Typical useDesktop apps, IDEs, personal toolsTeam services, cloud deployments

How Clients Choose a Transport

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 process

The 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.

Before You Go Remote

  • Add authentication. Some clients refuse to connect to remote servers without it.
  • Serve the endpoint over HTTPS, usually through a reverse proxy such as nginx.
  • Enable CORS only for browser-based clients, and list exact origins rather than a wildcard.
  • Use stateless mode if you run several workers behind a load balancer, because sessions otherwise live in a single process’s memory.

Troubleshooting

  • The host shows no tools – run the configured command yourself in a terminal; import errors and missing dependencies are reported there.
  • Garbled responses over STDIO – something is writing to standard output. Remove stray print() calls.
  • “Connection refused” over HTTP – check the host and port, and remember that 127.0.0.1 is unreachable from other machines.
  • Streaming stalls behind a proxy – disable response buffering, for example with proxy_buffering off in nginx.

The deployment guide covers the remote checklist in detail.

Frequently Asked Questions

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.

Keep reading

Related Guides