Authentication

Token Validation

Per-request bearer verification middleware enforcing SHA-256 hash lookup, RFC 8707 audience matching, grant allowlists, and scope checks.

Per-Request Verification Pipeline

Every HTTP call to POST /mcp, GET /mcp, and DELETE /mcp passes through requireMcpBearerAuth before the MCP transport layer parses JSON-RPC payloads. Authentication state is never cached across separate HTTP requests or assumed from an Mcp-Session-Id header alone.

  1. 1

    Extract Authorization header

    Parses Authorization: Bearer <token>. Query string tokens and cookie-based MCP authentication are explicitly rejected. Missing or malformed headers return HTTP 401 with the RFC 9728 WWW-Authenticate challenge.

  2. 2

    Compute SHA-256 digest and load McpAccessToken

    Hashes the presented token with SHA-256 and queries taicket_mcp.mcp_access_tokens by unique index tokenHash. Works identically for OAuth 2.1 access tokens (tokenKind: "oauth") and /account Personal Access Tokens (tokenKind: "pat").

  3. 3

    Verify active status, expiration, and parent grant

    Confirms revokedAt is null, expiresAt is strictly greater than Date.now(), and the referenced McpOAuthGrant (if present) has not been revoked.

  4. 4

    Validate RFC 8707 resource binding

    Confirms tokenRecord.resource equals https://mcp.taicket.xyz/mcp. Tokens minted for any other resource identifier are rejected.

  5. 5

    Derive immutable caller context

    Sets ctx.userId = tokenRecord.userId, ctx.scopes = tokenRecord.scopes, ctx.allowedGuildIds = tokenRecord.allowedGuildIds, and ctx.authKind = tokenRecord.tokenKind. No tool accepts caller identity from request arguments.

  6. 6

    Enforce BotBlacklist and trusted-proxy IP telemetry

    Rejects globally banned users in BotBlacklist with FORBIDDEN and records hashed client IP telemetry using trusted-proxy rules (CF-Connecting-IP is honored only when socket remoteAddress is loopback behind local Nginx).

Authenticated Request Format

Valid MCP JSON-RPC request with Bearer tokenhttp
POST /mcp HTTP/1.1
Host: mcp.taicket.xyz
Authorization: Bearer tmcp_oa_6a8f4d91e2c04b7790c1a4e5f8d2b3c4
Content-Type: application/json
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2025-06-18

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_user",
    "arguments": {}
  }
}

HTTP Status Mapping for Auth Failures

Failure ConditionHTTP StatusError Code / Header
Missing, malformed, unknown, expired, or revoked Bearer token401 UnauthorizedWWW-Authenticate: Bearer resource_metadata="https://mcp.taicket.xyz/.well-known/oauth-protected-resource", error="invalid_token"
Token valid but lacks required tool scope (e.g. mcp:write or mcp:destructive)403 ForbiddenWWW-Authenticate: Bearer error="insufficient_scope", scope="<required>"
Authenticated user or target guild is listed in BotBlacklist403 ForbiddenTool error code: FORBIDDEN
Target guildId is not included in token allowedGuildIds403 ForbiddenTool error code: FORBIDDEN
Per-user sliding-window quota exceeded429 Too Many RequestsTool error code: RATE_LIMITED + Retry-After header

Related documentation