{"record":{"id":"a3d9e639c50752a9","repo":"mastra-ai/mastra","slug":"cannot-register-an-elicitation-handler-after-conne","errorCode":null,"errorMessage":"Cannot register an elicitation handler after connecting unless elicitation capability was configured before initialization.","messagePattern":"Cannot register an elicitation handler after connecting unless elicitation capability was configured before initialization\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/client/client.ts","lineNumber":1219,"sourceCode":"    this.log('debug', 'Setting resource list changed notification handler');\n    this.client.setNotificationHandler('notifications/resources/list_changed', () => {\n      handler();\n    });\n  }\n\n  setElicitationRequestHandler(handler: ElicitationHandler): void {\n    this.log('debug', 'Setting elicitation request handler');\n    // The handler serves both protocol eras: on legacy (2025-era) connections it\n    // answers elicitation/create wire requests; on negotiated 2026-07-28\n    // connections the SDK's multi-round-trip driver dispatches embedded\n    // elicitation requests from input_required results through the same\n    // registered handler and retries the originating call automatically.\n    if (!this.hasElicitationCapability) {\n      try {\n        this.client.registerCapabilities({ elicitation: { form: {} } });\n        this.hasElicitationCapability = true;\n      } catch (error) {\n        throw new Error(\n          'Cannot register an elicitation handler after connecting unless elicitation capability was configured before initialization.',\n          { cause: error },\n        );\n      }\n    }\n\n    this.client.setRequestHandler('elicitation/create', async request => {\n      this.log('debug', `Received elicitation request: ${request.params.message}`);\n      return handler(request.params);\n    });\n  }\n\n  setProgressNotificationHandler(handler: ProgressHandler): void {\n    this.log('debug', 'Setting progress notification handler');\n    this.client.setNotificationHandler('notifications/progress', notification => {\n      handler(notification.params);\n    });\n  }","sourceCodeStart":1201,"sourceCodeEnd":1237,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/client/client.ts#L1201-L1237","documentation":"Elicitation capability must be negotiated during MCP initialization. registerElicitationHandler tries to late-register the elicitation capability on the connected Client via registerCapabilities({ elicitation: { form: {} } }); if the underlying SDK throws (capability cannot be added after initialization), this error is thrown with the original error as cause.","triggerScenarios":"Setting an elicitation handler after connect() has completed initialization on a server/client pair that did NOT negotiate the elicitation capability during initialize; the late registerCapabilities call fails and is rethrown wrapped.","commonSituations":"Adding elicitation support to an existing client without restarting the connection; server not advertising elicitation support; constructing the client without the elicitation capability option and then wiring the handler post-connect.","solutions":["Configure the elicitation capability up front when creating the client, before connect()/initialization","Restart/reconnect the client with elicitation capability enabled if the handler is added late","Verify the MCP SDK/server version supports elicitation and form capability","Check the `cause` of the error for the underlying SDK failure"],"exampleFix":"// before\nconst client = new InternalMastraMCPClient({ name: 'x', url });\nawait client.connect();\nclient.registerElicitationHandler(handler); // throws\n// after\nconst client = new InternalMastraMCPClient({ name: 'x', url, capabilities: { elicitation: { form: {} } } });\nclient.registerElicitationHandler(handler);\nawait client.connect();","handlingStrategy":"validation","validationCode":"if (!client.isConnected()) {\n  // safe: capability can still be configured before initialization\n  client.registerElicitationHandler(handler);\n} else {\n  throw new Error('Register elicitation handlers before connect()');\n}","typeGuard":null,"tryCatchPattern":"try {\n  client.registerElicitationHandler(handler);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('elicitation capability')) {\n    // recreate the client with elicitation capability configured pre-init, then reconnect\n  }\n  throw e;\n}","preventionTips":["Declare the elicitation capability in client options before connect(), never after","Register handlers during client setup, prior to initialization","Verify SDK/server versions support elicitation before enabling it","Inspect error.cause for the underlying registerCapabilities failure"],"tags":["mcp","elicitation","capability","initialization"],"backgroundTag":"capability-not-negotiated","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}