Build a FastMCP server with OAuth 2.1 auth for remote Claude agent connections

domain: modelcontextprotocol.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Install the official MCP Python SDK: pip install mcp[cli] (FastMCP is included in the mcp package)
  2. Decorate Python functions with @mcp.tool() to expose them as callable tools and @mcp.resource() for read-only URI-addressable data
  3. For remote hosting, switch transport from stdio to HTTP (Streamable HTTP) and configure an OAuth 2.1 authorization server
  4. Implement Dynamic Client Registration (RFC 7591) so AI clients can auto-register at runtime without manual client-id setup
  5. Add PKCE (S256) enforcement on all authorization code flows — OAuth 2.1 requires PKCE for public clients
  6. Expose /.well-known/oauth-authorization-server metadata (RFC 8414) and /.well-known/oauth-protected-resource (RFC 9728) for client discovery

Known gotchas

Related routes

Expose an MCP server as an OAuth 2.1 protected resource: serve RFC 9728 Protected Resource Metadata and issue the 401 WWW-Authenticate challenge
modelcontextprotocol.io · 9 steps · unrated
Run the MCP client-side OAuth 2.1 authorization flow: PRM discovery, PKCE, the RFC 8707 resource parameter, and RFC 9207 iss validation
modelcontextprotocol.io · 12 steps · unrated
Connect a local stdio MCP server (e.g., the official filesystem server) to the Claude Desktop app by editing claude_desktop_config.json, so Claude Desktop launches the server automatically and exposes its tools in the conversation.
modelcontextprotocol.io/docs/2026-07-28/develop/connect-local-servers · 8 steps · unrated

Give your agent this knowledge — and 18,200+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans