( p: (input: I, meta: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<O> )
| 413 | * @returns |
| 414 | */ |
| 415 | export function withStructuredResponse<I, O>( |
| 416 | p: (input: I, meta: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<O> |
| 417 | ): (input: I, meta: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<CallToolResult> { |
| 418 | return async (i, meta) => { |
| 419 | try { |
| 420 | const result = await p(i, meta); |
| 421 | |
| 422 | return { |
| 423 | structuredContent: { |
| 424 | result, |
| 425 | }, |
| 426 | content: [ |
| 427 | { |
| 428 | type: 'text', |
| 429 | text: JSON.stringify(result, null, 2), |
| 430 | }, |
| 431 | ], |
| 432 | }; |
| 433 | } catch (e: any) { |
| 434 | return { |
| 435 | isError: true, |
| 436 | structuredContent: { |
| 437 | error: formatErrorCauses(e as Error), |
| 438 | }, |
| 439 | content: [ |
| 440 | { |
| 441 | type: 'text', |
| 442 | text: `Error running: ${formatErrorCauses(e)}`, |
| 443 | }, |
| 444 | ], |
| 445 | }; |
| 446 | } |
| 447 | }; |
| 448 | } |
| 449 | |
| 450 | export type MCPToolOptions = { |
| 451 | /** |
no test coverage detected