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

Function withLogging

src/mcpTools.ts:73–98  ·  view source on GitHub ↗

* Wraps a tool function with entry/exit logging

(
  toolName: string,
  extras: RequestHandlerExtra<ServerRequest, ServerNotification>,
  toolFn: (client: DocumentEngineClient, params: T) => Promise<R>,
  server: McpServer,
  client: DocumentEngineClient,
  params: T
)

Source from the content-addressed store, hash-verified

71 * Wraps a tool function with entry/exit logging
72 */
73async function withLogging<T, R>(
74 toolName: string,
75 extras: RequestHandlerExtra<ServerRequest, ServerNotification>,
76 toolFn: (client: DocumentEngineClient, params: T) => Promise<R>,
77 server: McpServer,
78 client: DocumentEngineClient,
79 params: T
80): Promise<R> {
81 let messagePrefix = `[${toolName}]`;
82 if (extras.sessionId) messagePrefix += `[s=${extras.sessionId}]`;
83 if (extras.requestId) messagePrefix += `[r=${extras.requestId}]`;
84
85 logger.info(server, `${messagePrefix} START`, params);
86
87 try {
88 const result = await toolFn(client, params);
89 logger.debug(server, `${messagePrefix} END`, result);
90 logger.info(server, `${messagePrefix} END`);
91 return result;
92 } catch (error) {
93 logger.error(server, `${messagePrefix} END`, {
94 error: error instanceof Error ? error.message : String(error),
95 });
96 throw error;
97 }
98}
99
100/**
101 * Creates a tool handler with automatic logging

Callers 1

createToolHandlerFunction · 0.85

Calls 3

infoMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected