MCPcopy Index your code
hub / github.com/modelcontextprotocol/inspector / useConnection

Function useConnection

client/src/lib/hooks/useConnection.ts:107–1226  ·  view source on GitHub ↗
({
  transportType,
  command,
  args,
  sseUrl,
  env,
  customHeaders,
  oauthClientId,
  oauthClientSecret,
  oauthScope,
  config,
  connectionType = "proxy",
  onNotification,
  onPendingRequest,
  onElicitationRequest,
  getRoots,
  defaultLoggingLevel,
  metadata = {},
}: UseConnectionOptions)

Source from the content-addressed store, hash-verified

105}
106
107export function useConnection({
108 transportType,
109 command,
110 args,
111 sseUrl,
112 env,
113 customHeaders,
114 oauthClientId,
115 oauthClientSecret,
116 oauthScope,
117 config,
118 connectionType = "proxy",
119 onNotification,
120 onPendingRequest,
121 onElicitationRequest,
122 getRoots,
123 defaultLoggingLevel,
124 metadata = {},
125}: UseConnectionOptions) {
126 const [connectionStatus, setConnectionStatus] =
127 useState<ConnectionStatus>("disconnected");
128 const { toast } = useToast();
129 const [serverCapabilities, setServerCapabilities] =
130 useState<ServerCapabilities | null>(null);
131 const [mcpClient, setMcpClient] = useState<Client | null>(null);
132 const [clientTransport, setClientTransport] = useState<Transport | null>(
133 null,
134 );
135 const [requestHistory, setRequestHistory] = useState<
136 { request: string; response?: string }[]
137 >([]);
138 const [completionsSupported, setCompletionsSupported] = useState(false);
139 const [mcpSessionId, setMcpSessionId] = useState<string | null>(null);
140 const [mcpProtocolVersion, setMcpProtocolVersion] = useState<string | null>(
141 null,
142 );
143 const [serverImplementation, setServerImplementation] =
144 useState<Implementation | null>(null);
145
146 type ReceiverTaskRecord = {
147 task: Task;
148 payloadPromise: Promise<ClientResult>;
149 resolvePayload: (payload: ClientResult) => void;
150 rejectPayload: (reason?: unknown) => void;
151 cleanupTimeoutId?: ReturnType<typeof setTimeout>;
152 };
153
154 // Tasks created locally in response to *incoming* task-augmented requests
155 // (e.g. `sampling/createMessage` and `elicitation/create` with `params.task`).
156 const receiverTasksRef = useRef<Map<string, ReceiverTaskRecord>>(new Map());
157
158 useEffect(() => {
159 if (!oauthClientId) {
160 clearClientInformationFromSessionStorage({
161 serverUrl: sseUrl,
162 isPreregistered: true,
163 });
164 return;

Callers 4

AppFunction · 0.90
attemptConnectionFunction · 0.90
attemptConnectFunction · 0.90

Tested by 2

attemptConnectionFunction · 0.72
attemptConnectFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…