@@ -147,6 +147,11 @@ export class StatelessHttpTransport extends BaseTransport {
147147 // Check HF token validity if present
148148 const headers = req . headers as Record < string , string > ;
149149 extractQueryParamsToHeaders ( req , headers ) ;
150+
151+ // Extract IP address for tracking
152+ const ipAddress = this . extractIpAddress ( req . headers , req . ip ) ;
153+ this . trackIpAddress ( ipAddress ) ;
154+
150155 // Extract method name for tracking using shared utility
151156 const requestBody = req . body as
152157 | { method ?: string ; params ?: { clientInfo ?: unknown ; capabilities ?: unknown ; name ?: string } }
@@ -168,7 +173,7 @@ export class StatelessHttpTransport extends BaseTransport {
168173 if ( requestBody ?. method === 'initialize' ) {
169174 // Create new session
170175 sessionId = randomUUID ( ) ;
171- this . createAnalyticsSession ( sessionId , authResult . userIdentified ) ;
176+ this . createAnalyticsSession ( sessionId , authResult . userIdentified , ipAddress ) ;
172177
173178 // Add session ID to response headers
174179 res . setHeader ( 'Mcp-Session-Id' , sessionId ) ;
@@ -182,6 +187,7 @@ export class StatelessHttpTransport extends BaseTransport {
182187 clientVersion : initClientInfo ?. version ,
183188 requestJson : requestBody . params || '{}' ,
184189 capabilities : requestBody ?. params ?. capabilities ,
190+ ipAddress,
185191 } ) ;
186192 } else if ( sessionId ) {
187193 // Try to resume existing session
@@ -441,6 +447,7 @@ export class StatelessHttpTransport extends BaseTransport {
441447 clientName : analyticsSession ?. metadata . clientInfo ?. name ,
442448 clientVersion : analyticsSession ?. metadata . clientInfo ?. version ,
443449 requestJson : { method : 'session_delete' , sessionId } ,
450+ ipAddress : analyticsSession ?. metadata . ipAddress ,
444451 } ) ;
445452
446453 res . status ( 200 ) . json ( { jsonrpc : '2.0' , result : { deleted : true } } ) ;
@@ -492,7 +499,7 @@ export class StatelessHttpTransport extends BaseTransport {
492499 }
493500
494501 // Analytics mode methods
495- private createAnalyticsSession ( sessionId : string , isAuthenticated : boolean ) : void {
502+ private createAnalyticsSession ( sessionId : string , isAuthenticated : boolean , ipAddress ?: string ) : void {
496503 const session : AnalyticsSession = {
497504 transport : null ,
498505 server : null , // Server is null in analytics mode
@@ -503,6 +510,7 @@ export class StatelessHttpTransport extends BaseTransport {
503510 requestCount : 1 ,
504511 isAuthenticated,
505512 capabilities : { } ,
513+ ipAddress,
506514 } ,
507515 } ;
508516
0 commit comments