Skip to content

Commit 958902f

Browse files
committed
fix: use supported scopes on connection
1 parent 618370d commit 958902f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { useToast } from "@/lib/hooks/useToast";
3737
import { z } from "zod";
3838
import { ConnectionStatus } from "../constants";
3939
import { Notification, StdErrNotificationSchema } from "../notificationTypes";
40-
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
40+
import { auth, discoverOAuthProtectedResourceMetadata } from "@modelcontextprotocol/sdk/client/auth.js";
4141
import {
4242
clearClientInformationFromSessionStorage,
4343
InspectorOAuthClientProvider,
@@ -317,9 +317,19 @@ export function useConnection({
317317
if (is401Error(error)) {
318318
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
319319

320+
let scope = oauthScope;
321+
try {
322+
const resourceMetadata = await discoverOAuthProtectedResourceMetadata(sseUrl);
323+
if (resourceMetadata?.scopes_supported) {
324+
scope = resourceMetadata.scopes_supported.join(" ");
325+
}
326+
} catch {
327+
// Continue without scope if discovery fails
328+
}
329+
320330
const result = await auth(serverAuthProvider, {
321331
serverUrl: sseUrl,
322-
scope: oauthScope,
332+
scope,
323333
});
324334
return result === "AUTHORIZED";
325335
}

0 commit comments

Comments
 (0)