feat(mcp): add optional bearer-token auth#1384
Open
Conversation
PR Build Metrics✅ All clear — no issues detected
Binary Size
Dependency ChangesNo dependency changes. govulncheck OutputBuild Info
History (3 previous)
🤖 Updated on each push. |
corylanou
marked this pull request as ready for review
July 17, 2026 19:47
Reject configured tokens that expand to empty while preserving open behavior when auth is omitted. Accept valid multi-space Bearer headers and track the required user-facing security guidance. Refs #1374
Integrate the protocol-hardening base commit and preserve stateless MCP transport behavior beneath bearer authentication.
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.
Description
Adds optional bearer-token authentication to the MCP Streamable HTTP transport on top of #1378.
mcp-auth-tokenconfiguration setting, including existing YAML environment expansion support.401 UnauthorizedandWWW-Authenticate: Bearerfor missing or incorrect credentials when configured.Example configuration:
Motivation and Context
Before this change,
NewMCPregistered the official SDK HTTP handler directly on the server mux, andConfighad no MCP authentication setting. Anyone able to reachmcp-addrcould access tools including the mutating restore and reset operations.200 OK401 UnauthorizedThe token is a defense-in-depth option. SSH tunneling, an authenticated TLS reverse proxy, VPN, or private networking remain the primary controls for the MCP endpoint. Bearer tokens should not be sent over an untrusted plaintext connection.
Scope
In scope:
Not in scope:
How Has This Been Tested?
Types of changes
Checklist
go fmt,go vet)go test ./...)Related