mastra-ai/mastra · error · MastraError

MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED

MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED

Error message

MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED

What it means

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.

Source

Thrown at packages/mcp/src/client/configuration.ts:283

       * @param serverName - Name of the server to handle elicitation requests for
       * @param handler - Function to handle elicitation requests
       * @throws {MastraError} If setting up the handler fails
       *
       * @example
       * ```typescript
       * await mcp.elicitation.onRequest('weatherServer', async (request) => {
       *   // Prompt user for input
       *   const userInput = await promptUser(request.requestedSchema);
       *   return { action: 'accept', content: userInput };
       * });
       * ```
       */
      onRequest: async (serverName: string, handler: (request: ElicitRequest['params']) => Promise<ElicitResult>) => {
        try {
          const internalClient = await this.getClientForServer(serverName);
          return internalClient.elicitation.onRequest(handler);
        } catch (err) {
          throw new MastraError(
            {
              id: 'MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED',
              domain: ErrorDomain.MCP,
              category: ErrorCategory.THIRD_PARTY,
              details: {
                serverName,
              },
            },
            err,
          );
        }
      },
    };
  }

  /**
   * Provides access to resource-related operations across all configured servers.
   *

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify serverName matches a key in the MCPClient servers configuration exactly.
  2. Confirm the server is running and connectable (start it manually, check logs/transport config), then register the handler.
  3. Register elicitation handlers at client setup time, before invoking tools that may elicit input, and retry after a successful connect.
  4. Catch the error and degrade gracefully: tools that need elicitation will fail their own way; log that elicitation is unavailable.

Example fix

// before
await mcp.elicitation.onRequest('db-server ', handler); // trailing space in name
// after
await mcp.elicitation.onRequest('db-server', handler);
Defensive patterns

Strategy: try-catch

Validate before calling

const configured = Object.keys(serversConfig);
if (!configured.includes(serverName)) throw new Error(`server not configured: ${serverName}`);

Type guard

function isElicitationHandlerError(e: unknown): e is MastraError {
  return e instanceof MastraError && e.id === 'MCP_CLIENT_ON_REQUEST_ELICITATION_FAILED';
}

Try / catch

try {
  await mcp.elicitation.onRequest(serverName, async (req) => elicitationResultFor(req));
} catch (e) {
  if (isElicitationHandlerError(e)) {
    logger.warn(`elicitation unavailable for ${e.details.serverName}`, e);
    return; // tools needing input will surface their own failures
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/fd49f6580d7e9fb6. Report an issue: GitHub.