* Creates a tool handler with automatic logging
( toolFn: (client: DocumentEngineClient, params: TParams) => Promise<MCPToolOutput> )
| 101 | * Creates a tool handler with automatic logging |
| 102 | */ |
| 103 | function createToolHandler<TParams>( |
| 104 | toolFn: (client: DocumentEngineClient, params: TParams) => Promise<MCPToolOutput> |
| 105 | ): (toolName: string) => MCPToolCallback { |
| 106 | return (toolName: string) => async (server, client, params, extras) => { |
| 107 | const result = await withLogging(toolName, extras, toolFn, server, client, params as TParams); |
| 108 | |
| 109 | // Create the content array with the markdown text |
| 110 | const textContent = { |
| 111 | type: 'text' as const, |
| 112 | text: result.markdown, |
| 113 | }; |
| 114 | |
| 115 | // Create image content items |
| 116 | const imageContents = result.images |
| 117 | ? result.images.map(image => ({ |
| 118 | type: 'image' as const, |
| 119 | data: image.base64, |
| 120 | mimeType: image.mimeType, |
| 121 | })) |
| 122 | : []; |
| 123 | |
| 124 | // Combine text and image content |
| 125 | return { |
| 126 | content: [textContent, ...imageContents], |
| 127 | }; |
| 128 | }; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Helper function to create a tool definition with automatic handler creation |
no test coverage detected