-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Feature Request: Middleware support for McpServer #1238
Copy link
Copy link
Open
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implementIssue is actionable, needs maintainer decision on whether to implement
Metadata
Metadata
Assignees
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implementIssue is actionable, needs maintainer decision on whether to implement
Type
Fields
Give feedbackNo fields configured for issues without a type.
Is your feature request related to a problem? Please describe.
I've been
working on a secure MCP server (a "Zero Trust" database bridge) and found myself
needing to apply the same logic across multiple tools—such as logging every
request, checking permissions, or validating schemas.
Currently, I have to manually wrap every single tool handler function to add
this logic. This leads to repetitive code and makes it easy to accidentally miss
a tool. For example, if I want to log every tool call, I have to copy-paste the
logging code into every
server.tool(...)definition.Describe the solution you'd like
would love to see a
server.use()methodadded to
McpServer, similar to how Express or Koa handle middleware. Thiswould allow developers to define logic once and have it automatically run for
every tool or resource request.
Ideally, it could look something like this:
This would make the code much cleaner and ensure that important checks (like
auth) are never skipped.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
I am new to contributing to this project, but I would be
very happy to try implementing this feature if the team thinks it's a good idea!
I'm open to any guidance on how best to fit this into the existing architecture.