@@ -25,7 +25,7 @@ import {
25
25
Progress ,
26
26
} from "@modelcontextprotocol/sdk/types.js" ;
27
27
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js" ;
28
- import { useState } from "react" ;
28
+ import { useMemo , useState } from "react" ;
29
29
import { useToast } from "@/hooks/use-toast" ;
30
30
import { z } from "zod" ;
31
31
import { ConnectionStatus } from "../constants" ;
@@ -40,6 +40,7 @@ import {
40
40
} from "@/utils/configUtils" ;
41
41
import { getMCPServerRequestTimeout } from "@/utils/configUtils" ;
42
42
import { InspectorConfig } from "../configurationTypes" ;
43
+ import { OAuthClientInformation } from "@modelcontextprotocol/sdk/shared/auth.js" ;
43
44
44
45
interface UseConnectionOptions {
45
46
transportType : "stdio" | "sse" | "streamable-http" ;
@@ -49,6 +50,7 @@ interface UseConnectionOptions {
49
50
env : Record < string , string > ;
50
51
bearerToken ?: string ;
51
52
headerName ?: string ;
53
+ oauthClientId ?: string ;
52
54
config : InspectorConfig ;
53
55
onNotification ?: ( notification : Notification ) => void ;
54
56
onStdErrNotification ?: ( notification : Notification ) => void ;
@@ -66,6 +68,7 @@ export function useConnection({
66
68
env,
67
69
bearerToken,
68
70
headerName,
71
+ oauthClientId,
69
72
config,
70
73
onNotification,
71
74
onStdErrNotification,
@@ -83,6 +86,15 @@ export function useConnection({
83
86
> ( [ ] ) ;
84
87
const [ completionsSupported , setCompletionsSupported ] = useState ( true ) ;
85
88
89
+ const oauthClientInformation : OAuthClientInformation | undefined =
90
+ useMemo ( ( ) => {
91
+ if ( ! oauthClientId ) {
92
+ return undefined ;
93
+ }
94
+
95
+ return { client_id : oauthClientId } ;
96
+ } , [ oauthClientId ] ) ;
97
+
86
98
const pushHistory = ( request : object , response ?: object ) => {
87
99
setRequestHistory ( ( prev ) => [
88
100
...prev ,
@@ -247,7 +259,10 @@ export function useConnection({
247
259
const handleAuthError = async ( error : unknown ) => {
248
260
if ( error instanceof SseError && error . code === 401 ) {
249
261
// Create a new auth provider with the current server URL
250
- const serverAuthProvider = new InspectorOAuthClientProvider ( sseUrl ) ;
262
+ const serverAuthProvider = new InspectorOAuthClientProvider (
263
+ sseUrl ,
264
+ oauthClientInformation ,
265
+ ) ;
251
266
252
267
const result = await auth ( serverAuthProvider , { serverUrl : sseUrl } ) ;
253
268
return result === "AUTHORIZED" ;
@@ -294,7 +309,10 @@ export function useConnection({
294
309
const headers : HeadersInit = { } ;
295
310
296
311
// Create an auth provider with the current server URL
297
- const serverAuthProvider = new InspectorOAuthClientProvider ( sseUrl ) ;
312
+ const serverAuthProvider = new InspectorOAuthClientProvider (
313
+ sseUrl ,
314
+ oauthClientInformation ,
315
+ ) ;
298
316
299
317
// Use manually provided bearer token if available, otherwise use OAuth tokens
300
318
const token =
@@ -396,7 +414,10 @@ export function useConnection({
396
414
397
415
const disconnect = async ( ) => {
398
416
await mcpClient ?. close ( ) ;
399
- const authProvider = new InspectorOAuthClientProvider ( sseUrl ) ;
417
+ const authProvider = new InspectorOAuthClientProvider (
418
+ sseUrl ,
419
+ oauthClientInformation ,
420
+ ) ;
400
421
authProvider . clear ( ) ;
401
422
setMcpClient ( null ) ;
402
423
setConnectionStatus ( "disconnected" ) ;
0 commit comments