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

Function handleCompletion

client/src/lib/hooks/useConnection.ts:282–332  ·  view source on GitHub ↗
(
    ref: ResourceReference | PromptReference,
    argName: string,
    value: string,
    context?: Record<string, string>,
    signal?: AbortSignal,
  )

Source from the content-addressed store, hash-verified

280 };
281
282 const handleCompletion = async (
283 ref: ResourceReference | PromptReference,
284 argName: string,
285 value: string,
286 context?: Record<string, string>,
287 signal?: AbortSignal,
288 ): Promise<string[]> => {
289 if (!mcpClient || !completionsSupported) {
290 return [];
291 }
292
293 const request: ClientRequest = {
294 method: "completion/complete",
295 params: {
296 argument: {
297 name: argName,
298 value,
299 },
300 ref,
301 },
302 };
303
304 if (context) {
305 request["params"]["context"] = {
306 arguments: context,
307 };
308 }
309
310 try {
311 const response = await makeRequest(request, CompleteResultSchema, {
312 signal,
313 suppressToast: true,
314 });
315 return response?.completion.values || [];
316 } catch (e: unknown) {
317 // Disable completions silently if the server doesn't support them.
318 // See https://github.com/modelcontextprotocol/specification/discussions/122
319 if (e instanceof McpError && e.code === ErrorCode.MethodNotFound) {
320 setCompletionsSupported(false);
321 return [];
322 }
323
324 // Unexpected errors - show toast and rethrow
325 toast({
326 title: "Error",
327 description: e instanceof Error ? e.message : String(e),
328 variant: "destructive",
329 });
330 throw e;
331 }
332 };
333
334 const sendNotification = async (notification: ClientNotification) => {
335 if (!mcpClient) {

Callers 1

useCompletionStateFunction · 0.85

Calls 2

makeRequestFunction · 0.85
toastFunction · 0.85

Tested by

no test coverage detected