feat(mcp): Add request interceptor chain and extensible proxy transport#1174
Open
ClayGifford1 wants to merge 1 commit into
Open
feat(mcp): Add request interceptor chain and extensible proxy transport#1174ClayGifford1 wants to merge 1 commit into
ClayGifford1 wants to merge 1 commit into
Conversation
Add McpRequestInterceptor and McpRequestHandler interfaces that allow consumers to observe, modify, or short-circuit MCP JSON-RPC request handling. The interceptor chain is built into McpService and is accessible via both McpService.Builder and McpServerBuilder. Also makes McpServerProxy's rpc(), start(), and shutdown() methods protected to allow custom proxy transport implementations.
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
Request interceptors:
McpRequestInterceptorandMcpRequestHandlerinterfaces toMcpServicefor intercepting JSON-RPC requestsMcpService.Builder.addInterceptor()orMcpServerBuilder.addInterceptor()Extensible proxy transport:
McpServerProxy.rpc(),start(), andshutdown()protected to allow custom proxy transport implementations outside the packageMotivation
There's currently no way to observe, augment, or short-circuit requests at the
McpServicelevel. Consumers usingMcpServicedirectly can wrap it, but that customization is lost when usingMcpServer, which creates and owns theMcpServiceinstance internally. Placing the interceptor chain onMcpService.Buildersolves both cases — directMcpServiceusers add interceptors at construction, andMcpServerBuilderplumbs them through, so the same interceptors apply regardless of howMcpServiceis used.The interface mirrors the existing
handleRequestcontract directly, including the async callback for proxy tool calls, so it works with any transport.Separately, custom MCP proxy transports beyond the provided stdio and HTTP implementations are not possible today because
McpServerProxy's abstract methods are package-private. Making them protected allows consumers to implement their own proxy transports.