Skip to content

Commit ea82eff

Browse files
authored
Merge branch 'main' into add-mcp-docs-server-to-claude
2 parents 4835b73 + 94ba4c3 commit ea82eff

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

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: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,22 @@ export function useConnection({
393393
saveScopeToSessionStorage(sseUrl, scope);
394394
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
395395

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

403414
return false;
@@ -534,6 +545,7 @@ export function useConnection({
534545
requestHeaders["Accept"] = "text/event-stream";
535546
requestHeaders["content-type"] = "application/json";
536547
transportOptions = {
548+
authProvider: serverAuthProvider,
537549
fetch: async (
538550
url: string | URL | globalThis.Request,
539551
init?: RequestInit,
@@ -555,6 +567,7 @@ export function useConnection({
555567

556568
case "streamable-http":
557569
transportOptions = {
570+
authProvider: serverAuthProvider,
558571
fetch: async (
559572
url: string | URL | globalThis.Request,
560573
init?: RequestInit,
@@ -643,6 +656,7 @@ export function useConnection({
643656
);
644657
}
645658
transportOptions = {
659+
authProvider: serverAuthProvider,
646660
eventSourceInit: {
647661
fetch: (
648662
url: string | URL | globalThis.Request,
@@ -664,6 +678,7 @@ export function useConnection({
664678
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
665679
mcpProxyServerUrl.searchParams.append("url", sseUrl);
666680
transportOptions = {
681+
authProvider: serverAuthProvider,
667682
eventSourceInit: {
668683
fetch: (
669684
url: string | URL | globalThis.Request,

0 commit comments

Comments
 (0)