Repository navigation
Conversation
mount_http()/mount_sse() ignored the prefix a router was included with via app.include_router(router, prefix=...), mounting MCP endpoints at the app root instead (tadata-org#204). Resolve the include prefix from FastAPI's own include-time bookkeeping (>= 0.137 _IncludedRouter metadata) with a path-diffing fallback for older FastAPI; ambiguous or unresolvable prefixes fall back to the safe empty prefix instead of guessing. Adopted from tadata-org#329 (original patch by @wakqasahmed).
Author
|
Closing for housekeeping - the repo had no reviewer engagement and we are re-approaching these areas through a narrower pipeline. Happy to reopen on request. |
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.
Adopted from #329 (original patch by @wakqasahmed) — rebased onto current main and verified. Fixes #204.
Why this is needed
The documented FastAPI pattern — define routes on a sub-router, then app.include_router(router, prefix=/api) — is broken for MCP mounting: mount_http()/mount_sse() registered the MCP endpoints under the app root because the include-time prefix was never recovered. Issue #204's exact repro (a pure mount-point router with zero routes of its own) is the worst case: there is nothing to diff paths against.
The fix resolves the include prefix in two tiers:
Ambiguity (router included at multiple prefixes, shared endpoints on old FastAPI) falls back to the safe empty prefix rather than guessing wrong.
Verification
Credit to @wakqasahmed for the original report and patch in #329.