fix: omit scope field in OAuth DCR when undefined and improve error handling (#1003)

fix: OAuth DCR scope field compliance

Omits the scope field entirely when undefined, per RFC 7591. This allows OAuth servers to assign default scopes instead of registering clients with no scopes.

Tested with Keycloak DCR.
This commit is contained in:
Ahmet Soormally 2026-01-18 22:22:21 +01:00 • committed by GitHub
commit 2bf0dd1a03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 7 deletions

View file

@ -153,15 +153,22 @@ export class InspectorOAuthClientProvider implements OAuthClientProvider {
}
get clientMetadata(): OAuthClientMetadata {
return {
const metadata: OAuthClientMetadata = {
redirect_uris: this.redirect_uris,
token_endpoint_auth_method: "none",
grant_types: ["authorization_code", "refresh_token"],
response_types: ["code"],
client_name: "MCP Inspector",
client_uri: "https://github.com/modelcontextprotocol/inspector",
scope: this.scope ?? "",
};
// Only include scope if it's defined and non-empty
// Per OAuth spec, omit the scope field entirely if no scopes are requested
if (this.scope) {
metadata.scope = this.scope;
}
return metadata;
}
state(): string | Promise<string> {

View file

@ -393,11 +393,22 @@ export function useConnection({
saveScopeToSessionStorage(sseUrl, scope);
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
const result = await auth(serverAuthProvider, {
serverUrl: sseUrl,
scope,
});
return result === "AUTHORIZED";
try {
const result = await auth(serverAuthProvider, {
serverUrl: sseUrl,
scope,
});
return result === "AUTHORIZED";
} catch (authError) {
// Show user-friendly error message for OAuth failures
toast({
title: "OAuth Authentication Failed",
description:
authError instanceof Error ? authError.message : String(authError),
variant: "destructive",
});
return false;
}
}
return false;