Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const server = new McpServer(
listChanged: true // Advertise support for dynamic tool registration (ready for future capability-dependent tools)
},
resources: {},
prompts: {}
prompts: {},
logging: {}
}
}
);
Expand Down Expand Up @@ -181,6 +182,7 @@ server.server.setRequestHandler(ListPromptsRequestSchema, async () => {
async function main() {
// Initialize OpenTelemetry tracing if not in test mode
let tracingInitialized = false;
let tracingError: Error | null = null;
if (process.env.NODE_ENV !== 'test' && !process.env.VITEST) {
try {
await initializeTracing();
Expand Down Expand Up @@ -219,16 +221,24 @@ async function main() {
span.end();
}
} catch (error) {
// Tracing initialization failed, log it but continue without tracing
server.server.sendLoggingMessage({
level: 'warning',
data: `Failed to initialize tracing: ${error instanceof Error ? error.message : String(error)}`
});
// Store the error to log after connection is established
tracingError = error instanceof Error ? error : new Error(String(error));
}
}

// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
await server.connect(transport);

// Now that we're connected, send all the logging messages

// Log tracing status and configuration
if (tracingInitialized) {
if (tracingError) {
server.server.sendLoggingMessage({
level: 'warning',
data: `Failed to initialize tracing: ${tracingError.message}`
});
} else if (tracingInitialized) {
const tracingConfig = {
status: 'enabled',
endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'not set',
Expand Down Expand Up @@ -273,10 +283,6 @@ async function main() {
data: JSON.stringify(relevantEnvVars, null, 2)
});

// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
await server.connect(transport);

// After connection, dynamically register capability-dependent tools
const clientCapabilities = server.server.getClientCapabilities();

Expand Down
Loading