fix(mcp): add request rate limiting for MCP tool calls#1243
Merged
Conversation
Add --max-requests-per-minute flag for MCP mode. Tracks tool/call request timestamps in a sliding 1-minute window. Returns JSON-RPC error -32000 when limit is exceeded. Non-tool methods (tools/list, initialize) are not rate-limited. Closes #1168
a67a67a to
bea18b3
Compare
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.
Summary\n\n- Add
--max-requests-per-minuteCLI flag for MCP subcommand (0 = unlimited, default)\n- Track tool/call timestamps in sliding 1-minute window\n- Return JSON-RPC error -32000 when rate limit exceeded\n- Non-tool methods (tools/list, initialize, shutdown) bypass rate limit\n\n## Test plan\n\n- [x]test_rate_limit_blocks_excess_requests— 3rd request blocked at limit=2\n- [x]test_rate_limit_zero_means_unlimited— 10 rapid requests succeed at limit=0\n- [x]test_rate_limit_does_not_block_non_tool_calls— tools/list works after limit reached\n- [x]cargo clippyandcargo fmtclean\n\nCloses #1168