Skip to content

Commit 4e58410

Browse files
User-agent for timeout
1 parent abb9d4e commit 4e58410

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/index.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ import { JsonHTTPServerTransport } from './utils/json-http-transport';
1515
import { logger } from './utils/logger';
1616
import { 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+
1836
function 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,
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
export function defineRequestTimeoutInSeconds(mcpClient: string): number {
2-
const claudeTimeout = 180;
32
const bigTimeout = 600;
4-
const defaultTimeout = Math.min(claudeTimeout, bigTimeout);
53

4+
console.error('mcpClient', mcpClient);
65
switch (mcpClient) {
76
case 'claude':
8-
return claudeTimeout;
7+
return 180;
8+
case 'chatgpt':
9+
return 50;
910
case 'cursor':
1011
case 'vscode':
1112
case 'windsurf':
1213
return bigTimeout;
1314
default:
14-
return defaultTimeout;
15+
return 60;
1516
}
1617
}

0 commit comments

Comments
 (0)