MCPcopy Create free account
hub / github.com/PSPDFKit/nutrient-document-engine-mcp-server / createToolHandler

Function createToolHandler

src/mcpTools.ts:103–129  ·  view source on GitHub ↗

* Creates a tool handler with automatic logging

(
  toolFn: (client: DocumentEngineClient, params: TParams) => Promise<MCPToolOutput>
)

Source from the content-addressed store, hash-verified

101 * Creates a tool handler with automatic logging
102 */
103function 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

Callers 1

createToolFunction · 0.85

Calls 1

withLoggingFunction · 0.85

Tested by

no test coverage detected