-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add Discord OAuth provider and corresponding tests #2428
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis change introduces a complete Discord OAuth provider implementation for FastMCP. It adds three new classes to Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/fastmcp/server/auth/providers/discord.py (1)
67-183: Tighten exception handling in DiscordTokenVerifier to avoid masking bugsThe overall verification flow (calling
/api/oauth2/@me, enforcing scopes, optional/users/@me, and buildingAccessToken) looks good, but the broadexcept Exceptionblocks can hide real programming errors and are flagged by Ruff (BLE001).You can keep behavior (treat network/JSON issues as invalid token) while narrowing the catches to expected failures:
@@ - user_data = {} - if "identify" in token_scopes: - try: - userinfo_response = await client.get( - "https://discord.com/api/users/@me", - headers=headers, - ) - if userinfo_response.status_code == 200: - user_data = userinfo_response.json() - except Exception as e: - logger.debug("Failed to fetch Discord user info: %s", e) + user_data = {} + if "identify" in token_scopes: + try: + userinfo_response = await client.get( + "https://discord.com/api/users/@me", + headers=headers, + ) + if userinfo_response.status_code == 200: + user_data = userinfo_response.json() + except httpx.RequestError as e: + logger.debug("Failed to fetch Discord user info: %s", e) + except ValueError as e: + logger.debug("Failed to decode Discord user info JSON: %s", e) @@ - except httpx.RequestError as e: - logger.debug("Failed to verify Discord token: %s", e) - return None - except Exception as e: - logger.debug("Discord token verification error: %s", e) - return None + except httpx.RequestError as e: + logger.debug("Failed to verify Discord token: %s", e) + return None + except ValueError as e: + logger.debug("Failed to decode Discord tokeninfo JSON: %s", e) + return NoneOptionally, you might also treat 5xx responses from Discord differently from 4xx (e.g., log as upstream failure vs. invalid token), but that’s secondary to fixing the broad catches. Based on static analysis hints.
Please verify the exact exception types httpx can raise in your version and adjust the narrowed
exceptclauses accordingly.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
README.mdis excluded by none and included by nonetests/server/auth/providers/test_discord.pyis excluded by none and included by none
📒 Files selected for processing (1)
src/fastmcp/server/auth/providers/discord.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/fastmcp/server/auth/providers/discord.py (2)
src/fastmcp/server/auth/auth.py (2)
TokenVerifier(170-193)AccessToken(36-39)src/fastmcp/server/auth/oauth_proxy.py (1)
OAuthProxy(536-2172)
🪛 Ruff (0.14.4)
src/fastmcp/server/auth/providers/discord.py
146-146: Do not catch blind exception: Exception
(BLE001)
181-181: Do not catch blind exception: Exception
(BLE001)
277-279: Avoid specifying long messages outside the exception class
(TRY003)
281-283: Avoid specifying long messages outside the exception class
(TRY003)
304-304: Possible hardcoded password assigned to argument: "upstream_token_endpoint"
(S106)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Run tests: Python 3.10 on windows-latest
🔇 Additional comments (1)
src/fastmcp/server/auth/providers/discord.py (1)
42-65: DiscordProviderSettings env wiring and scope parsing look consistentThe settings model (env prefix, ENV_FILE usage, ignore-extra, and
_parse_scopesdelegating toparse_scopes) is clean and matches the expected pattern for other providers; I don’t see required changes here.Please just confirm
parse_scopesalready handlesNoneand both string / list inputs the same way for other providers.
Description
Add a Discord OAuth provider to the FastMCP server auth stack, mirroring the existing GitHub/Google-style providers.
Contributors Checklist
Review Checklist