Skip to content

Commit 659b17b

Browse files
committed
add logging
1 parent 1ea679c commit 659b17b

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

server.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"url": "https://github.com/mapbox/mcp-server",
77
"source": "github"
88
},
9-
"version": "0.7.0",
9+
"version": "0.7.1",
1010
"packages": [
1111
{
1212
"registryType": "npm",
1313
"registryBaseUrl": "https://registry.npmjs.org",
1414
"runtimeHint": "npx",
15-
"version": "0.7.0",
15+
"version": "0.7.1",
1616
"identifier": "@mapbox/mcp-server",
1717
"transport": {
1818
"type": "stdio"

src/index.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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) => {
8485
async 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

Comments
 (0)