Skip to content

feat(mcp): Add request interceptor chain and extensible proxy transport#1174

Open
ClayGifford1 wants to merge 1 commit into
smithy-lang:mainfrom
ClayGifford1:mcp-request-interceptor
Open

feat(mcp): Add request interceptor chain and extensible proxy transport#1174
ClayGifford1 wants to merge 1 commit into
smithy-lang:mainfrom
ClayGifford1:mcp-request-interceptor

Conversation

@ClayGifford1
Copy link
Copy Markdown

Summary

Request interceptors:

  • Adds McpRequestInterceptor and McpRequestHandler interfaces to McpService for intercepting JSON-RPC requests
  • Interceptors can be registered via McpService.Builder.addInterceptor() or McpServerBuilder.addInterceptor()
  • Supports observing, augmenting, or short-circuiting requests with no breaking changes and zero overhead when unused

Extensible proxy transport:

  • Makes McpServerProxy.rpc(), start(), and shutdown() protected to allow custom proxy transport implementations outside the package

Motivation

There's currently no way to observe, augment, or short-circuit requests at the McpService level. Consumers using McpService directly can wrap it, but that customization is lost when using McpServer, which creates and owns the McpService instance internally. Placing the interceptor chain on McpService.Builder solves both cases — direct McpService users add interceptors at construction, and McpServerBuilder plumbs them through, so the same interceptors apply regardless of how McpService is used.

The interface mirrors the existing handleRequest contract 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant