( serverName: string, result: ElicitResult, signal: AbortSignal, mode?: 'form' | 'url', elicitationId?: string, )
| 262 | * ElicitResult — hooks may override the action/content or block the response. |
| 263 | */ |
| 264 | export async function runElicitationResultHooks( |
| 265 | serverName: string, |
| 266 | result: ElicitResult, |
| 267 | signal: AbortSignal, |
| 268 | mode?: 'form' | 'url', |
| 269 | elicitationId?: string, |
| 270 | ): Promise<ElicitResult> { |
| 271 | try { |
| 272 | const { elicitationResultResponse, blockingError } = |
| 273 | await executeElicitationResultHooks({ |
| 274 | serverName, |
| 275 | action: result.action, |
| 276 | content: result.content as Record<string, unknown> | undefined, |
| 277 | signal, |
| 278 | mode, |
| 279 | elicitationId, |
| 280 | }) |
| 281 | |
| 282 | if (blockingError) { |
| 283 | void executeNotificationHooks({ |
| 284 | message: `Elicitation response for server "${serverName}": decline`, |
| 285 | notificationType: 'elicitation_response', |
| 286 | }) |
| 287 | return { action: 'decline' } |
| 288 | } |
| 289 | |
| 290 | const finalResult = elicitationResultResponse |
| 291 | ? { |
| 292 | action: elicitationResultResponse.action, |
| 293 | content: elicitationResultResponse.content ?? result.content, |
| 294 | } |
| 295 | : result |
| 296 | |
| 297 | // Fire a notification for observability |
| 298 | void executeNotificationHooks({ |
| 299 | message: `Elicitation response for server "${serverName}": ${finalResult.action}`, |
| 300 | notificationType: 'elicitation_response', |
| 301 | }) |
| 302 | |
| 303 | return finalResult |
| 304 | } catch (error) { |
| 305 | logMCPError(serverName, `ElicitationResult hook error: ${error}`) |
| 306 | // Fire notification even on error |
| 307 | void executeNotificationHooks({ |
| 308 | message: `Elicitation response for server "${serverName}": ${result.action}`, |
| 309 | notificationType: 'elicitation_response', |
| 310 | }) |
| 311 | return result |
| 312 | } |
| 313 | } |
| 314 |
no test coverage detected