Skip to content

feat: add configurable rate limit for client registration - #630

Merged
zereight merged 2 commits into
zereight:mainfrom
raskad:register-rate-limit-configurable
Jul 29, 2026
Merged

feat: add configurable rate limit for client registration#630
zereight merged 2 commits into
zereight:mainfrom
raskad:register-rate-limit-configurable

Conversation

@raskad

@raskad raskad commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

In certain scenarios, like using multiple windows of Kiro IDE, clients will multiple registrations at once (e.g. n windows of Kiro IDE open => n client registrations).
Currently the mcp uses the default upstream rate limit of 20 requests per hour for the POST /register endpoint. This PR adds the capability to adjust this rate limit to account for client specific technical details like the one mentioned above.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f3b4189d-ce62-44a4-af6b-278e3a0e10d7

📥 Commits

Reviewing files that changed from the base of the PR and between 6dda61b and 1fbc19d.

📒 Files selected for processing (1)
  • index.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (5)
  • GitHub Check: schema-tests
  • GitHub Check: code-quality
  • GitHub Check: docs-build
  • GitHub Check: integration-test
  • GitHub Check: test
🔇 Additional comments (3)
index.ts (3)

1071-1073: LGTM!


13814-13814: LGTM!


13794-13798: 🎯 Functional Correctness

No change needed for OAUTH_REGISTER_RATE_LIMIT_PER_HOUR.

In the current startup flow, validateConfiguration() rejects values above 1000 before startStreamableHTTPServer() can use this parser, and the parser defaults invalid values to 20 rather than leaking them.

			> Likely an incorrect or invalid review comment.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a new configuration option to control per-IP rate limiting for OAuth client registration.
    • Uses a rolling one-hour window with a default of 20 registrations, adjustable from 1 to 1,000.
  • Bug Fixes

    • Improved startup validation by detecting and reporting invalid OAUTH_REGISTER_RATE_LIMIT_PER_HOUR values (must be an integer within the allowed range).

Walkthrough

The change documents and validates OAUTH_REGISTER_RATE_LIMIT_PER_HOUR, then applies its value as a dedicated hourly per-IP limiter for OAuth client registration in Streamable HTTP mode.

Changes

OAuth registration limiting

Layer / File(s) Summary
Registration limit configuration
docs/configuration/environment-variables.md, index.ts
Documents the environment variable and validates configured values as integers between 1 and 1000.
Hourly OAuth registration limiter
index.ts
Uses the configured value, defaulting to 20, to create a one-hour client registration limiter and passes it to the OAuth router.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: zereight, sidi7, shiroksh

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding a configurable rate limit for client registration.
Description check ✅ Passed The description is directly related and accurately explains the registration rate-limit change and its motivation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai
coderabbitai Bot requested a review from zereight July 28, 2026 14:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
index.ts (1)

13798-13813: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Document the registration limiter as process-local or use shared storage.

The registration limiter passes no shared store, so express-rate-limit falls back to process-local MemoryStore counters. In a multi-instance deployment, registration requests can pass this limit across processes; either configure shared storage or update docs/configuration/environment-variables.md#L580 to make the documented limit clearly per process/instance.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@index.ts` around lines 13798 - 13813, Update the registration rate-limit
configuration in index.ts around clientRegistrationRateLimitOptions to use
shared storage, or explicitly document its process-local/instance-scoped
behavior. If retaining the default MemoryStore, update
docs/configuration/environment-variables.md lines 580-583 to state that
OAUTH_REGISTER_RATE_LIMIT_PER_HOUR applies independently per process/instance;
if shared storage is configured instead, document that setup accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@index.ts`:
- Around line 1068-1073: Update validation of OAUTH_REGISTER_RATE_LIMIT_PER_HOUR
to reject malformed and non-integer strings before applying the 1–1000 range
check; replace the permissive parseInt-based validation with strict numeric
validation so values like “20foo” and “1.5” fail. Apply the same strict parsing
at the runtime rate-limit parsing site, preserving valid integer behavior.

---

Outside diff comments:
In `@index.ts`:
- Around line 13798-13813: Update the registration rate-limit configuration in
index.ts around clientRegistrationRateLimitOptions to use shared storage, or
explicitly document its process-local/instance-scoped behavior. If retaining the
default MemoryStore, update docs/configuration/environment-variables.md lines
580-583 to state that OAUTH_REGISTER_RATE_LIMIT_PER_HOUR applies independently
per process/instance; if shared storage is configured instead, document that
setup accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a22c07d6-8864-4949-9039-09b8a0d8c01c

📥 Commits

Reviewing files that changed from the base of the PR and between 04e90d3 and 6dda61b.

📒 Files selected for processing (2)
  • docs/configuration/environment-variables.md
  • index.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: test
  • GitHub Check: integration-test
  • GitHub Check: docs-build

Comment thread index.ts Outdated
@zereight
zereight merged commit 667b196 into zereight:main Jul 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants