MCPcopy
hub / github.com/codeaashu/claude-code / registerElicitationHandlers

Function registerElicitationHandlers

src/cli/print.ts:1263–1387  ·  view source on GitHub ↗

* Register elicitation request/completion handlers on connected MCP clients * that haven't been registered yet. SDK MCP servers are excluded because they * route through SdkControlClientTransport. Hooks run first (matching REPL * behavior); if no hook responds, the request is forwarded to t

(clients: MCPServerConnection[])

Source from the content-addressed store, hash-verified

1261 * consumer via the control protocol.
1262 */
1263 function registerElicitationHandlers(clients: MCPServerConnection[]): void {
1264 for (const connection of clients) {
1265 if (
1266 connection.type !== 'connected' ||
1267 elicitationRegistered.has(connection.name)
1268 ) {
1269 continue
1270 }
1271 // Skip SDK MCP servers — elicitation flows through SdkControlClientTransport
1272 if (connection.config.type === 'sdk') {
1273 continue
1274 }
1275 const serverName = connection.name
1276
1277 // Wrapped in try/catch because setRequestHandler throws if the client wasn't
1278 // created with elicitation capability declared (e.g., SDK-created clients).
1279 try {
1280 connection.client.setRequestHandler(
1281 ElicitRequestSchema,
1282 async (request, extra) => {
1283 logMCPDebug(
1284 serverName,
1285 `Elicitation request received in print mode: ${jsonStringify(request)}`,
1286 )
1287
1288 const mode = request.params.mode === 'url' ? 'url' : 'form'
1289
1290 logEvent('tengu_mcp_elicitation_shown', {
1291 mode: mode as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
1292 })
1293
1294 // Run elicitation hooks first — they can provide a response programmatically
1295 const hookResponse = await runElicitationHooks(
1296 serverName,
1297 request.params,
1298 extra.signal,
1299 )
1300 if (hookResponse) {
1301 logMCPDebug(
1302 serverName,
1303 `Elicitation resolved by hook: ${jsonStringify(hookResponse)}`,
1304 )
1305 logEvent('tengu_mcp_elicitation_response', {
1306 mode: mode as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
1307 action:
1308 hookResponse.action as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
1309 })
1310 return hookResponse
1311 }
1312
1313 // Delegate to SDK consumer via control protocol
1314 const url =
1315 'url' in request.params
1316 ? (request.params.url as string)
1317 : undefined
1318 const requestedSchema =
1319 'requestedSchema' in request.params
1320 ? (request.params.requestedSchema as

Callers 2

drainCommandQueueFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 11

logMCPDebugFunction · 0.85
jsonStringifyFunction · 0.85
logEventFunction · 0.85
runElicitationHooksFunction · 0.85
executeNotificationHooksFunction · 0.85
getSessionIdFunction · 0.85
handleElicitationMethod · 0.80
hasMethod · 0.45
enqueueMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected