@i18n-agent/mcp-client 1.1.0 → 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 +74 -21
- package/package.json +3 -3
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: {
|
|
@@ -30,8 +32,14 @@ const server = new Server(
|
|
|
30
32
|
);
|
|
31
33
|
|
|
32
34
|
// Configuration
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
if (!process.env.MCP_SERVER_URL) {
|
|
36
|
+
throw new Error('MCP_SERVER_URL environment variable is required');
|
|
37
|
+
}
|
|
38
|
+
if (!process.env.API_KEY) {
|
|
39
|
+
throw new Error('API_KEY environment variable is required');
|
|
40
|
+
}
|
|
41
|
+
const MCP_SERVER_URL = process.env.MCP_SERVER_URL;
|
|
42
|
+
const API_KEY = process.env.API_KEY;
|
|
35
43
|
|
|
36
44
|
// Available tools
|
|
37
45
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
@@ -235,6 +243,7 @@ async function handleTranslateText(args) {
|
|
|
235
243
|
};
|
|
236
244
|
|
|
237
245
|
try {
|
|
246
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_text] Request: ${texts.length} texts, ${totalChars} chars to ${MCP_SERVER_URL}`);
|
|
238
247
|
const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
|
|
239
248
|
headers: {
|
|
240
249
|
'Content-Type': 'application/json',
|
|
@@ -298,7 +307,31 @@ async function handleTranslateText(args) {
|
|
|
298
307
|
]
|
|
299
308
|
};
|
|
300
309
|
}
|
|
301
|
-
|
|
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
|
+
|
|
317
|
+
// Check if it's actually a service unavailable error (503, timeout, connection issues)
|
|
318
|
+
if (error.code === 'ECONNREFUSED' ||
|
|
319
|
+
error.code === 'ETIMEDOUT' ||
|
|
320
|
+
error.response?.status === 503 ||
|
|
321
|
+
error.response?.status === 502 ||
|
|
322
|
+
error.response?.status === 504) {
|
|
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}`);
|
|
330
|
+
}
|
|
331
|
+
|
|
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);
|
|
334
|
+
throw error;
|
|
302
335
|
}
|
|
303
336
|
}
|
|
304
337
|
|
|
@@ -436,6 +469,7 @@ async function handleTranslateFile(args) {
|
|
|
436
469
|
};
|
|
437
470
|
|
|
438
471
|
try {
|
|
472
|
+
console.error(`[MCP v${MCP_CLIENT_VERSION}/STDIO/translate_file] Request: ${content?.length || 0} chars to ${MCP_SERVER_URL}`);
|
|
439
473
|
const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
|
|
440
474
|
headers: {
|
|
441
475
|
'Content-Type': 'application/json',
|
|
@@ -489,7 +523,31 @@ async function handleTranslateFile(args) {
|
|
|
489
523
|
]
|
|
490
524
|
};
|
|
491
525
|
}
|
|
492
|
-
|
|
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
|
+
|
|
533
|
+
// Check if it's actually a service unavailable error
|
|
534
|
+
if (error.code === 'ECONNREFUSED' ||
|
|
535
|
+
error.code === 'ETIMEDOUT' ||
|
|
536
|
+
error.response?.status === 503 ||
|
|
537
|
+
error.response?.status === 502 ||
|
|
538
|
+
error.response?.status === 504) {
|
|
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}`);
|
|
546
|
+
}
|
|
547
|
+
|
|
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);
|
|
550
|
+
throw error;
|
|
493
551
|
}
|
|
494
552
|
}
|
|
495
553
|
|
|
@@ -568,25 +626,20 @@ async function pollTranslationJob(jobId, estimatedTime) {
|
|
|
568
626
|
|
|
569
627
|
async function handleGetCredits(args) {
|
|
570
628
|
try {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
arguments: {
|
|
574
|
-
apiKey: API_KEY,
|
|
575
|
-
}
|
|
576
|
-
}, {
|
|
629
|
+
// Get team info first using the API key
|
|
630
|
+
const teamResponse = await axios.get(`https://platform.i18nagent.ai/api/teams/by-api-key/${API_KEY}`, {
|
|
577
631
|
headers: {
|
|
578
632
|
'Content-Type': 'application/json'
|
|
579
633
|
},
|
|
580
634
|
timeout: 10000
|
|
581
635
|
});
|
|
582
636
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
if (result.isError) {
|
|
586
|
-
throw new Error(result.content[0].text);
|
|
637
|
+
if (!teamResponse.data.success) {
|
|
638
|
+
throw new Error(teamResponse.data.error || 'Failed to get team information');
|
|
587
639
|
}
|
|
588
640
|
|
|
589
|
-
const
|
|
641
|
+
const teamInfo = teamResponse.data.data;
|
|
642
|
+
const approximateWordsAvailable = Math.floor(teamInfo.credits * 1000); // 0.001 credits per word
|
|
590
643
|
|
|
591
644
|
return {
|
|
592
645
|
content: [
|
|
@@ -594,11 +647,11 @@ async function handleGetCredits(args) {
|
|
|
594
647
|
type: 'text',
|
|
595
648
|
text: `💰 **Credits Information**
|
|
596
649
|
|
|
597
|
-
🏢 **Team**: ${
|
|
598
|
-
💳 **Credits Remaining**: ${
|
|
599
|
-
📝 **Approximate Words Available**: ${
|
|
600
|
-
💵 **Cost per Word**:
|
|
601
|
-
⏰ **Last Updated**: ${new Date(
|
|
650
|
+
🏢 **Team**: ${teamInfo.name}
|
|
651
|
+
💳 **Credits Remaining**: ${teamInfo.credits}
|
|
652
|
+
📝 **Approximate Words Available**: ${approximateWordsAvailable.toLocaleString()}
|
|
653
|
+
💵 **Cost per Word**: 0.001 credits
|
|
654
|
+
⏰ **Last Updated**: ${new Date().toLocaleString()}
|
|
602
655
|
|
|
603
656
|
Note: Word count is approximate and may vary based on actual content complexity and translation requirements.`,
|
|
604
657
|
},
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-agent/mcp-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "MCP client for i18n-agent translation service - supports Claude, Cursor, VS Code, and other AI IDEs",
|
|
5
5
|
"main": "mcp-client.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"i18n-agent-install": "
|
|
7
|
+
"i18n-agent-install": "install.js"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
@@ -50,4 +50,4 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|