Skip to content

Introduce MCP client oauth flow #478

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 15 commits into from
May 31, 2025
Merged

Introduce MCP client oauth flow #478

merged 15 commits into from
May 31, 2025

Conversation

jlowin
Copy link
Owner

@jlowin jlowin commented May 16, 2025

This is a first cut at adding oauth support to fastmcp clients, with the goal of enabling e.g. fastmcp run https://mcp.paypal.com/sse from the CLI (or Claude Desktop / Cursor / local client of choice) to interact with any remote + authenticated server.

This needs careful review for spec compliance and log verbosity.

Includes support for both SSE and SHTTP client transports. fastmcp run is not part of this PR.

Quick demo script to log in to the Paypal MCP server and list available tools:

from fastmcp import Client
from rich import print

async with Client("https://mcp.paypal.com/sse", auth="oauth") as client:
    tools = await client.list_tools()
    print(tools)

@jlowin jlowin added the feature label May 16, 2025
@jlowin
Copy link
Owner Author

jlowin commented May 16, 2025

MCP # 734 would allow us to avoid the ugly patch

@juan-abia
Copy link

modelcontextprotocol/python-sdk#752 was just merged. It allows customisation to avoid the ugly path

@jlowin jlowin marked this pull request as ready for review May 31, 2025 01:38
@Copilot Copilot AI review requested due to automatic review settings May 31, 2025 01:38
Copy link
Contributor

@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 support for fastmcp clients by implementing and integrating a new OAuth flow into both client and server components. Key changes include new test cases covering OAuth flows, updates to server and HTTP routes to support an OAuthProvider, and modifications to client transports and OAuth client implementations.

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/client/test_oauth.py Added comprehensive tests for OAuth flows including authorization and token exchange.
src/fastmcp/utilities/tests.py Adjusted server startup retry logic by reducing max_attempts and adjusting sleep intervals.
src/fastmcp/settings.py Removed the auth field from ServerSettings in favor of using an OAuthProvider directly.
src/fastmcp/server/server.py, src/fastmcp/server/http.py Updated authentication-related parameters to use a unified OAuthProvider rather than two separate parameters.
src/fastmcp/client/transports.py Modified transport constructors to support an "oauth" authentication option.
src/fastmcp/client/auth.py, src/fastmcp/client/oauth_callback.py Added a new OAuth client implementation and callback server for handling OAuth redirects.
pyproject.toml Updated dependency versions and added authlib for OAuth support.
Comments suppressed due to low confidence (2)

src/fastmcp/utilities/tests.py:97

  • Reducing max_attempts from 100 to 10 may lead to premature failure in environments with high load; please verify that 10 attempts provide sufficient stability during server startup.
max_attempts = 10

src/fastmcp/server/server.py:188

  • The removal of the consistency check between settings.auth and auth_server_provider streamlines configuration; please ensure that the new approach fully covers potential misconfigurations that were previously caught.
self.auth = auth

@jlowin jlowin merged commit f21edd5 into main May 31, 2025
5 checks passed
@jlowin jlowin deleted the oauthclient branch May 31, 2025 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants