MCP gateway: add per-tool scopes, tracing, rate limiting, and audit logging#2850
Merged
MCP gateway: add per-tool scopes, tracing, rate limiting, and audit logging#2850
Conversation
- Add Scopes field to Tool struct for per-tool scope requirements
- Add Auth (auth.Auth) integration to Options for token inspection
- Add trace ID generation (UUID) propagated via metadata to downstream RPCs
- Add per-tool rate limiting with configurable requests/sec and burst
- Add AuditFunc callback for immutable tool-call audit records
- Extract tool scopes from registry endpoint metadata ("scopes" key)
- Update both HTTP and stdio transports with auth/trace/rate/audit
- Add comprehensive tests for all new functionality
Co-authored-by: asim <17530+asim@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add fine-grained scoping and tracing for MCP tools
Add per-tool scopes, tracing, rate limiting, and audit logging to MCP gateway
Feb 11, 2026
…ation - Add server.WithEndpointScopes() for declaring per-endpoint auth scopes at handler registration time - Add mcp.Options.ToolScopes for gateway-level scope overrides without changing individual services - Update documented example to show WithEndpointScopes usage - Update examples/mcp/README.md with scopes, tracing, and rate-limiting docs - Update gateway/mcp/DOCUMENTATION.md with scopes section and FAQ - Add tests for both new features Co-authored-by: asim <17530+asim@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
Copilot
AI
changed the title
Add per-tool scopes, tracing, rate limiting, and audit logging to MCP gateway
Add WithEndpointScopes helper and gateway-level ToolScopes for MCP
Feb 11, 2026
The field name "Scopes" is more universal and consistent with how auth scopes are used throughout go-micro. Updated all code references, tests, and documentation. Co-authored-by: asim <17530+asim@users.noreply.github.com>
…ogging Co-authored-by: asim <17530+asim@users.noreply.github.com>
Copilot
AI
changed the title
Add WithEndpointScopes helper and gateway-level ToolScopes for MCP
MCP gateway: add per-tool scopes, tracing, rate limiting, and audit logging
Feb 11, 2026
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 fine-grained auth scopes, request tracing, rate limiting, and audit logging to the MCP gateway — motivated by user feedback on least-privilege authz and traceability for agent-initiated tool calls.
Server-side: scope declaration at handler registration
New
server.WithEndpointScopes()helper, consistent with existingWithEndpointDescription()/WithEndpointExample():Gateway-side: auth, scopes, rate limiting, tracing, audit
Options.Auth—auth.Authprovider for token inspection; enforces per-tool scopes from endpoint metadataOptions.Scopes— gateway-level scope overrides per tool name, without changing servicesOptions.RateLimit— per-tool token-bucket rate limitingOptions.AuditFunc— callback with immutableAuditRecordfor every tool call (allowed or denied)Mcp-Trace-Id/Mcp-Tool-Name/Mcp-Account-Idmetadata to downstream RPCsScope resolution order
server.WithEndpointScopes()→ stored as"scopes"in endpoint metadataOptions.Scopesoverrides if present for that tool nameChanges
server/doc.go—WithEndpointScopes()helpergateway/mcp/mcp.go—Auth,Scopes,RateLimit,AuditFunconOptions; scope/auth/rate-limit/trace enforcement inhandleCallToolanddiscoverServices;AuditRecordtypegateway/mcp/ratelimit.go— token-bucket rate limitergateway/mcp/stdio.go— same auth/scope/rate/trace/audit flow for stdio transportgateway/mcp/mcp_test.go— tests for scopes, auth, rate limiting, audit, trace IDs, gateway-level scope overridesserver/comments_test.go— test forWithEndpointScopesDOCUMENTATION.md,examples/mcp/README.md,examples/mcp/documented/main.goupdatedWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
224.0.0.251REDACTED, pid is -1(packet block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.