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

Function makeRequest

client/src/lib/hooks/useConnection.ts:201–280  ·  view source on GitHub ↗
(
    request: ClientRequest,
    schema: T,
    options?: RequestOptions & { suppressToast?: boolean },
  )

Source from the content-addressed store, hash-verified

199 };
200
201 const makeRequest = async <T extends AnySchema>(
202 request: ClientRequest,
203 schema: T,
204 options?: RequestOptions & { suppressToast?: boolean },
205 ): Promise<SchemaOutput<T>> => {
206 if (!mcpClient) {
207 throw new Error("MCP client not connected");
208 }
209 try {
210 const abortController = new AbortController();
211
212 // Add metadata to the request if available, but skip for tool calls
213 // as they handle metadata merging separately
214 const shouldAddGeneralMetadata =
215 request.method !== "tools/call" && Object.keys(metadata).length > 0;
216 const requestWithMetadata = shouldAddGeneralMetadata
217 ? {
218 ...request,
219 params: {
220 ...request.params,
221 _meta: metadata,
222 },
223 }
224 : request;
225
226 // prepare MCP Client request options
227 const mcpRequestOptions: RequestOptions = {
228 signal: options?.signal ?? abortController.signal,
229 resetTimeoutOnProgress:
230 options?.resetTimeoutOnProgress ??
231 resetRequestTimeoutOnProgress(config),
232 timeout: options?.timeout ?? getMCPServerRequestTimeout(config),
233 maxTotalTimeout:
234 options?.maxTotalTimeout ??
235 getMCPServerRequestMaxTotalTimeout(config),
236 };
237
238 // If progress notifications are enabled, add an onprogress hook to the MCP Client request options
239 // This is required by SDK to reset the timeout on progress notifications
240 if (mcpRequestOptions.resetTimeoutOnProgress) {
241 mcpRequestOptions.onprogress = (params: Progress) => {
242 // Add progress notification to `Server Notification` window in the UI
243 if (onNotification) {
244 onNotification({
245 method: "notifications/progress",
246 params,
247 });
248 }
249 };
250 }
251
252 let response;
253 try {
254 response = await mcpClient.request(
255 requestWithMetadata,
256 schema,
257 mcpRequestOptions,
258 );

Callers 4

sendMCPRequestFunction · 0.85
handleCompletionFunction · 0.85
cancelTaskFunction · 0.85
listTasksFunction · 0.85

Calls 5

pushHistoryFunction · 0.85
toastFunction · 0.85

Tested by

no test coverage detected