@@ -66,7 +66,8 @@ const server = new McpServer(
6666 {
6767 capabilities : {
6868 tools : { } ,
69- resources : { }
69+ resources : { } ,
70+ logging : { }
7071 }
7172 }
7273) ;
@@ -84,6 +85,7 @@ allResources.forEach((resource) => {
8485async function main ( ) {
8586 // Initialize OpenTelemetry tracing if not in test mode
8687 let tracingInitialized = false ;
88+ let tracingError : Error | null = null ;
8789 if ( process . env . NODE_ENV !== 'test' && ! process . env . VITEST ) {
8890 try {
8991 await initializeTracing ( ) ;
@@ -122,14 +124,25 @@ async function main() {
122124 span . end ( ) ;
123125 }
124126 } catch ( error ) {
125- // Tracing initialization failed, log it but continue without tracing
126- server . server . sendLoggingMessage ( {
127- level : 'warning' ,
128- data : `Failed to initialize tracing: ${ error instanceof Error ? error . message : String ( error ) } `
129- } ) ;
127+ // Store the error to log after connection is established
128+ tracingError = error instanceof Error ? error : new Error ( String ( error ) ) ;
130129 }
131130 }
132131
132+ // Start receiving messages on stdin and sending messages on stdout
133+ const transport = new StdioServerTransport ( ) ;
134+ await server . connect ( transport ) ;
135+
136+ // Now that we're connected, send all the logging messages
137+
138+ // Log tracing initialization error if any
139+ if ( tracingError ) {
140+ server . server . sendLoggingMessage ( {
141+ level : 'warning' ,
142+ data : `Failed to initialize tracing: ${ tracingError . message } `
143+ } ) ;
144+ }
145+
133146 // Log tracing status and configuration
134147 if ( tracingInitialized ) {
135148 const tracingConfig = {
@@ -175,10 +188,6 @@ async function main() {
175188 level : 'debug' ,
176189 data : JSON . stringify ( relevantEnvVars , null , 2 )
177190 } ) ;
178-
179- // Start receiving messages on stdin and sending messages on stdout
180- const transport = new StdioServerTransport ( ) ;
181- await server . connect ( transport ) ;
182191}
183192
184193// Ensure cleanup interval is cleared when the process exits
0 commit comments