Skip to content

feat!(mcp-adapters): add authProvider for oauth, fix header passing #8239

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 4 commits into from
May 28, 2025

Conversation

benjamincburns
Copy link
Collaborator

@benjamincburns benjamincburns commented May 23, 2025

BREAKING_CHANGE: Drops the useNodeEventSource flag and stops passing an empty eventSourceInit object to Streamable HTTP and SSE transport constructors. If there continues to be header passing issues as a result of the way SSEClientTransport and StreamableHTTPClientTransport handle EventSource initialization, the correct fix will be to PR a change to the MCP SDK that changes how headers are populated on EventSource initialization.

Also includes integration tests that validate the new behavior against actual MCP servers, and fixes to further problems surfaced by these tests related to passing headers when authProvider is present.

fixes #8196
fixes #8194

BREAKING_CHANGE: Drops the `useNodeEventSource` flag and stops passing
an empty eventSourceInit object to Streamable HTTP and SSE transport
constructors. If there continues to be header passing issues as a result
of the way `SSEClientTransport` and `StreamableHTTPClientTransport`
handle EventSource initialization, the correct fix will be to PR a
change to the MCP SDK that changes how headers are populated on
EventSource initialization.

fixes #8196
fixes #8194
Copy link

vercel bot commented May 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2025 0:00am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) May 28, 2025 0:00am

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 23, 2025
@benjamincburns benjamincburns requested a review from Copilot May 23, 2025 06:40
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces OAuth 2.0 support by replacing the useNodeEventSource flag with an authProvider option and updates header passing and error messaging for both Streamable HTTP and SSE transports. Key changes include:

  • Removing the useNodeEventSource flag and replacing it with authProvider in the transport schemas and client functions.
  • Updating error messages to specifically handle authentication failures.
  • Enhancing documentation and test coverage to demonstrate OAuth integration and header management.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
libs/langchain-mcp-adapters/vitest.setup.ts Removed the file that mocks node:crypto, suggesting tests now use real implementations or other mocks.
libs/langchain-mcp-adapters/vitest.config.ts Updated configuration formatting (double-quoted strings) without functional changes.
libs/langchain-mcp-adapters/src/client.ts Refactored transport creation to support OAuth via authProvider, updated error messaging, and adjusted reconnection options.
libs/langchain-mcp-adapters/tests/fixtures/dummy-stdio-server.ts Added a dummy stdio server for integration testing.
libs/langchain-mcp-adapters/tests/fixtures/dummy-http-server.ts Enhanced the dummy HTTP server to support header and authentication testing.
libs/langchain-mcp-adapters/tests/client.comprehensive.test.ts Modified tests to expect updated transport configuration with authProvider support.
libs/langchain-mcp-adapters/README.md Updated guides to reflect the new OAuth authentication option and removed outdated sections.
libs/langchain-mcp-adapters/.eslintrc.cjs Minor ESLint config improvements using path.join for tsconfig paths.
Comments suppressed due to low confidence (2)

libs/langchain-mcp-adapters/vitest.setup.ts:1

  • Confirm that the removal of vitest.setup.ts is intentional and that any necessary mocking of node:crypto is now handled elsewhere.
Entire file removal

libs/langchain-mcp-adapters/src/client.ts:1057

  • The _createNodeEventSourceTransport function now returns a StreamableHTTPClientTransport instance instead of an SSEClientTransport, which may not be intended. Consider returning an SSEClientTransport to meet the expected type for SSE connections.
return Object.keys(options).length > 0 ? new StreamableHTTPClientTransport(new URL(url), options) : new StreamableHTTPClientTransport(new URL(url));

Copy link
Collaborator

@nfcampos nfcampos left a comment

Choose a reason for hiding this comment

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

Thanks!

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label May 26, 2025
@benjamincburns benjamincburns merged commit 16a3a2f into main May 28, 2025
24 checks passed
@benjamincburns benjamincburns deleted the ben/mcp-error-headers branch May 28, 2025 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm PRs that are ready to be merged as-is size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
3 participants