@@ -249,9 +249,16 @@ export function useConnection({
249
249
}
250
250
} ;
251
251
252
+ const is401Error = ( error : unknown ) : boolean => {
253
+ return (
254
+ ( error instanceof SseError && error . code === 401 ) ||
255
+ ( error instanceof Error && error . message . includes ( "401" ) ) ||
256
+ ( error instanceof Error && error . message . includes ( "Unauthorized" ) )
257
+ ) ;
258
+ } ;
259
+
252
260
const handleAuthError = async ( error : unknown ) => {
253
- if ( error instanceof SseError && error . code === 401 ) {
254
- // Create a new auth provider with the current server URL
261
+ if ( is401Error ( error ) ) {
255
262
const serverAuthProvider = new InspectorOAuthClientProvider ( sseUrl ) ;
256
263
257
264
const result = await auth ( serverAuthProvider , { serverUrl : sseUrl } ) ;
@@ -330,7 +337,6 @@ export function useConnection({
330
337
mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /sse` ) ;
331
338
mcpProxyServerUrl . searchParams . append ( "url" , sseUrl ) ;
332
339
transportOptions = {
333
- authProvider : serverAuthProvider ,
334
340
eventSourceInit : {
335
341
fetch : (
336
342
url : string | URL | globalThis . Request ,
@@ -347,7 +353,6 @@ export function useConnection({
347
353
mcpProxyServerUrl = new URL ( `${ getMCPProxyAddress ( config ) } /mcp` ) ;
348
354
mcpProxyServerUrl . searchParams . append ( "url" , sseUrl ) ;
349
355
transportOptions = {
350
- authProvider : serverAuthProvider ,
351
356
eventSourceInit : {
352
357
fetch : (
353
358
url : string | URL | globalThis . Request ,
@@ -425,13 +430,14 @@ export function useConnection({
425
430
`Failed to connect to MCP Server via the MCP Inspector Proxy: ${ mcpProxyServerUrl } :` ,
426
431
error ,
427
432
) ;
433
+
428
434
const shouldRetry = await handleAuthError ( error ) ;
429
435
if ( shouldRetry ) {
430
436
return connect ( undefined , retryCount + 1 ) ;
431
437
}
432
-
433
- if ( error instanceof SseError && error . code === 401 ) {
438
+ if ( is401Error ( error ) ) {
434
439
// Don't set error state if we're about to redirect for auth
440
+
435
441
return ;
436
442
}
437
443
throw error ;
0 commit comments