Skip to content

oauth client example: skip DCR if MCP_CLIENT_ID is set #549

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

djoreilly
Copy link

@djoreilly djoreilly commented Aug 14, 2025

Description

If the user has set the MCP_CLIENT_ID environmental variable then they don't want Dynamic Client Registration and it should be skipped.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • MCP spec compatibility implementation
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Tests only (no functional changes)
  • Other (please describe):

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly

MCP Spec Compliance

  • This PR implements a feature defined in the MCP specification
  • Link to relevant spec section: Link text
  • Implementation follows the specification exactly

Additional Information

Summary by CodeRabbit

  • Bug Fixes
    • Prevents duplicate OAuth client registration, reducing errors when rerunning the example.
    • Improves reliability of the authorization flow by registering only when necessary, ensuring smoother browser launch, callback handling, and token exchange.
  • Chores
    • Minor internal adjustments to streamline OAuth setup behavior without affecting public interfaces.

If the user has set the MCP_CLIENT_ID environmental variable then they
don't want Dynamic Client Registration and it should be skipped.
Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

Introduces a conditional check before registering the OAuth client in examples/oauth_client/main.go. The client is registered only if oauthHandler.GetClientID() returns an empty string. All other OAuth flow steps remain unchanged.

Changes

Cohort / File(s) Summary
OAuth example client logic
examples/oauth_client/main.go
Add guard: call RegisterClient only when GetClientID() is empty; retain existing authorization URL generation, browser open, callback wait, and code exchange logic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

type: enhancement

Suggested reviewers

  • giridhar-murthy-glean
  • pottekkat
  • robert-jackson-glean

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
examples/oauth_client/main.go (2)

132-137: Add lightweight logs to clarify whether DCR is performed or skipped

Improves observability and helps users understand why registration ran or was skipped.

Apply this diff:

-        if oauthHandler.GetClientID() == "" {
-            err = oauthHandler.RegisterClient(context.Background(), "mcp-go-oauth-example")
+        if oauthHandler.GetClientID() == "" {
+            log.Printf("No client ID configured; attempting dynamic client registration...")
+            err = oauthHandler.RegisterClient(context.Background(), "mcp-go-oauth-example")
             if err != nil {
                 log.Fatalf("Failed to register client: %v", err)
             }
+        } else {
+            log.Printf("Using configured client ID %q; skipping dynamic client registration.", oauthHandler.GetClientID())
         }

28-36: Sanitize env vars to avoid accidental whitespace causing false “configured” state

If MCP_CLIENT_ID or MCP_CLIENT_SECRET contain only whitespace, GetClientID() may be non-empty and skip DCR, leading to confusing failures later. Trim the env vars at source.

Apply this diff:

-        ClientID:     os.Getenv("MCP_CLIENT_ID"),
-        ClientSecret: os.Getenv("MCP_CLIENT_SECRET"),
+        ClientID:     strings.TrimSpace(os.Getenv("MCP_CLIENT_ID")),
+        ClientSecret: strings.TrimSpace(os.Getenv("MCP_CLIENT_SECRET")),

Also add the import:

 import (
   "context"
   "fmt"
   "log"
   "net/http"
   "os"
   "os/exec"
   "runtime"
+  "strings"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9f16336 and ceaa63c.

📒 Files selected for processing (1)
  • examples/oauth_client/main.go (1 hunks)
🔇 Additional comments (1)
examples/oauth_client/main.go (1)

132-137: LGTM: Conditional DCR guard matches the PR objective and preserves expected behavior

Checking oauthHandler.GetClientID() before calling RegisterClient correctly skips dynamic client registration when a client ID is provided (e.g., via MCP_CLIENT_ID). This aligns with the PR intent without altering the rest of the OAuth flow.

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.

1 participant