feat(mcp): declarative per-server tool policy layer with rate limiting#1191
Merged
feat(mcp): declarative per-server tool policy layer with rate limiting#1191
Conversation
c644c55 to
93f8abb
Compare
Adds McpPolicy (allowlist, denylist, rate limit) and PolicyEnforcer backed by DashMap per-server mutexes. Enforcer runs before each call_tool() in McpManager. Policy configured via [mcp.servers.policy] TOML sub-table; servers with no policy allow all tools (backward compatible). Rate limiting uses a sliding 60s window.
93f8abb to
2b2b4d8
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
Implements task 5.1 from the infrastructure hardening roadmap (epic #1159).
Adds a declarative policy enforcement layer for MCP multi-server setups. Previously any connected server could invoke any tool without restriction.
McpPolicystruct: per-server allowed/denied tool lists and rate limitsPolicyEnforcerintercepts everycall_tool()invocation before executionDashMap<String, VecDeque<Instant>>for lock-free rate limiting (no global contention)tracing::warn!with structured fields (server,tool,action,reason)[policy]sub-table inside each[[mcp.servers]]TOML sectionallowed_toolsmeans allow all; non-empty is an allowlistunwrap_or(now)guard on rate limit window calculation (no panic within 60s of boot)Test plan
cargo nextest run --config-file .github/nextest.toml --workspace --lib --bins— all tests passcargo +nightly fmt --checkpassescargo clippy --workspace -- -D warningspassesCloses #1175