Skip to content

Commit 5601411

Browse files
committed
fix: omit scope field in OAuth DCR when undefined and improve error handling
1 parent 9bb76ee commit 5601411

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

client/src/lib/auth.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,22 @@ export class InspectorOAuthClientProvider implements OAuthClientProvider {
153153
}
154154

155155
get clientMetadata(): OAuthClientMetadata {
156-
return {
156+
const metadata: OAuthClientMetadata = {
157157
redirect_uris: this.redirect_uris,
158158
token_endpoint_auth_method: "none",
159159
grant_types: ["authorization_code", "refresh_token"],
160160
response_types: ["code"],
161161
client_name: "MCP Inspector",
162162
client_uri: "https://github.com/modelcontextprotocol/inspector",
163-
scope: this.scope ?? "",
164163
};
164+
165+
// Only include scope if it's defined and non-empty
166+
// Per OAuth spec, omit the scope field entirely if no scopes are requested
167+
if (this.scope) {
168+
metadata.scope = this.scope;
169+
}
170+
171+
return metadata;
165172
}
166173

167174
state(): string | Promise<string> {

client/src/lib/hooks/useConnection.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,22 @@ export function useConnection({
389389
saveScopeToSessionStorage(sseUrl, scope);
390390
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
391391

392-
const result = await auth(serverAuthProvider, {
393-
serverUrl: sseUrl,
394-
scope,
395-
});
396-
return result === "AUTHORIZED";
392+
try {
393+
const result = await auth(serverAuthProvider, {
394+
serverUrl: sseUrl,
395+
scope,
396+
});
397+
return result === "AUTHORIZED";
398+
} catch (authError) {
399+
// Show user-friendly error message for OAuth failures
400+
toast({
401+
title: "OAuth Authentication Failed",
402+
description:
403+
authError instanceof Error ? authError.message : String(authError),
404+
variant: "destructive",
405+
});
406+
return false;
407+
}
397408
}
398409

399410
return false;

0 commit comments

Comments
 (0)