9
9
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
10
10
} from '../../semanticAttributes' ;
11
11
import { startSpan } from '../../tracing' ;
12
- import { logger } from '../logger' ;
12
+ import { logger } from '../../utils/ logger' ;
13
13
import {
14
14
CLIENT_ADDRESS_ATTRIBUTE ,
15
15
CLIENT_PORT_ATTRIBUTE ,
@@ -30,6 +30,7 @@ import {
30
30
NETWORK_TRANSPORT_ATTRIBUTE ,
31
31
} from './attributes' ;
32
32
import type { ExtraHandlerData , JsonRpcNotification , JsonRpcRequest , McpSpanConfig , MCPTransport , MethodConfig } from './types' ;
33
+ import { isURLObjectRelative , parseStringToURLObject } from '../../utils/url' ;
33
34
34
35
/** Validates if a message is a JSON-RPC request */
35
36
export function isJsonRpcRequest ( message : unknown ) : message is JsonRpcRequest {
@@ -102,17 +103,17 @@ const METHOD_CONFIGS: Record<string, MethodConfig> = {
102
103
} ;
103
104
104
105
/** Extracts target info from method and params based on method type */
105
- function extractTargetInfo ( method : string , params : Record < string , unknown > ) : {
106
- target ?: string ;
107
- attributes : Record < string , string >
106
+ function extractTargetInfo ( method : string , params : Record < string , unknown > ) : {
107
+ target ?: string ;
108
+ attributes : Record < string , string >
108
109
} {
109
110
const config = METHOD_CONFIGS [ method as keyof typeof METHOD_CONFIGS ] ;
110
111
if ( ! config ) {
111
112
return { attributes : { } } ;
112
113
}
113
114
114
- const target = config . targetField && typeof params ?. [ config . targetField ] === 'string'
115
- ? params [ config . targetField ] as string
115
+ const target = config . targetField && typeof params ?. [ config . targetField ] === 'string'
116
+ ? params [ config . targetField ] as string
116
117
: undefined ;
117
118
118
119
return {
@@ -125,7 +126,7 @@ function extractTargetInfo(method: string, params: Record<string, unknown>): {
125
126
function getRequestArguments ( method : string , params : Record < string , unknown > ) : Record < string , string > {
126
127
const args : Record < string , string > = { } ;
127
128
const config = METHOD_CONFIGS [ method as keyof typeof METHOD_CONFIGS ] ;
128
-
129
+
129
130
if ( ! config ) {
130
131
return args ;
131
132
}
@@ -160,13 +161,13 @@ function getTransportTypes(transport: MCPTransport): { mcpTransport: string; net
160
161
if ( transportName . includes ( 'stdio' ) ) {
161
162
return { mcpTransport : 'stdio' , networkTransport : 'pipe' } ;
162
163
}
163
-
164
+
164
165
// Streamable HTTP is the standard HTTP-based transport
165
166
// The official SDK uses 'StreamableHTTPServerTransport' / 'StreamableHTTPClientTransport'
166
167
if ( transportName . includes ( 'streamablehttp' ) || transportName . includes ( 'streamable' ) ) {
167
168
return { mcpTransport : 'http' , networkTransport : 'tcp' } ;
168
169
}
169
-
170
+
170
171
// SSE is the deprecated HTTP+SSE transport (backwards compatibility)
171
172
// Note: Modern Streamable HTTP can use SSE internally, but SSE transport is deprecated
172
173
if ( transportName . includes ( 'sse' ) ) {
@@ -335,7 +336,7 @@ function buildTypeSpecificAttributes(
335
336
if ( type === 'request' ) {
336
337
const request = message as JsonRpcRequest ;
337
338
const targetInfo = extractTargetInfo ( request . method , params || { } ) ;
338
-
339
+
339
340
return {
340
341
...( request . id !== undefined && { [ MCP_REQUEST_ID_ATTRIBUTE ] : String ( request . id ) } ) ,
341
342
...targetInfo . attributes ,
@@ -354,7 +355,7 @@ function buildTypeSpecificAttributes(
354
355
function buildSentryAttributes ( type : McpSpanConfig [ 'type' ] ) : Record < string , string > {
355
356
let op : string ;
356
357
let origin : string ;
357
-
358
+
358
359
switch ( type ) {
359
360
case 'request' :
360
361
op = MCP_SERVER_OP_VALUE ;
@@ -369,7 +370,7 @@ function buildSentryAttributes(type: McpSpanConfig['type']): Record<string, stri
369
370
origin = MCP_NOTIFICATION_ORIGIN_VALUE ;
370
371
break ;
371
372
}
372
-
373
+
373
374
return {
374
375
[ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : op ,
375
376
[ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : origin ,
@@ -432,17 +433,17 @@ export function createMcpOutgoingNotificationSpan(
432
433
/**
433
434
* Combine the two extraction functions into one
434
435
*/
435
- function extractClientInfo ( extra : ExtraHandlerData ) : {
436
- address ?: string ;
437
- port ?: number
436
+ function extractClientInfo ( extra : ExtraHandlerData ) : {
437
+ address ?: string ;
438
+ port ?: number
438
439
} {
439
440
return {
440
441
address : extra ?. requestInfo ?. remoteAddress ||
441
442
extra ?. clientAddress ||
442
443
extra ?. request ?. ip ||
443
444
extra ?. request ?. connection ?. remoteAddress ,
444
- port : extra ?. requestInfo ?. remotePort ||
445
- extra ?. clientPort ||
445
+ port : extra ?. requestInfo ?. remotePort ||
446
+ extra ?. clientPort ||
446
447
extra ?. request ?. connection ?. remotePort
447
448
} ;
448
449
}
0 commit comments