@i18n-agent/mcp-client 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mcp-client.js +35 -5
- package/package.json +1 -1
package/mcp-client.js
CHANGED
|
@@ -17,10 +17,12 @@ import axios from 'axios';
|
|
|
17
17
|
import fs from 'fs';
|
|
18
18
|
import path from 'path';
|
|
19
19
|
|
|
20
|
+
const MCP_CLIENT_VERSION = '1.1.2';
|
|
21
|
+
|
|
20
22
|
const server = new Server(
|
|
21
23
|
{
|
|
22
24
|
name: 'i18n-agent',
|
|
23
|
-
version:
|
|
25
|
+
version: MCP_CLIENT_VERSION,
|
|
24
26
|
},
|
|
25
27
|
{
|
|
26
28
|
capabilities: {
|
|
@@ -241,6 +243,7 @@ async function handleTranslateText(args) {
|
|
|
241
243
|
};
|
|
242
244
|
|
|
243
245
|
try {
|
|
246
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_text] Request: ${texts.length} texts, ${totalChars} chars to ${MCP_SERVER_URL}`);
|
|
244
247
|
const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
|
|
245
248
|
headers: {
|
|
246
249
|
'Content-Type': 'application/json',
|
|
@@ -305,16 +308,29 @@ async function handleTranslateText(args) {
|
|
|
305
308
|
};
|
|
306
309
|
}
|
|
307
310
|
|
|
311
|
+
// Check for payment required error
|
|
312
|
+
if (error.response?.status === 402) {
|
|
313
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_text] Payment required (402)`);
|
|
314
|
+
throw new Error(`⚠️ Insufficient credits. Please top up at https://app.i18nagent.ai [MCP v${MCP_CLIENT_VERSION}/STDIO]`);
|
|
315
|
+
}
|
|
316
|
+
|
|
308
317
|
// Check if it's actually a service unavailable error (503, timeout, connection issues)
|
|
309
318
|
if (error.code === 'ECONNREFUSED' ||
|
|
310
319
|
error.code === 'ETIMEDOUT' ||
|
|
311
320
|
error.response?.status === 503 ||
|
|
312
321
|
error.response?.status === 502 ||
|
|
313
322
|
error.response?.status === 504) {
|
|
314
|
-
|
|
323
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_text] Infrastructure error:`, {
|
|
324
|
+
code: error.code,
|
|
325
|
+
status: error.response?.status,
|
|
326
|
+
message: error.message,
|
|
327
|
+
url: MCP_SERVER_URL
|
|
328
|
+
});
|
|
329
|
+
throw new Error(`Translation service unavailable [MCP v${MCP_CLIENT_VERSION}/STDIO/translate_text]: ${error.message}`);
|
|
315
330
|
}
|
|
316
331
|
|
|
317
|
-
// For other errors (401,
|
|
332
|
+
// For other errors (401, 404, etc), add context but don't mark as unavailable
|
|
333
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_text] Error:`, error.message);
|
|
318
334
|
throw error;
|
|
319
335
|
}
|
|
320
336
|
}
|
|
@@ -453,6 +469,7 @@ async function handleTranslateFile(args) {
|
|
|
453
469
|
};
|
|
454
470
|
|
|
455
471
|
try {
|
|
472
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_file] Request: ${content?.length || 0} chars to ${MCP_SERVER_URL}`);
|
|
456
473
|
const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
|
|
457
474
|
headers: {
|
|
458
475
|
'Content-Type': 'application/json',
|
|
@@ -507,16 +524,29 @@ async function handleTranslateFile(args) {
|
|
|
507
524
|
};
|
|
508
525
|
}
|
|
509
526
|
|
|
527
|
+
// Check for payment required error
|
|
528
|
+
if (error.response?.status === 402) {
|
|
529
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_file] Payment required (402)`);
|
|
530
|
+
throw new Error(`⚠️ Insufficient credits. Please top up at https://app.i18nagent.ai [MCP v${MCP_CLIENT_VERSION}/STDIO]`);
|
|
531
|
+
}
|
|
532
|
+
|
|
510
533
|
// Check if it's actually a service unavailable error
|
|
511
534
|
if (error.code === 'ECONNREFUSED' ||
|
|
512
535
|
error.code === 'ETIMEDOUT' ||
|
|
513
536
|
error.response?.status === 503 ||
|
|
514
537
|
error.response?.status === 502 ||
|
|
515
538
|
error.response?.status === 504) {
|
|
516
|
-
|
|
539
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_file] Infrastructure error:`, {
|
|
540
|
+
code: error.code,
|
|
541
|
+
status: error.response?.status,
|
|
542
|
+
message: error.message,
|
|
543
|
+
url: MCP_SERVER_URL
|
|
544
|
+
});
|
|
545
|
+
throw new Error(`Translation service unavailable [MCP v${MCP_CLIENT_VERSION}/STDIO/translate_file]: ${error.message}`);
|
|
517
546
|
}
|
|
518
547
|
|
|
519
|
-
// For other errors,
|
|
548
|
+
// For other errors, add context but don't mark as unavailable
|
|
549
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_file] Error:`, error.message);
|
|
520
550
|
throw error;
|
|
521
551
|
}
|
|
522
552
|
}
|
package/package.json
CHANGED