{"record":{"id":"fd49f6580d7e9fb6","repo":"mastra-ai/mastra","slug":"mcp-client-on-request-elicitation-failed","errorCode":"MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED","errorMessage":"MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED","messagePattern":"MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/client/configuration.ts","lineNumber":283,"sourceCode":"       * @param serverName - Name of the server to handle elicitation requests for\n       * @param handler - Function to handle elicitation requests\n       * @throws {MastraError} If setting up the handler fails\n       *\n       * @example\n       * ```typescript\n       * await mcp.elicitation.onRequest('weatherServer', async (request) => {\n       *   // Prompt user for input\n       *   const userInput = await promptUser(request.requestedSchema);\n       *   return { action: 'accept', content: userInput };\n       * });\n       * ```\n       */\n      onRequest: async (serverName: string, handler: (request: ElicitRequest['params']) => Promise<ElicitResult>) => {\n        try {\n          const internalClient = await this.getClientForServer(serverName);\n          return internalClient.elicitation.onRequest(handler);\n        } catch (err) {\n          throw new MastraError(\n            {\n              id: 'MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED',\n              domain: ErrorDomain.MCP,\n              category: ErrorCategory.THIRD_PARTY,\n              details: {\n                serverName,\n              },\n            },\n            err,\n          );\n        }\n      },\n    };\n  }\n\n  /**\n   * Provides access to resource-related operations across all configured servers.\n   *","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/client/configuration.ts#L265-L301","documentation":"Thrown when registering an elicitation request handler fails: MCPClient's elicitation.onRequest(serverName, handler) looks up the client for that server and attaches the handler; failures are wrapped in a MastraError with id MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED (category THIRD_PARTY). Elicitation lets an MCP server ask the user for input mid-tool-call, so this error means user-input solicitation could not be wired up for that server.","triggerScenarios":"Calling mcpClient.elicitation.onRequest('myServer', handler) when the server is unknown, unreachable (failed transport/spawn), or the internal elicitation.onRequest registration throws — e.g. wrong serverName key, server not connected, or an already-registered conflicting handler.","commonSituations":"Server name typo vs the servers config; calling onRequest before any tool call connected the server; server crashed and reconnect failed; dev server restarted between registration and use.","solutions":["Verify serverName matches a key in the MCPClient servers configuration exactly.","Confirm the server is running and connectable (start it manually, check logs/transport config), then register the handler.","Register elicitation handlers at client setup time, before invoking tools that may elicit input, and retry after a successful connect.","Catch the error and degrade gracefully: tools that need elicitation will fail their own way; log that elicitation is unavailable."],"exampleFix":"// before\nawait mcp.elicitation.onRequest('db-server ', handler); // trailing space in name\n// after\nawait mcp.elicitation.onRequest('db-server', handler);","handlingStrategy":"try-catch","validationCode":"const configured = Object.keys(serversConfig);\nif (!configured.includes(serverName)) throw new Error(`server not configured: ${serverName}`);","typeGuard":"function isElicitationHandlerError(e: unknown): e is MastraError {\n  return e instanceof MastraError && e.id === 'MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED';\n}","tryCatchPattern":"try {\n  await mcp.elicitation.onRequest(serverName, async (req) => elicitationResultFor(req));\n} catch (e) {\n  if (isElicitationHandlerError(e)) {\n    logger.warn(`elicitation unavailable for ${e.details.serverName}`, e);\n    return; // tools needing input will surface their own failures\n  }\n  throw e;\n}","preventionTips":["Register elicitation handlers before invoking any tools that may elicit user input.","Keep server names in a shared constant/enum used by both config and handler registration.","Verify the server connects (run it manually, check logs) before attaching handlers.","Re-register handlers after server restarts or reconnects."],"tags":["mcp","elicitation","event-handler","server-not-found"],"backgroundTag":"mcp-server-not-connected","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}