Skip to content

Make egress-tracking middleware apply to MCP route #5685

Description

@gefjon

The middleware introduced by #5611 , resolve_database_name_and_count_response_egress_middleware, does not apply to the POST /database/:name_or_identity/mcp route. This is unfortunate, as MCP requests may generate large user-controlled responses, and so we would very much like to measure their response egress bytes. I found it challenging to apply the middleware to the MCP route due to its non-standard handling of its name_or_identity argument. I especially did not want to do this while there are outstanding PRs to update the MCP route; as of my writing this, #5582 has just merged and #5672 is outstanding.

Rewrite the MCP route so that instead of taking a NameOrIdentity as a path parameter, it takes a Database via the ResolvedDatabase extension. This will necessarily move name resolution and 404 responses out of and before the route handler. Move the registration of the MCP route in DatabaseRoute::into_router so that the middleware applies to it.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions