Repository navigation
Rate limit the MCP endpoint per token, by the minute and by the hour - #518
Merged
Merged
Conversation
Each MCP connection (one AI client, for one user, in one workspace) gets its own budget, kept across token refreshes, so the shared egress of ChatGPT and Claude and a busy teammate never spend anyone else's. 240 a minute and 2400 an hour by default, set in config/trypost.php; the REST API keeps its 60 per workspace.
Contributor
|
Thanks a lot for this, David! The MCP endpoint really needed a limit, and the tests made it easy to build on. We pushed a few changes on top of your branch:
Thanks again for the contribution! 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #408.
What changes
mcp, applied to/mcp/trypostafter the token's workspace is loaded (routes/ai.php).config/trypost.php(MCP_REQUESTS_PER_MINUTE,MCP_REQUESTS_PER_HOUR). One agent task chains many tool calls, so the limit sits above the REST API's.mcp-oauthalready exempts).What a client receives
The limiter runs as HTTP middleware, before
laravel/mcpreads the JSON-RPC message. A refused request gets HTTP 429 withRetry-Afterand theX-RateLimit-*headers. Requests refused at sign-in (401) or for the workspace (403) never reach the limiter, so they do not count.Tests
tests/Feature/Mcp/McpRateLimitTest.php(limits lowered in config, so each test sends a handful of requests):Retry-After;tests/Feature/Parity/CrossCuttingParityTest.php: an MCP token may send at least what the REST API allows a workspace per minute.