Skip to content

oauth: use requested scopes instead of all supported scope #590

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 3 commits into
base: main
Choose a base branch
from

Conversation

howardjohn
Copy link

Motivation and Context

This mirrors the logic in client_registration

Fixes #587

Without this change, all supported scopes are requested rather than just the ones suggested by the PRM

How Has This Been Tested?

Manually tested

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@cliffhall
Copy link
Member

cliffhall commented Jul 23, 2025

Hi @howardjohn! Thanks for this contribution. It's right, but we also need to do the same thing in useConnection.ts in the handleAuthError function.

Separately, we were considering a solution like this in useConnection

const handleAuthError = async (error: unknown) => {  
  if (is401Error(error)) {  
    const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);  
      
    // Minimal scope discovery  
    let scope: string | undefined = undefined;  
    try {  
      const metadata = await discoverOAuthMetadata(sseUrl);  
      if (metadata?.scopes_supported) {  
        scope = metadata.scopes_supported.join(" ");  
      }  
    } catch (error) {  
      // Continue without scope if discovery fails  
    }  
  
    const result = await auth(serverAuthProvider, {   
      serverUrl: sseUrl,  
      scope   
    });  
    return result === "AUTHORIZED";  
  }  
  
  return false;  
};

I think we should try and extract the logic into a function that can be used in both places. Would you mind looking into that here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants