@@ -45,25 +45,16 @@ import type {
4545 * @returns Transport type mapping for span attributes
4646 */
4747export function getTransportTypes ( transport : MCPTransport ) : { mcpTransport : string ; networkTransport : string } {
48- // Handle undefined transport gracefully while preserving type detection
4948 if ( ! transport ?. constructor ) {
5049 return { mcpTransport : 'unknown' , networkTransport : 'unknown' } ;
5150 }
52- const transportName = transport . constructor . name ?. toLowerCase ( ) || '' ;
51+ const transportName = transport . constructor . name ?. toLowerCase ( ) || 'unknown' ;
52+ const networkTransport = transportName === 'stdio' ? 'pipe' : 'tcp' ;
5353
54- if ( transportName . includes ( 'stdio' ) ) {
55- return { mcpTransport : 'stdio' , networkTransport : 'pipe' } ;
56- }
57-
58- if ( transportName . includes ( 'streamablehttp' ) || transportName . includes ( 'streamable' ) ) {
59- return { mcpTransport : 'http' , networkTransport : 'tcp' } ;
60- }
61-
62- if ( transportName . includes ( 'sse' ) ) {
63- return { mcpTransport : 'sse' , networkTransport : 'tcp' } ;
64- }
65-
66- return { mcpTransport : 'unknown' , networkTransport : 'unknown' } ;
54+ return {
55+ mcpTransport : transportName ,
56+ networkTransport,
57+ } ;
6758}
6859
6960/**
@@ -264,17 +255,13 @@ export function extractClientInfo(extra: ExtraHandlerData): {
264255 * @param transport - MCP transport instance
265256 * @param extra - Optional extra handler data
266257 * @returns Transport attributes for span instrumentation
258+ * @note sessionId may be undefined during initial setup - session should be established by client during initialize flow
267259 */
268260export function buildTransportAttributes (
269261 transport : MCPTransport ,
270262 extra ?: ExtraHandlerData ,
271263) : Record < string , string | number > {
272- // Gracefully handle undefined sessionId during MCP initialization
273- // Respects client-provided sessions and waits for proper session establishment
274264 const sessionId = transport && 'sessionId' in transport ? transport . sessionId : undefined ;
275-
276- // Note: sessionId may be undefined during initial setup - this is expected behavior
277- // The actual session should be established by the client during the initialize flow
278265 const clientInfo = extra ? extractClientInfo ( extra ) : { } ;
279266 const { mcpTransport, networkTransport } = getTransportTypes ( transport ) ;
280267 const clientAttributes = getClientAttributes ( transport ) ;
0 commit comments