fix(http): fail closed without auth config - #325
Open
Daniyal0100101 wants to merge 1 commit into
Open
Conversation
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.
Describe your changes
Make Streamable HTTP transport fail closed when
FastApiMCPis mounted without anAuthConfig.Previously,
mount_http()registered the MCP route without dependencies whenauth_configwas absent, allowing anonymous clients to initialize sessions and invoke exposed tools. This change installs a default FastAPI dependency that rejects HTTP MCP requests with401 Unauthorizedand aWWW-Authenticate: Bearerheader before the MCP transport handles the request.Configured
AuthConfig.dependenciesremain unchanged. The existing HTTP transport tests now provide an explicit no-op dependency so they continue testing the protocol behavior independently of authentication, and new regression coverage verifies the default route dependency and unauthenticated response.Issue ticket number and link (if applicable)
Fixes #324
#324
Screenshots of the feature / bugfix
Not applicable. This is an HTTP authentication behavior change covered by regression tests.
Checklist before requesting a review
Validation:
uv run ruff check fastapi_mcp/server.py tests/test_http_real_transport.pyuv run ruff format --check fastapi_mcp/server.py tests/test_http_real_transport.pyuv run mypy fastapi_mcp/server.py tests/test_http_real_transport.pyuv run pytest -q— 120 passed, 85.83% coverageuv run pre-commit run --files fastapi_mcp/server.py tests/test_http_real_transport.py