Skip to content

Commit 5323d4d

Browse files
committed
Fix connect button behavior for Oauth by making sure that scope is included in client metadata when client is registered.
- In auth.ts - in InspectorOAuthClientProvider constructor - add optional scope param - set instance var this.scope to scope param - in clientMetadata getter - add scope param set to this.scope or "" - in useConnection.ts - in handleAuthError handler - move instantiation of serverAuthProvider until after scope has been determined - pass scope to InspectorOAuthClientProvider constructor
1 parent 94f44c7 commit 5323d4d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

client/src/lib/auth.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ export const clearClientInformationFromSessionStorage = ({
102102
};
103103

104104
export class InspectorOAuthClientProvider implements OAuthClientProvider {
105-
constructor(protected serverUrl: string) {
105+
constructor(
106+
protected serverUrl: string,
107+
scope?: string,
108+
) {
109+
this.scope = scope;
106110
// Save the server URL to session storage
107111
sessionStorage.setItem(SESSION_KEYS.SERVER_URL, serverUrl);
108112
}
113+
scope: string | undefined;
109114

110115
get redirectUrl() {
111116
return window.location.origin + "/oauth/callback";
@@ -119,6 +124,7 @@ export class InspectorOAuthClientProvider implements OAuthClientProvider {
119124
response_types: ["code"],
120125
client_name: "MCP Inspector",
121126
client_uri: "https://github.com/modelcontextprotocol/inspector",
127+
scope: this.scope ?? "",
122128
};
123129
}
124130

client/src/lib/hooks/useConnection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ export function useConnection({
319319

320320
const handleAuthError = async (error: unknown) => {
321321
if (is401Error(error)) {
322-
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
323-
324322
let scope = oauthScope?.trim();
325323
if (!scope) {
326324
// Only discover resource metadata when we need to discover scopes
@@ -334,6 +332,7 @@ export function useConnection({
334332
}
335333
scope = await discoverScopes(sseUrl, resourceMetadata);
336334
}
335+
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl, scope);
337336

338337
const result = await auth(serverAuthProvider, {
339338
serverUrl: sseUrl,

0 commit comments

Comments
 (0)