Skip to content

Commit 97990c6

Browse files
committed
use parseStringToURLObject for url handling and update test
1 parent 7b5fd86 commit 97990c6

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

packages/core/src/integrations/mcp-server/utils.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,9 @@ function getNotificationAttributes(
236236
if (params?.uri) {
237237
attributes['mcp.resource.uri'] = String(params.uri);
238238
// Extract protocol from URI
239-
try {
240-
const url = new URL(String(params.uri));
241-
attributes['mcp.resource.protocol'] = url.protocol;
242-
} catch {
243-
// Ignore invalid URIs
239+
const urlObject = parseStringToURLObject(String(params.uri));
240+
if (urlObject && !isURLObjectRelative(urlObject)) {
241+
attributes['mcp.resource.protocol'] = urlObject.protocol.replace(':', '');
244242
}
245243
}
246244
break;

packages/core/test/lib/mcp-server.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest';
2-
import { wrapMcpServerWithSentry } from '../../src/mcp-server';
2+
import { wrapMcpServerWithSentry } from '../../src/integrations/mcp-server';
33
import * as tracingModule from '../../src/tracing';
44

55
describe('wrapMcpServerWithSentry', () => {
@@ -497,7 +497,7 @@ describe('wrapMcpServerWithSentry', () => {
497497
attributes: expect.objectContaining({
498498
'mcp.method.name': 'notifications/resources/updated',
499499
'mcp.resource.uri': 'file:///tmp/data.json',
500-
'mcp.resource.protocol': 'file:',
500+
'mcp.resource.protocol': 'file',
501501
'sentry.op': 'mcp.notification.client_to_server',
502502
'sentry.origin': 'auto.mcp.notification',
503503
'sentry.source': 'route',
@@ -671,7 +671,7 @@ function createMockTransport() {
671671
send = vi.fn().mockResolvedValue(undefined);
672672
sessionId = 'test-session-123';
673673
}
674-
674+
675675
return new StreamableHTTPServerTransport();
676676
}
677677

@@ -684,7 +684,7 @@ function createMockStdioTransport() {
684684
send = vi.fn().mockResolvedValue(undefined);
685685
sessionId = 'stdio-session-456';
686686
}
687-
687+
688688
return new StdioServerTransport();
689689
}
690690

@@ -697,6 +697,6 @@ function createMockSseTransport() {
697697
send = vi.fn().mockResolvedValue(undefined);
698698
sessionId = 'sse-session-789';
699699
}
700-
700+
701701
return new SSEServerTransport();
702702
}

0 commit comments

Comments
 (0)