-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PR: Middleware Support for McpServer (Fixes #1238) #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Middleware Support for McpServer (Fixes #1238) #1344
Conversation
…ial request processing
…, and error handling
…authentication, and activity aggregation
…d tool handler error propagation
… once and adding a verification test
… middleware timing
|
commit: |
PR: Middleware Support for McpServer (Fixes #1238)
🚀 Summary
This PR implements a request-lifecycle middleware system for
McpServer,enabling cross-cutting concerns (logging, authentication, error handling) to be
applied consistently across all Tools, Resources, and Prompts.
It introduces a strictly ordered "Onion Model" execution pipeline ensuring:
registered.
anyusage.double-invocation guards.
🛠️ Key Changes
private _executeRequestpipeline toMcpServer.public use(middleware: McpMiddleware)method.setToolRequestHandlers,setResourceRequestHandlers,and
setPromptRequestHandlersto utilize the pipeline.🧪 Verification
packages/server/test/server/mcpServer.test.tscovering:
packages/server/examples/manual_verification.ts.pnpm test(348 passing) andpnpm typecheckpassed.📝 Example Usage