> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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.

> [!NOTE]
>
> This page covers the **server side** — PraisonAI acting as the OAuth 2.1 authorization server for incoming MCP clients. For a PraisonAI agent connecting as a **client** to an external OAuth-protected MCP server, see [MCP OAuth Authentication](https://praison.ai/docs/mcp/mcp-oauth.md).

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "MCP Server OAuth 2.1"
        Client[💻 Editor / Agent] -->|1. 401 + resource_metadata| PRM[🔎 RFC 9728 / 8414]
        PRM -->|2. CIMD or DCR + PKCE S256| Consent[🔐 Owner Consent]
        Consent -->|3. Scoped Bearer Token| MCP[✅ praisonai mcp serve]
    end

    classDef client fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef disc fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef auth fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef ok fill:#10B981,stroke:#7C90A0,color:#fff

    class Client client
    class PRM disc
    class Consent auth
    class MCP ok
```

## Quick Start

**1. Install with server and auth extras**

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant Editor as MCP Client
    participant Server as praisonai mcp serve
    participant Owner as Owner Browser

    Editor->>Server: POST /mcp (unauthenticated)
    Server-->>Editor: 401 + WWW-Authenticate: Bearer resource_metadata=...
    Editor->>Server: GET /.well-known/oauth-protected-resource & oauth-authorization-server
    Editor->>Server: CIMD (https client_id) or POST /oauth/register (DCR)
    Editor->>Owner: Open /oauth/authorize (PKCE S256 + resource)
    Owner->>Server: Verify owner key + approve selected scopes
    Server-->>Editor: Authorization code (or error=access_denied on Deny)
    Editor->>Server: POST /oauth/token (code + verifier)
    Server-->>Editor: Opaque access token + single-use rotating refresh token
    Editor->>Server: POST /mcp (Authorization: Bearer ...)
    Server-->>Editor: 200 OK
```

| Standard / Feature | Behaviour |
| - | - |
| **Discovery** | Returns `401` + `WWW-Authenticate: Bearer resource_metadata=...` with Protected Resource Metadata (RFC 9728) and Authorization Server Metadata (RFC 8414). |
| **PKCE + Audience** | Authorization 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 tokens** | Refresh tokens are single-use and rotate on every refresh. Replaying an already-used refresh token revokes the entire grant. |
| **Headless / SSH device flow** | RFC 8628 device flow: `POST /oauth/device`, then open `/oauth/device/verify` and enter the user code (e.g. `ABCD-EFGH`). |
| **Manage & revoke apps** | `GET /oauth/apps` and `POST /oauth/apps/<id>/revoke` (with the owner key as Bearer), plus RFC 7009 client-initiated revocation. |
| **Hashed storage** | Tokens are opaque; only SHA-256 hashes are stored in `oauth.json` (`0600`) inside the PraisonAI MCP data folder. |

***

## Choosing an Auth Mode

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    Q{Where does praisonai mcp serve run?}
    Q -->|Local stdio or 127.0.0.1| Z[⚡ Zero-auth default]
    Q -->|Public / team network with editors| O[🔐 Built-in OAuth 2.1<br/>default on 0.0.0.0 without API key]
    Q -->|Scripts / CI with static keys| K[🗝️ --api-key or --keys-file]

    classDef q fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef ok fill:#10B981,stroke:#7C90A0,color:#fff
    classDef cfg fill:#6366F1,stroke:#7C90A0,color:#fff

    class Q q
    class Z,O ok
    class K cfg
```

***

## Best Practices

> [accordion] 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.

> [accordion] 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.

> [accordion] 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

> [card] [praisonai connect](https://praison.ai/docs/features/praisonai-connect.md)
>
> One-command MCP client installation across 22 editors

> [card] [MCP OAuth Authentication (Client)](https://praison.ai/docs/mcp/mcp-oauth.md)
>
> Connect a PraisonAI agent to an external OAuth-protected MCP server

> [card] [praisonai-mcp Package](https://praison.ai/docs/features/praisonai-mcp-package.md)
>
> Full praisonai-mcp installation and host CLI reference

> [card] [Scoped API Keys](https://praison.ai/docs/features/mcp-scoped-api-keys.md)
>
> Static scoped bearer keys for scripts and service accounts


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.