@telemetry-dev/mcp 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +29 -18
- package/package.json +4 -4
- package/src/index.ts +29 -24
package/dist/index.mjs
CHANGED
|
@@ -188,13 +188,17 @@ function instrumentMcpTransport(transport, options = {}) {
|
|
|
188
188
|
const originalSetProtocolVersion = target.setProtocolVersion?.bind(target);
|
|
189
189
|
const outgoing = /* @__PURE__ */ new Map();
|
|
190
190
|
const incoming = /* @__PURE__ */ new Map();
|
|
191
|
+
const sendingResponses = /* @__PURE__ */ new Set();
|
|
191
192
|
const dispatching = /* @__PURE__ */ new WeakSet();
|
|
192
193
|
const capturePayloads = options.capturePayloads === true;
|
|
193
194
|
const propagateBaggage = options.propagateBaggage === true;
|
|
194
195
|
let onmessage = target.onmessage;
|
|
195
196
|
const wrapClose = (handler) => function() {
|
|
196
197
|
for (const [key, pending] of outgoing) completePending(outgoing, key, pending, () => setFailure(pending, "connection_error"));
|
|
197
|
-
for (const [key, pending] of incoming)
|
|
198
|
+
for (const [key, pending] of incoming) {
|
|
199
|
+
if (sendingResponses.has(pending)) continue;
|
|
200
|
+
completePending(incoming, key, pending, () => setFailure(pending, "connection_error"));
|
|
201
|
+
}
|
|
198
202
|
handler?.call(target);
|
|
199
203
|
};
|
|
200
204
|
let onclose = wrapClose(target.onclose);
|
|
@@ -296,26 +300,33 @@ function instrumentMcpTransport(transport, options = {}) {
|
|
|
296
300
|
}
|
|
297
301
|
}
|
|
298
302
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
303
|
+
const responses = [];
|
|
304
|
+
for (const message of messages) {
|
|
305
|
+
if (message === void 0 || message.method !== void 0 || message.id === void 0) continue;
|
|
306
|
+
const key = idKey(message.id);
|
|
307
|
+
const pending = incoming.get(key);
|
|
308
|
+
if (pending === void 0 || sendingResponses.has(pending)) continue;
|
|
309
|
+
sendingResponses.add(pending);
|
|
310
|
+
responses.push({
|
|
311
|
+
key,
|
|
312
|
+
pending,
|
|
313
|
+
message
|
|
314
|
+
});
|
|
310
315
|
}
|
|
311
316
|
try {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
+
try {
|
|
318
|
+
await originalSend(sent, forwardedOptions);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
for (const { key, pending } of started) completePending(outgoing, key, pending, () => pending.handle.update({ error }));
|
|
321
|
+
for (const { key, pending } of responses) completePending(incoming, key, pending, () => pending.handle.update({ error }));
|
|
322
|
+
throw error;
|
|
317
323
|
}
|
|
318
|
-
|
|
324
|
+
try {
|
|
325
|
+
for (const { key, pending, message } of responses) completePending(incoming, key, pending, () => finishResponse(target, pending, message));
|
|
326
|
+
} catch {}
|
|
327
|
+
} finally {
|
|
328
|
+
for (const { pending } of responses) sendingResponses.delete(pending);
|
|
329
|
+
}
|
|
319
330
|
};
|
|
320
331
|
if (originalSetProtocolVersion !== void 0) target.setProtocolVersion = (version) => {
|
|
321
332
|
PROTOCOL_VERSIONS.set(target, version);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemetry-dev/mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Model Context Protocol SDK instrumentation for telemetry.dev: instruments MCP v2 transports and emits OpenTelemetry spans.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -38,17 +38,17 @@
|
|
|
38
38
|
"@modelcontextprotocol/server": "2.0.0",
|
|
39
39
|
"@opentelemetry/api": "^1.9.1",
|
|
40
40
|
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
41
|
+
"@telemetry-dev/sdk": "0.1.2",
|
|
41
42
|
"@types/node": "^24",
|
|
42
43
|
"typescript": "^5",
|
|
43
44
|
"vite-plus": "0.1.20",
|
|
44
|
-
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.20"
|
|
45
|
-
"@telemetry-dev/sdk": "0.1.0"
|
|
45
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.20"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@modelcontextprotocol/client": ">=2.0.0 <3",
|
|
49
49
|
"@modelcontextprotocol/server": ">=2.0.0 <3",
|
|
50
50
|
"@opentelemetry/api": ">=1.9.0 <2",
|
|
51
|
-
"@telemetry-dev/sdk": "^0.1.
|
|
51
|
+
"@telemetry-dev/sdk": "^0.1.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"@modelcontextprotocol/client": {
|
package/src/index.ts
CHANGED
|
@@ -328,6 +328,7 @@ export function instrumentMcpTransport<T extends McpTransport>(
|
|
|
328
328
|
const originalSetProtocolVersion = target.setProtocolVersion?.bind(target);
|
|
329
329
|
const outgoing = new Map<string, PendingRequest>();
|
|
330
330
|
const incoming = new Map<string, PendingRequest>();
|
|
331
|
+
const sendingResponses = new Set<PendingRequest>();
|
|
331
332
|
const dispatching = new WeakSet<object>();
|
|
332
333
|
const capturePayloads = options.capturePayloads === true;
|
|
333
334
|
const propagateBaggage = options.propagateBaggage === true;
|
|
@@ -338,6 +339,7 @@ export function instrumentMcpTransport<T extends McpTransport>(
|
|
|
338
339
|
completePending(outgoing, key, pending, () => setFailure(pending, "connection_error"));
|
|
339
340
|
}
|
|
340
341
|
for (const [key, pending] of incoming) {
|
|
342
|
+
if (sendingResponses.has(pending)) continue;
|
|
341
343
|
completePending(incoming, key, pending, () => setFailure(pending, "connection_error"));
|
|
342
344
|
}
|
|
343
345
|
handler?.call(target);
|
|
@@ -472,35 +474,38 @@ export function instrumentMcpTransport<T extends McpTransport>(
|
|
|
472
474
|
}
|
|
473
475
|
}
|
|
474
476
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const key = idKey(message.id);
|
|
485
|
-
const inbound = incoming.get(key);
|
|
486
|
-
if (inbound !== undefined) {
|
|
487
|
-
completePending(incoming, key, inbound, () => inbound.handle.update({ error }));
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
throw error;
|
|
477
|
+
const responses: Array<{ key: string; pending: PendingRequest; message: ParsedMessage }> = [];
|
|
478
|
+
for (const message of messages) {
|
|
479
|
+
if (message === undefined || message.method !== undefined || message.id === undefined)
|
|
480
|
+
continue;
|
|
481
|
+
const key = idKey(message.id);
|
|
482
|
+
const pending = incoming.get(key);
|
|
483
|
+
if (pending === undefined || sendingResponses.has(pending)) continue;
|
|
484
|
+
sendingResponses.add(pending);
|
|
485
|
+
responses.push({ key, pending, message });
|
|
491
486
|
}
|
|
492
487
|
|
|
493
488
|
try {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const key
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
489
|
+
try {
|
|
490
|
+
await originalSend(sent, forwardedOptions);
|
|
491
|
+
} catch (error) {
|
|
492
|
+
for (const { key, pending } of started) {
|
|
493
|
+
completePending(outgoing, key, pending, () => pending.handle.update({ error }));
|
|
494
|
+
}
|
|
495
|
+
for (const { key, pending } of responses) {
|
|
496
|
+
completePending(incoming, key, pending, () => pending.handle.update({ error }));
|
|
501
497
|
}
|
|
498
|
+
throw error;
|
|
502
499
|
}
|
|
503
|
-
|
|
500
|
+
|
|
501
|
+
try {
|
|
502
|
+
for (const { key, pending, message } of responses) {
|
|
503
|
+
completePending(incoming, key, pending, () => finishResponse(target, pending, message));
|
|
504
|
+
}
|
|
505
|
+
} catch {}
|
|
506
|
+
} finally {
|
|
507
|
+
for (const { pending } of responses) sendingResponses.delete(pending);
|
|
508
|
+
}
|
|
504
509
|
};
|
|
505
510
|
|
|
506
511
|
if (originalSetProtocolVersion !== undefined) {
|