* 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 )
| 71 | * Wraps a tool function with entry/exit logging |
| 72 | */ |
| 73 | async 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 |
no test coverage detected