Skip to content

Rate-limit MCP calls per person instead of per network address #551

Closed

Description

@HMarzban

Summary

Every REST request, /api/mcp included, counts against one global limit per network address. A hosted AI app, such as claude.ai, ChatGPT or Replit, calls docs.plus from its own servers. So all of that app's users may share one address bucket, and one busy group could block everyone on that app. The MCP connector already has a fair per-person budget. This issue decides whether /api/mcp should rely on that budget instead of the per-address limit.

Parent: #230.

Facts (read from code on 2026-10-20, not measured)

  • Global limiter (apps/hocuspocus.server/src/middleware/index.ts): RATE_LIMIT_MAX points per 15 minutes, keyed by x-real-ip (or the first x-forwarded-for hop). A code comment says production runs RATE_LIMIT_MAX=500. Only /health and media reads have their own rule. /api/mcp takes the global one.
  • MCP tool budget (apps/hocuspocus.server/src/modules/mcp/infra/toolBudget.ts): 60 tool calls per minute per signed-in person (sub), in Redis. If Redis is down, it allows the call.
  • Not measured: how many addresses each hosted AI app uses, and whether any app has hit the global limit. The admin /mcp usage page and the RATE_LIMIT_EXCEEDED logs would show it.

Open decisions

  1. Take /api/mcp off the per-address limit once the bearer token verifies? Recommended: yes. Keep the per-person tool budget, and keep a high per-address ceiling for requests without a valid token. Reason: the person, not the shared address of the AI app, is the fair unit.
  2. Decide before more hosted apps are listed? Recommended: yes. Reason: Replit and the official MCP Registry listing (Publish docs.plus to the official MCP Registry #459) bring more hosted traffic through the same few addresses.
  3. Measure first? Recommended: check the RATE_LIMIT_EXCEEDED log lines on /api/mcp for the last 30 days before building. Reason: a ruling on numbers beats a ruling on argument.

Where

  • apps/hocuspocus.server/src/middleware/index.ts: the global limiter and its path rules.
  • apps/hocuspocus.server/src/modules/mcp/http/controller.ts: where the token is verified.

Acceptance criteria

  • The measurement in decision 3 is posted here.
  • The ruling is posted here.
  • If built: a verified /api/mcp request never spends the per-address budget, an unverified one still does, and the per-person budget is unchanged.

Activity

  1. added this to the v2.2.0 milestone on Oct 20, 2026
  2. added
    enhancement
    Performance
    on Oct 20, 2026
  3. HMarzban commented on Oct 20, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-10-20

    Build decisions 1 and 2 as recommended: a verified /api/mcp request does not spend the per-address budget, an unverified one still does, and the per-person tool budget stays. Decision 3 (measure first) is skipped for now: the build goes ahead without the 30-day log count.

  4. HMarzban commented on Oct 20, 2026

    @HMarzban
    CollaboratorAuthor

    Rulings (maintainer, 2026-10-20), shipped in 2c3596eea and 7f550750f:

    1. Budget before verify stays. A verified /api/mcp call skips the per-address limit only while the address still has budget. A spent address gets 429 even for a good token, and it never reaches Supabase Auth. That stops forged tokens from driving Auth calls.
    2. Calls that are not tool calls are no longer uncapped. Every request with an accepted token now spends a per-person bucket (mcp-req, 300 a minute). Over it, the transport answers 429 with Retry-After. Tool calls still spend the separate 60-a-minute tool budget. 300 is not measured against host traffic yet. Watch for mcp-req 429s from Claude and ChatGPT, and raise it if a normal session hits it.

    Docs: apps/hocuspocus.server/API.md §Rate limiting, docs/mcp/reference.md §Limits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Performanceenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions