Skip to content

Commit 96875a2

Browse files
committed
fix: use supported scopes on connection
1 parent 5e6095d commit 96875a2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 8 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,15 @@ export function useConnection({
317317
if (is401Error(error)) {
318318
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
319319

320+
let scope = oauthScope;
321+
const resourceMetadata = await discoverOAuthProtectedResourceMetadata(sseUrl);
322+
if (resourceMetadata?.scopes_supported) {
323+
scope = resourceMetadata.scopes_supported.join(" ");
324+
}
325+
320326
const result = await auth(serverAuthProvider, {
321327
serverUrl: sseUrl,
322-
scope: oauthScope,
328+
scope,
323329
});
324330
return result === "AUTHORIZED";
325331
}

0 commit comments

Comments
 (0)