Repository navigation
Conversation
transformRouteSchema already lets users hide the MCP transport routes from @fastify/swagger with `hide: true` or a hidden tag, but several routes the plugin registers bypassed it and still leaked into the generated OpenAPI document (and into types generated from it): - GET /mcp when enableSSE is off (the 405 route) - /.well-known/oauth-protected-resource*, /.well-known/mcp-resource-health and the OPTIONS /.well-known/* preflight route when authorization is on - the /oauth/* client routes and the Client ID Metadata Document route when oauth2Client is configured All of them now go through the transformer with their own route IDs. The helpers moved from routes/mcp.ts to routes/route-schema.ts so the well-known, OAuth route and OAuth client plugins can share them. @fastify/swagger is added as a devDependency to test the generated spec. Fixes #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM
This branch has not been deployed
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.
Problem
Issue #72 asks for a way to keep the MCP routes out of an OpenAPI document generated with
@fastify/swagger, since they end up in types generated withopenapi-fetch. ThetransformRouteSchemaoption (#183) covers most of this: returning{ ...schema, hide: true }, or a tag matching swagger'shiddenTag, hidesPOST/DELETE /mcp. I tested it againstapp.swagger()and found that some routes the plugin registers skip the transformer, so they still appear in the spec:GET /mcpwhenenableSSEis off (the route that returns 405). With default options,/mcpwas always in the spec./.well-known/oauth-protected-resource*,/.well-known/mcp-resource-healthand theOPTIONS /.well-known/*preflight route.oauth2Clientis configured: the/oauth/*routes and the Client ID Metadata Document route.Fix
transformRouteSchema. New route IDs:wellKnown.protectedResourceMetadata,wellKnown.resourceHealth,wellKnown.preflight,oauth.authorize|callback|refresh|validate|status|register|logout,oauth.clientIdMetadataDocument. The 405GET /mcproute uses the existingmcp.getID.querystring/body/responseschemas to the transformer. The README tells users to spread them.src/routes/mcp.tstosrc/routes/route-schema.ts, so the other plugins can use them too.hide: true, or theX-HIDDENtag), extended the route ID table, and removed the note that OAuth/well-known routes are not customized.@fastify/swaggeris added as a devDependency.test/openapi-hide-routes.test.tschecks thatapp.swagger()lists no plugin paths with SSE on and off, with authorization, and withoauth2Client.Behaviour change
A transformer now runs for more routes than before: 3 calls instead of 2 with default options, and more when authorization is enabled. If a transformer assumed it only sees
mcp.*IDs, it now also receiveswellKnown.*andoauth.*IDs.Fixes #72
🤖 Generated with Claude Code
https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM