@@ -15,6 +15,24 @@ import { JsonHTTPServerTransport } from './utils/json-http-transport';
1515import { logger } from './utils/logger' ;
1616import { LinkedApiProgressNotification } from './utils/types' ;
1717
18+ function deriveClientFromUserAgent ( userAgent : string ) : string {
19+ const ua = userAgent . toLowerCase ( ) ;
20+ if ( ua . includes ( 'cursor' ) ) return 'cursor' ;
21+ if ( ua . includes ( 'windsurf' ) ) return 'windsurf' ;
22+ if ( ua . includes ( 'vscode' ) || ua . includes ( 'visual studio code' ) ) return 'vscode' ;
23+ if ( ua . includes ( 'chatgpt' ) || ua . includes ( 'openai' ) ) return 'chatgpt' ;
24+ if ( ua . includes ( 'curl' ) ) return 'curl' ;
25+ if ( ua . includes ( 'postman' ) ) return 'postman' ;
26+ if (
27+ ua . includes ( 'mozilla' ) ||
28+ ua . includes ( 'chrome' ) ||
29+ ua . includes ( 'safari' ) ||
30+ ua . includes ( 'firefox' )
31+ )
32+ return 'browser' ;
33+ return userAgent ;
34+ }
35+
1836function getArgValue ( flag : string ) : string | undefined {
1937 const index = process . argv . indexOf ( flag ) ;
2038 if ( index === - 1 ) return undefined ;
@@ -104,7 +122,13 @@ async function main() {
104122 const identificationToken = ( headers [ 'identification-token' ] ??
105123 localIdentificationToken ??
106124 '' ) as string ;
107- const mcpClient = ( headers [ 'client' ] ?? '' ) as string ;
125+ let mcpClient = ( headers [ 'client' ] ?? '' ) as string ;
126+ if ( ! mcpClient ) {
127+ const userAgentHeader = headers [ 'user-agent' ] ;
128+ if ( typeof userAgentHeader === 'string' && userAgentHeader . trim ( ) . length > 0 ) {
129+ mcpClient = deriveClientFromUserAgent ( userAgentHeader ) ;
130+ }
131+ }
108132
109133 const result = await linkedApiServer . executeWithTokens ( request . params , {
110134 linkedApiToken,
0 commit comments