Skip to content

feat: support custom authorization headers, fix #395 #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 30, 2025

Conversation

Littly
Copy link
Contributor

@Littly Littly commented May 13, 2025

Added custom header support.

Motivation and Context

See #395

How Has This Been Tested?

The header parser implementation has been tested with a server driven by Spring-AI locally.

Breaking Changes

This change will impact services that rely on the "Bearer " prefix for authentication.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Copy link
Contributor

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions and suggestions

@cliffhall cliffhall added enhancement New feature or request waiting on submitter Waiting for the submitter to provide more info labels May 15, 2025
Littly added 2 commits May 20, 2025 10:38
- Avoid calling .lowerCase twice
- Keep 'Bearer ' prefix when header equals 'Authorization'
- Remove unnecessary Array type checks
Copy link
Contributor

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few requests...

- Remove unnecessary auth header name check
- Extract operations on headers into a function
@Littly Littly requested a review from cliffhall May 28, 2025 02:46
@olaservo
Copy link
Member

Sorry to be jumping in a little late in the game, want to cc @pcarleton for extra 👀 .

For anything auth-related I think we want to be careful that we're not introducing any unintentional inconsistencies here with security best practices, etc. that are being shared alongside the official docs + tools. I think for this ^^ PR it would be OK to merge with the caveat that we should follow up with some version of this feature, which would just make headers in general more flexible to add (including custom auth headers).

Copy link
Contributor

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Just one thing...

@Littly Littly requested a review from cliffhall May 29, 2025 03:50
Copy link
Contributor

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Littly Looks good, except it needs a prettier run to pass CI.

Local build and tests are good. Manually tested with a custom auth header against all three transport types.

SSE

Screenshot 2025-05-29 at 11 14 26 AM

StreamableHttp

Screenshot 2025-05-29 at 11 16 22 AM

STDIO

Screenshot 2025-05-29 at 11 16 51 AM

Express converts all header names to lowercase, which prevents custom headers with uppercase characters from being properly passed to the target service. This fix ensures that custom headers preserve their original capitalization when forwarded through the proxy.
Copy link
Contributor

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@cliffhall cliffhall merged commit 1919a0e into modelcontextprotocol:main May 30, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request waiting on submitter Waiting for the submitter to provide more info
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants