@@ -23,7 +23,10 @@ if (process.env.NODE_ENV !== 'test') {
2323 try {
2424 validateEnvironment ( ) ;
2525 } catch ( error ) {
26- console . error ( 'Environment validation failed:' , error instanceof Error ? error . message : error ) ;
26+ logger . error (
27+ null ,
28+ `Environment validation failed: ${ error instanceof Error ? error . message : error } `
29+ ) ;
2730 process . exit ( 1 ) ;
2831 }
2932}
@@ -41,29 +44,32 @@ async function waitForDocumentEngine(): Promise<DocumentEngineClient> {
4144 while ( attempts < maxRetries ) {
4245 try {
4346 logger . info (
47+ null ,
4448 `Attempting to connect to Document Engine (attempt ${ attempts + 1 } /${ maxRetries } )`
4549 ) ;
4650 const client = await getDocumentEngineClient ( ) ;
4751
4852 // Test the connection with a health check
4953 await client . get ( '/healthcheck' ) ;
5054
51- logger . info ( 'Document Engine is ready! Connection established successfully.' ) ;
55+ logger . info ( null , 'Document Engine is ready! Connection established successfully.' ) ;
5256 return client ;
5357 } catch ( error ) {
5458 attempts ++ ;
5559 const errorMessage = error instanceof Error ? error . message : String ( error ) ;
5660
5761 if ( attempts >= maxRetries ) {
5862 logger . error (
63+ null ,
5964 `Failed to connect to Document Engine after ${ maxRetries } attempts. Last error: ${ errorMessage } `
6065 ) ;
6166 throw new Error (
6267 `Document Engine connection failed after ${ maxRetries } attempts: ${ errorMessage } `
6368 ) ;
6469 }
6570
66- logger . warn (
71+ logger . warning (
72+ null ,
6773 `Document Engine not ready yet (attempt ${ attempts } /${ maxRetries } ): ${ errorMessage } . Retrying in ${ retryDelay } ms...`
6874 ) ;
6975 await new Promise ( resolve => setTimeout ( resolve , retryDelay ) ) ;
@@ -97,7 +103,7 @@ function createMCPServer(): McpServer {
97103
98104function configureMCPServerTools ( server : McpServer ) : void {
99105 for ( const tool of mcpToolsToRegister ) {
100- server . tool ( tool . name , tool . schema , ( args , extra ) => tool . handler ( client , args , extra ) ) ;
106+ server . tool ( tool . name , tool . schema , ( args , extra ) => tool . handler ( server , client , args , extra ) ) ;
101107 }
102108}
103109
@@ -127,7 +133,7 @@ function createExpressApp(enableDashboard: boolean = false): express.Application
127133 } ) ;
128134 }
129135 } catch ( error ) {
130- logger . error ( 'Health check endpoint error' , { error } ) ;
136+ logger . error ( null , 'Health check endpoint error' , { error } ) ;
131137 res . status ( 500 ) . json ( {
132138 status : 'error' ,
133139 message : error instanceof Error ? error . message : 'Unknown error' ,
@@ -153,7 +159,10 @@ async function startStdioServer() {
153159
154160 // Start HTTP server for dashboard
155161 app . listen ( env . PORT , env . MCP_HOST , ( ) => {
156- logger . info ( `Dashboard server running on HTTP at ${ env . MCP_HOST } :${ env . PORT } /dashboard` ) ;
162+ logger . info (
163+ null ,
164+ `Dashboard server running on HTTP at ${ env . MCP_HOST } :${ env . PORT } /dashboard`
165+ ) ;
157166 } ) ;
158167 }
159168
@@ -168,8 +177,7 @@ async function startStdioServer() {
168177 } ) ;
169178
170179 await server . connect ( transport ) ;
171- logger . setMCPServer ( server ) ;
172- logger . info ( `Nutrient Document Engine MCP server ${ getVersion ( ) } running on stdio` ) ;
180+ logger . info ( null , `Nutrient Document Engine MCP server ${ getVersion ( ) } running on stdio` ) ;
173181}
174182
175183async function startHttpServer ( ) {
@@ -204,12 +212,14 @@ async function startHttpServer() {
204212 transport . onclose = ( ) => {
205213 if ( transport . sessionId ) {
206214 delete transports [ transport . sessionId ] ;
215+ logger . info ( null , `Close Session : ${ transport . sessionId } ` ) ;
207216 }
208217 } ;
209218
210219 const server = createMCPServer ( ) ;
211220 await server . connect ( transport ) ;
212- logger . setMCPServer ( server ) ;
221+
222+ logger . info ( null , `Open Session : ${ transport . sessionId } ` ) ;
213223 } else {
214224 // Invalid request
215225 res . status ( 400 ) . json ( {
@@ -226,7 +236,7 @@ async function startHttpServer() {
226236 // Handle the request
227237 await transport . handleRequest ( req , res , req . body ) ;
228238 } catch ( error ) {
229- logger . error ( 'Error handling MCP request:' , error ) ;
239+ logger . error ( null , 'Error handling MCP request:' , error ) ;
230240 if ( ! res . headersSent ) {
231241 res . status ( 500 ) . json ( {
232242 jsonrpc : '2.0' ,
@@ -265,10 +275,14 @@ async function startHttpServer() {
265275
266276 app . listen ( env . PORT , env . MCP_HOST , ( ) => {
267277 logger . info (
278+ null ,
268279 `Nutrient Document Engine MCP server ${ getVersion ( ) } running on HTTP at ${ env . MCP_HOST } :${ env . PORT } /mcp`
269280 ) ;
270281 if ( dashboardEnabled ) {
271- logger . info ( `Dashboard server running on HTTP at ${ env . MCP_HOST } :${ env . PORT } /dashboard` ) ;
282+ logger . info (
283+ null ,
284+ `Dashboard server running on HTTP at ${ env . MCP_HOST } :${ env . PORT } /dashboard`
285+ ) ;
272286 }
273287 } ) ;
274288}
@@ -284,6 +298,6 @@ async function main() {
284298}
285299
286300main ( ) . catch ( error => {
287- logger . error ( 'Failed to start server' , { error : error . message , stack : error . stack } ) ;
301+ logger . error ( null , 'Failed to start server' , { error : error . message , stack : error . stack } ) ;
288302 process . exit ( 1 ) ;
289303} ) ;
0 commit comments