FastMCP can serve the same server over stdio or Streamable HTTP. Remote mode changes the security model: the server is now reachable by anything that can hit the port, and every request must be authenticated and authorized. Host binding, TLS, and client configuration are part of the implementation.
Run the server in HTTP mode
from mcp.server.fastmcp import FastMCP
mcp = FastMCP(
"status-mcp",
host="127.0.0.1",
port=8000,
stateless_http=True,
)
@mcp.tool()
def get_status() -> str:
"""Return a non-sensitive service status."""
return '{"status":"ok"}'
if __name__ == "__main__":
mcp.run(transport="streamable-http")
The exact constructor options (host, port, stateless_http, and the endpoint path) depend on the SDK version. Check the SDK documentation for the version you pinned. The important architecture point is that HTTP mode is a separate deployment surface, not a flag you flip casually.
Bind to 127.0.0.1 during development. For a container, bind to the container interface but publish only through a reverse proxy with TLS and authentication. Do not expose port 8000 directly to the internet.
Authentication belongs in front of the tools
A tool should not ask the model for an API key. Authentication happens at the HTTP boundary or through the SDK’s auth providers; authorization happens per request and per resource. A valid token for tenant A must not be able to invoke a tool against tenant B.
At minimum:
- Require HTTPS.
- Require a bearer token or OAuth access token on every MCP request.
- Verify the token’s issuer, audience, expiry, and required scope.
- Pass the authenticated tenant identity into the tool context.
- Check resource-level authorization inside each tool.
Do not rely on a secret URL. Do not accept credentials in query strings; they leak through logs and browser history.
The exact auth integration API changes between SDK versions. If you cannot verify it for your pinned version, put authentication in the reverse proxy and pass a signed identity header to the server, then validate that header at the app boundary. Document the trust boundary.
Protocol behavior
Modern Streamable HTTP uses a single endpoint. POST requests carry JSON-RPC. The client may request an SSE stream for a particular request. Protocol version headers must be preserved by proxies.
The 2026-07-28 revision removed HTTP sessions. If you use an SDK version that creates session IDs, understand whether it implements an older revision, and test with the client versions you intend to support. A server that works with a spec-2025 client may not work with a spec-2026 client without an upgrade.
Reverse proxy checklist
- Terminate TLS with a current certificate and full chain.
- Preserve
Authorization,Accept,Content-Type, and MCP headers. - Disable proxy buffering for streaming responses.
- Set request body limits.
- Set upstream timeouts longer than your slowest expected tool call but bounded.
- Remove or redact sensitive query strings from access logs.
- Do not expose an admin/metrics port publicly without its own auth.
Test with a real client
A health check is not an MCP test. Use MCP Inspector in HTTP mode or configure a client against the endpoint:
npx @modelcontextprotocol/inspector
Choose the streamable HTTP transport and enter the full endpoint URL. Verify:
- Unauthenticated requests are rejected.
- Authenticated initialization succeeds.
- Tool discovery returns only the intended tools.
- A read-only call succeeds.
- A cross-tenant request is denied.
- A timeout returns a controlled error.
- TLS and Origin checks behave as configured.
Check the 401 guide and TLS guide if the handshake or authentication fails before MCP messages appear.
Deployment shape
For a small deployment, one container behind a TLS proxy is enough. For multiple replicas:
- Make the server stateless or externalize session state.
- Use sticky sessions only if the protocol revision requires them.
- Ensure every replica sees the same tool definitions and credentials.
- Apply rate limits at the edge and inside the server.
- Roll out protocol or SDK upgrades in a canary, then verify with a client.
Do not claim production readiness without exercising authentication, authorization, failure, and rollback paths. The deployment guide and production checklist cover the release mechanics.
Sources
Sources were checked on Oct 23, 2026. Versions and client behavior can change; confirm the current documentation before relying on a configuration.