fix(mcp): replace SeerrAPIKeyMiddleware with MCPAuthMiddleware#92
Merged
electather merged 1 commit intomainfrom Mar 16, 2026
Merged
fix(mcp): replace SeerrAPIKeyMiddleware with MCPAuthMiddleware#92electather merged 1 commit intomainfrom
electather merged 1 commit intomainfrom
Conversation
X-Api-Key on the MCP endpoint is for client authentication (checked against --auth-token), not for forwarding the Seerr API key. The Seerr API key is always read from the application config (seerr.api_key). Remove SeerrAPIKeyMiddleware, which incorrectly extracted X-Api-Key from incoming requests and injected it as the Seerr API key. Replace the bearer-only auth middleware with MCPAuthMiddleware, which accepts the configured auth token via Authorization: Bearer, X-Api-Key header, or ?api_key= query parameter (when --allow-api-key-query-param is set). Clients configured with no auth token no longer receive spurious 401s.
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.
Summary
Fixes a bug where MCP HTTP clients with no auth config received a 401 even when the server was started without
--auth-token.SeerrAPIKeyMiddlewarewas incorrectly treating theX-Api-Keyrequest header as the Seerr API key and rejecting requests that didn't supply one. In reality,X-Api-Keyon the MCP endpoint is for client authentication (an alternative toAuthorization: Bearer), checked against--auth-token. The Seerr API key is always read from the application config (seerr.api_key) and never sourced from the incoming request.Changes
SeerrAPIKeyMiddlewareentirelybearerAuthMiddlewarewithMCPAuthMiddleware(token, allowQueryParam, next)that accepts the configured auth token via:Authorization: Bearer <token>X-Api-Key: <token>?api_key=<token>(when--allow-api-key-query-paramis set)--allow-api-key-query-paramflag description: it passes the MCP auth token, not the Seerr API keymcp_api_key_middleware_test.gowith tests covering all three credential methods, wrong tokens, disabled query params, and the no-auth pass-through scenarioTest plan
go test -v ./...passesgo fmt ./...produces no diffgo buildsucceeds--no-authand connect a client with no credentials — expect 200, not 401--auth-token secretand sendX-Api-Key: secret— expect 200--auth-token secretand send wrong key — expect 401Checklist
--help, comments)