MCP usage limits: add server-authoritative meter backend#592
Merged
Conversation
5f8a970 to
8352b5b
Compare
Adds an opt-in "remote" backend to the MCP usage gate. With MCP_USAGE_METER=remote, each gated research run (backtest / Monte Carlo / optimization / significance) checks its remaining daily allowance against the licensing backend, which resolves the plan from the license token, holds the counter, and enforces the limit. This makes the limit authoritative — the local Redis counter is trivially bypassable since the user controls their own Redis. - New _remote_usage_decision(feature): asks the backend for the remaining daily allowance; FAILS OPEN (returns None) on any error, so the limit check never disrupts the feature. - The local Redis meter + api1 plan read remain the default; activate with MCP_USAGE_METER=remote. 6 new tests; all 26 pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8352b5b to
87aa6d4
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.
Adds an opt-in
"remote"backend to the MCP usage gate (jesse/mcp/usage_limits.py).What
With
MCP_USAGE_METER=remote, each gated research run (backtest / Monte Carlo / optimization / significance) checks its remaining daily allowance against the licensing backend instead of the local Redis counter:Fail-open
_remote_usage_decision(feature, action)returnsNoneon any error / non-200 / unreachable backend, and the gate then runs the tool anyway — the limit check never disrupts usage.Default unchanged / activation
Default stays
"local"(the existing Redis counter + api1 plan read), so behavior is unchanged until activated. FlipMCP_USAGE_METER=remotein production.Tests
6 new tests for the remote path (allowed, blocked-free, blocked-guest, fail-open, request/response shape, non-200 fail-open). All 26 pass.