Skip to content

feat: expose authProvider for HTTP MCP servers to enable OAuth token refresh#6370

Merged
abhiaiyer91 merged 6 commits into
mastra-ai:mainfrom
PhoebeMay:mcp/expose-auth-provider
Aug 5, 2025
Merged

feat: expose authProvider for HTTP MCP servers to enable OAuth token refresh#6370
abhiaiyer91 merged 6 commits into
mastra-ai:mainfrom
PhoebeMay:mcp/expose-auth-provider

Conversation

@PhoebeMay
Copy link
Copy Markdown
Contributor

@PhoebeMay PhoebeMay commented Jul 29, 2025

Summary

Exposes authProvider option for HTTP-based MCP servers to enable OAuth authentication with automatic token refresh.

Changes

  • Add authProvider field to HttpServerDefinition type (excluded from stdio servers)
  • Pass authProvider to both Streamable HTTP and SSE transports in connectHttp method
  • Add comprehensive tests covering authProvider configuration and backward compatibility
  • Update README with OAuth authentication documentation and usage examples
  • Add changelog entry

Test plan

  • New tests verify authProvider can be configured for HTTP servers
  • Tests confirm authProvider is excluded from stdio server definitions
  • Backward compatibility confirmed - servers work without authProvider
  • Both HTTP transport types (Streamable HTTP and SSE fallback) receive authProvider

PhoebeMay and others added 3 commits July 28, 2025 20:39
Add tests to verify that authProvider functionality works correctly:
- Accept authProvider field in HTTP server configuration
- Handle undefined authProvider gracefully
- Maintain backward compatibility for clients without authProvider

These tests validate the authProvider exposure added for token refresh capability.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive documentation for the new authProvider option:
- OAuth authentication section with usage examples
- Configuration reference for authProvider field
- Feature list updates to highlight OAuth support
- CHANGELOG entry for the new functionality

This documents the authProvider functionality that enables automatic
token refresh for HTTP-based MCP servers.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented Jul 29, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jul 29, 2025

🦋 Changeset detected

Latest commit: df860c9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@mastra/mcp Patch
mastra Patch
@mastra/mcp-docs-server Patch
@mastra/dane Patch
create-mastra Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 29, 2025

@PhoebeMay is attempting to deploy a commit to the Mastra Team on Vercel.

A member of the Team first needs to authorize it.

@PhoebeMay PhoebeMay changed the title title feat: expose authProvider for HTTP MCP servers to enable OAuth token refresh Jul 29, 2025
@PhoebeMay PhoebeMay marked this pull request as ready for review July 29, 2025 10:52
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR exposes OAuth authentication support for HTTP-based MCP (Model Context Protocol) servers by adding an authProvider field to the client configuration. The implementation adds type-safe OAuth support that's restricted to HTTP servers only (excluding stdio servers), as OAuth authentication is only relevant for HTTP-based connections.

The key changes include:

  • Type System Updates: Added authProvider?: StreamableHTTPClientTransportOptions['authProvider'] to HttpServerDefinition while explicitly excluding it from StdioServerDefinition with authProvider?: never
  • Transport Integration: Modified the connectHttp method to extract and pass the authProvider to both StreamableHTTPClientTransport and SSEClientTransport constructors
  • Comprehensive Testing: Added test coverage for authProvider configuration, backward compatibility, and proper exclusion from stdio servers
  • Documentation: Updated README with OAuth authentication examples and usage patterns

This change enables automatic token refresh for long-running MCP client connections to HTTP servers that require OAuth authentication, addressing a critical need for production applications that need to maintain authenticated connections over extended periods.

Confidence score: 5/5

  • This PR is very safe to merge with minimal risk of production issues
  • The implementation follows established patterns, maintains backward compatibility, and includes comprehensive tests
  • All files look well-implemented with proper type safety and no apparent issues

3 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

Copy link
Copy Markdown
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

LGTM, but @DanielSLew, does this look correct for you?

Comment thread .changeset/fast-steaks-shine.md Outdated
@wardpeet wardpeet requested a review from DanielSLew July 29, 2025 13:06
@abhiaiyer91 abhiaiyer91 merged commit 9e792ef into mastra-ai:main Aug 5, 2025
20 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants