@@ -30,7 +30,7 @@ import {
3030 Progress ,
3131} from "@modelcontextprotocol/sdk/types.js" ;
3232import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js" ;
33- import { useState } from "react" ;
33+ import { useMemo , useState } from "react" ;
3434import { useToast } from "@/lib/hooks/useToast" ;
3535import { z } from "zod" ;
3636import { ConnectionStatus } from "../constants" ;
@@ -45,6 +45,7 @@ import {
4545} from "@/utils/configUtils" ;
4646import { getMCPServerRequestTimeout } from "@/utils/configUtils" ;
4747import { InspectorConfig } from "../configurationTypes" ;
48+ import { OAuthClientInformation } from "@modelcontextprotocol/sdk/shared/auth.js" ;
4849
4950interface UseConnectionOptions {
5051 transportType : "stdio" | "sse" | "streamable-http" ;
@@ -54,6 +55,7 @@ interface UseConnectionOptions {
5455 env : Record < string , string > ;
5556 bearerToken ?: string ;
5657 headerName ?: string ;
58+ oauthClientId ?: string ;
5759 config : InspectorConfig ;
5860 onNotification ?: ( notification : Notification ) => void ;
5961 onStdErrNotification ?: ( notification : Notification ) => void ;
@@ -71,6 +73,7 @@ export function useConnection({
7173 env,
7274 bearerToken,
7375 headerName,
76+ oauthClientId,
7477 config,
7578 onNotification,
7679 onStdErrNotification,
@@ -88,6 +91,15 @@ export function useConnection({
8891 > ( [ ] ) ;
8992 const [ completionsSupported , setCompletionsSupported ] = useState ( true ) ;
9093
94+ const oauthClientInformation : OAuthClientInformation | undefined =
95+ useMemo ( ( ) => {
96+ if ( ! oauthClientId ) {
97+ return undefined ;
98+ }
99+
100+ return { client_id : oauthClientId } ;
101+ } , [ oauthClientId ] ) ;
102+
91103 const pushHistory = ( request : object , response ?: object ) => {
92104 setRequestHistory ( ( prev ) => [
93105 ...prev ,
@@ -252,7 +264,10 @@ export function useConnection({
252264 const handleAuthError = async ( error : unknown ) => {
253265 if ( error instanceof SseError && error . code === 401 ) {
254266 // Create a new auth provider with the current server URL
255- const serverAuthProvider = new InspectorOAuthClientProvider ( sseUrl ) ;
267+ const serverAuthProvider = new InspectorOAuthClientProvider (
268+ sseUrl ,
269+ oauthClientInformation ,
270+ ) ;
256271
257272 const result = await auth ( serverAuthProvider , { serverUrl : sseUrl } ) ;
258273 return result === "AUTHORIZED" ;
@@ -290,7 +305,10 @@ export function useConnection({
290305 const headers : HeadersInit = { } ;
291306
292307 // Create an auth provider with the current server URL
293- const serverAuthProvider = new InspectorOAuthClientProvider ( sseUrl ) ;
308+ const serverAuthProvider = new InspectorOAuthClientProvider (
309+ sseUrl ,
310+ oauthClientInformation ,
311+ ) ;
294312
295313 // Use manually provided bearer token if available, otherwise use OAuth tokens
296314 const token =
@@ -463,7 +481,10 @@ export function useConnection({
463481
464482 const disconnect = async ( ) => {
465483 await mcpClient ?. close ( ) ;
466- const authProvider = new InspectorOAuthClientProvider ( sseUrl ) ;
484+ const authProvider = new InspectorOAuthClientProvider (
485+ sseUrl ,
486+ oauthClientInformation ,
487+ ) ;
467488 authProvider . clear ( ) ;
468489 setMcpClient ( null ) ;
469490 setConnectionStatus ( "disconnected" ) ;
0 commit comments