MCP Server OAuth 2.1

Built-in OAuth 2.1 authorization server for praisonai mcp serve –transport http-stream (PRM, CIMD + DCR, PKCE, device flow)

praisonai mcp serve --transport http-stream includes a built-in OAuth 2.1 authorization server so editors and coding agents sign in to your remote PraisonAI MCP server automatically — no static API keys to distribute.

python
from praisonaiagents import Agent

agent = Agent(name="RemoteHelper", instructions="Serve authorised MCP tool calls.")
agent.start("List available capabilities")

Start the HTTP-stream host on a network address (or with --oauth locally) and editors like Cursor, VS Code, Claude Code, Zed, Antigravity, Kiro, Codex, Goose, and OpenCode discover the login flow automatically.

Diagram

MCP Server OAuth 2.1

1. 401 + resource_metadata
2. CIMD or DCR + PKCE S256
3. Scoped Bearer Token

💻 Editor / Agent

🔎 RFC 9728 / 8414

🔐 Owner Consent

✅ praisonai mcp serve

Quick Start

  1. Install with server and auth extras
    bash
    pip install "praisonai-mcp[all]"
    # or via the umbrella package:
    pip install "praisonai[mcp]"
  2. Start an OAuth-protected remote MCP server

    Local stdio and --host 127.0.0.1 remain zero-auth. Binding to a non-loopback address without --api-key or --keys-file turns OAuth 2.1 on automatically (or pass --oauth to enable it on localhost too):

    bash
    PRAISONAI_MCP_OWNER_KEY="choose-a-strong-owner-key" \
    praisonai mcp serve --transport http-stream \
      --host 0.0.0.0 \
      --issuer https://agents.example.com

    If PRAISONAI_MCP_OWNER_KEY is unset, a one-time owner key is generated and printed at startup.

  3. Approve on the consent page

    When an editor connects, it opens your browser to the consent page. Enter the owner key once, review whether the client is Verified or On this device, untick any scopes you want to withhold (or click Allow read-only), pick a lifetime, and approve.


How It Works

Diagram
Owner Browserpraisonai mcp serveMCP ClientOwner Browserpraisonai mcp serveMCP ClientPOST /mcp (unauthenticated)401 + WWW-Authenticate: Bearer resource_metadata=…GET /.well-known/oauth-protected-resource & oauth-authorization-serverCIMD (https client_id) or POST /oauth/register (DCR)Open /oauth/authorize (PKCE S256 + resource)Verify owner key + approve selected scopesAuthorization code (or error=access_denied on Deny)POST /oauth/token (code + verifier)Opaque access token + single-use rotating refresh tokenPOST /mcp (Authorization: Bearer …)200 OK
Standard / FeatureBehaviour
DiscoveryReturns 401 + WWW-Authenticate: Bearer resource_metadata=... with Protected Resource Metadata (RFC 9728) and Authorization Server Metadata (RFC 8414).
PKCE + AudienceAuthorization code with PKCE S256 only (RFC 7636) for public clients; tokens are audience-bound to the requested resource (RFC 8707).
Client verification (CIMD + DCR)Supports Dynamic Client Registration (RFC 7591) and Client ID Metadata Documents (https client_id, 64 KiB cap, 1 h cache). Known editors (VS Code, Zed, Kiro, Antigravity, Claude Code, ChatGPT/Codex, Goose, OpenCode, Cursor, Claude) display as Verified; loopback redirects display as On this device (RFC 8252); unknown apps display an explicit warning.
Rotating refresh tokensRefresh tokens are single-use and rotate on every refresh. Replaying an already-used refresh token revokes the entire grant.
Headless / SSH device flowRFC 8628 device flow: POST /oauth/device, then open /oauth/device/verify and enter the user code (e.g. ABCD-EFGH).
Manage & revoke appsGET /oauth/apps and POST /oauth/apps/<id>/revoke (with the owner key as Bearer), plus RFC 7009 client-initiated revocation.
Hashed storageTokens are opaque; only SHA-256 hashes are stored in oauth.json (0600) inside the PraisonAI MCP data folder.

Choosing an Auth Mode

Diagram

Local stdio or 127.0.0.1

Public / team network with editors

Scripts / CI with static keys

Where does praisonai mcp serve run?

⚡ Zero-auth default

🔐 Built-in OAuth 2.1
default on 0.0.0.0 without API key

🗝️ –api-key or –keys-file


Best Practices

Set –issuer to your public HTTPS URL

Always pass --issuer https://your-domain.example behind TLS so OAuth discovery metadata and token audiences match the URL clients connect to.

Use Allow read-only for untrusted or exploratory clients

The consent page lets you untick tools:call or click Allow read-only so a client can inspect tools and resources without executing actions.

Use the device flow over SSH or containers

For headless terminals where opening a local browser callback is awkward, use the built-in RFC 8628 device flow (/oauth/device → /oauth/device/verify).


Related