MCPcopy Create free account
hub / github.com/modelcontextprotocol/inspector / connect

Function connect

client/src/lib/hooks/useConnection.ts:447–1158  ·  view source on GitHub ↗
(_e?: unknown, retryCount: number = 0)

Source from the content-addressed store, hash-verified

445 };
446
447 const connect = async (_e?: unknown, retryCount: number = 0) => {
448 const clientCapabilities = {
449 capabilities: {
450 sampling: {},
451 elicitation: {
452 form: {},
453 url: {},
454 },
455 roots: {
456 listChanged: true,
457 },
458 tasks: {
459 list: {},
460 cancel: {},
461 ...(onPendingRequest || onElicitationRequest
462 ? {
463 requests: {
464 ...(onPendingRequest
465 ? { sampling: { createMessage: {} } }
466 : undefined),
467 ...(onElicitationRequest
468 ? { elicitation: { create: {} } }
469 : undefined),
470 },
471 }
472 : undefined),
473 },
474 },
475 };
476
477 const client = new Client<Request, Notification, Result>(
478 CLIENT_IDENTITY,
479 clientCapabilities,
480 );
481
482 // Only check proxy health for proxy connections
483 if (connectionType === "proxy") {
484 try {
485 await checkProxyHealth();
486 } catch {
487 setConnectionStatus("error-connecting-to-proxy");
488 return;
489 }
490 }
491
492 let lastRequest = "";
493 try {
494 // Inject auth manually instead of using SSEClientTransport, because we're
495 // proxying through the inspector server first.
496 const headers: HeadersInit = {};
497
498 // Create an auth provider with the current server URL
499 const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
500
501 // Use custom headers (migration is handled in App.tsx)
502 let finalHeaders: CustomHeaders = customHeaders || [];
503
504 const isEmptyAuthHeader = (header: CustomHeaders[number]) =>

Callers

nothing calls this directly

Calls 15

tokensMethod · 0.95
getMCPProxyAuthTokenFunction · 0.90
getMCPProxyAddressFunction · 0.90
resolveRefsInMessageFunction · 0.90
isConnectionAuthErrorFunction · 0.90
checkProxyHealthFunction · 0.85
isEmptyAuthHeaderFunction · 0.85
toastFunction · 0.85
captureResponseHeadersFunction · 0.85
pushHistoryFunction · 0.85
isProxyAuthErrorFunction · 0.85
handleAuthErrorFunction · 0.85

Tested by

no test coverage detected