Skip to content
Open
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
29 changes: 19 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const server = new McpServer(
{
capabilities: {
tools: {},
resources: {}
resources: {},
logging: {}
}
}
);
Expand All @@ -84,6 +85,7 @@ allResources.forEach((resource) => {
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 @@ -122,14 +124,25 @@ 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 initialization error if any
if (tracingError) {
server.server.sendLoggingMessage({
level: 'warning',
data: `Failed to initialize tracing: ${tracingError.message}`
});
}

// Log tracing status and configuration
if (tracingInitialized) {
const tracingConfig = {
Expand Down Expand Up @@ -175,10 +188,6 @@ async function main() {
level: 'debug',
data: JSON.stringify(relevantEnvVars, null, 2)
});

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

// Ensure cleanup interval is cleared when the process exits
Expand Down