@i18n-agent/mcp-client 1.7.6 → 1.7.7
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 +101 -27
- package/package.json +1 -1
package/mcp-client.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Integrates with Claude Code CLI to provide translation capabilities
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const MCP_CLIENT_VERSION = '1.7.
|
|
8
|
+
const MCP_CLIENT_VERSION = '1.7.7';
|
|
9
9
|
|
|
10
10
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
11
11
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
@@ -218,6 +218,20 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
218
218
|
required: ['jobId'],
|
|
219
219
|
},
|
|
220
220
|
},
|
|
221
|
+
{
|
|
222
|
+
name: 'resume_translation',
|
|
223
|
+
description: 'Resume a failed or interrupted async translation job from its last checkpoint. This allows you to continue processing from where it stopped instead of starting over.',
|
|
224
|
+
inputSchema: {
|
|
225
|
+
type: 'object',
|
|
226
|
+
properties: {
|
|
227
|
+
jobId: {
|
|
228
|
+
type: 'string',
|
|
229
|
+
description: 'The job ID of the translation job to resume',
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
required: ['jobId'],
|
|
233
|
+
},
|
|
234
|
+
},
|
|
221
235
|
],
|
|
222
236
|
};
|
|
223
237
|
});
|
|
@@ -248,7 +262,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
248
262
|
|
|
249
263
|
case 'check_translation_status':
|
|
250
264
|
return await handleCheckTranslationStatus(args);
|
|
251
|
-
|
|
265
|
+
|
|
266
|
+
case 'resume_translation':
|
|
267
|
+
return await handleResumeTranslation(args);
|
|
268
|
+
|
|
252
269
|
default:
|
|
253
270
|
throw new McpError(
|
|
254
271
|
ErrorCode.MethodNotFound,
|
|
@@ -630,7 +647,26 @@ async function handleTranslateFile(args) {
|
|
|
630
647
|
|
|
631
648
|
// Check if this is a large file that might need async processing
|
|
632
649
|
const isLargeFile = content.length > 50000; // > 50KB
|
|
633
|
-
|
|
650
|
+
|
|
651
|
+
// Build arguments object, filtering out undefined values (they get stripped by JSON.stringify)
|
|
652
|
+
const requestArgs = {
|
|
653
|
+
apiKey: API_KEY,
|
|
654
|
+
filePath,
|
|
655
|
+
fileContent: content,
|
|
656
|
+
fileType,
|
|
657
|
+
sourceLanguage,
|
|
658
|
+
targetAudience,
|
|
659
|
+
industry,
|
|
660
|
+
preserveKeys,
|
|
661
|
+
outputFormat
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
// Add optional parameters only if defined
|
|
665
|
+
if (targetLanguage !== undefined) requestArgs.targetLanguage = targetLanguage;
|
|
666
|
+
if (targetLanguages !== undefined) requestArgs.targetLanguages = targetLanguages;
|
|
667
|
+
if (region !== undefined) requestArgs.region = region;
|
|
668
|
+
if (context !== undefined) requestArgs.context = context;
|
|
669
|
+
|
|
634
670
|
// Use MCP JSON-RPC protocol for translate_file
|
|
635
671
|
const mcpRequest = {
|
|
636
672
|
jsonrpc: '2.0',
|
|
@@ -638,21 +674,7 @@ async function handleTranslateFile(args) {
|
|
|
638
674
|
method: 'tools/call',
|
|
639
675
|
params: {
|
|
640
676
|
name: 'translate_file',
|
|
641
|
-
arguments:
|
|
642
|
-
apiKey: API_KEY,
|
|
643
|
-
filePath,
|
|
644
|
-
fileContent: content,
|
|
645
|
-
fileType,
|
|
646
|
-
targetLanguage,
|
|
647
|
-
targetLanguages,
|
|
648
|
-
sourceLanguage,
|
|
649
|
-
targetAudience,
|
|
650
|
-
industry,
|
|
651
|
-
region,
|
|
652
|
-
context,
|
|
653
|
-
preserveKeys,
|
|
654
|
-
outputFormat
|
|
655
|
-
}
|
|
677
|
+
arguments: requestArgs
|
|
656
678
|
}
|
|
657
679
|
};
|
|
658
680
|
|
|
@@ -1315,11 +1337,11 @@ function getCodeBlockLanguage(fileType) {
|
|
|
1315
1337
|
// Handler for checking translation status
|
|
1316
1338
|
async function handleCheckTranslationStatus(args) {
|
|
1317
1339
|
const { jobId } = args;
|
|
1318
|
-
|
|
1340
|
+
|
|
1319
1341
|
if (!jobId) {
|
|
1320
1342
|
throw new Error('jobId is required');
|
|
1321
1343
|
}
|
|
1322
|
-
|
|
1344
|
+
|
|
1323
1345
|
const mcpRequest = {
|
|
1324
1346
|
jsonrpc: '2.0',
|
|
1325
1347
|
id: Date.now(),
|
|
@@ -1329,41 +1351,93 @@ async function handleCheckTranslationStatus(args) {
|
|
|
1329
1351
|
arguments: { jobId }
|
|
1330
1352
|
}
|
|
1331
1353
|
};
|
|
1332
|
-
|
|
1354
|
+
|
|
1333
1355
|
try {
|
|
1334
1356
|
const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
|
|
1335
1357
|
headers: { 'Content-Type': 'application/json' },
|
|
1336
1358
|
timeout: 30000
|
|
1337
1359
|
});
|
|
1338
|
-
|
|
1360
|
+
|
|
1339
1361
|
if (response.data.error) {
|
|
1340
1362
|
throw new Error(`Translation status error: ${response.data.error.message || response.data.error}`);
|
|
1341
1363
|
}
|
|
1342
|
-
|
|
1364
|
+
|
|
1343
1365
|
return response.data.result;
|
|
1344
1366
|
} catch (error) {
|
|
1345
1367
|
console.error('Check translation status error:', error);
|
|
1346
|
-
|
|
1368
|
+
|
|
1347
1369
|
// Handle 503 service unavailable
|
|
1348
1370
|
if (error.response?.status === 503) {
|
|
1349
1371
|
throw new Error(`i18n-agent encountered unexpected problem, and we are working on it, try again later.`);
|
|
1350
1372
|
}
|
|
1351
|
-
|
|
1373
|
+
|
|
1352
1374
|
// Handle 404 not found
|
|
1353
1375
|
if (error.response?.status === 404) {
|
|
1354
1376
|
throw new Error(`Translation job ${jobId} not found. The job may have expired or the ID is incorrect.`);
|
|
1355
1377
|
}
|
|
1356
|
-
|
|
1378
|
+
|
|
1357
1379
|
// Handle timeout
|
|
1358
1380
|
if (error.code === 'ECONNABORTED') {
|
|
1359
1381
|
throw new Error(`Status check timed out. The service may be experiencing high load. Please try again.`);
|
|
1360
1382
|
}
|
|
1361
|
-
|
|
1383
|
+
|
|
1362
1384
|
// Generic error
|
|
1363
1385
|
throw new Error(`Unable to check translation status: ${error.message}`);
|
|
1364
1386
|
}
|
|
1365
1387
|
}
|
|
1366
1388
|
|
|
1389
|
+
// Handler for resuming translation jobs
|
|
1390
|
+
async function handleResumeTranslation(args) {
|
|
1391
|
+
const { jobId } = args;
|
|
1392
|
+
|
|
1393
|
+
if (!jobId) {
|
|
1394
|
+
throw new Error('jobId is required');
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
const mcpRequest = {
|
|
1398
|
+
jsonrpc: '2.0',
|
|
1399
|
+
id: Date.now(),
|
|
1400
|
+
method: 'tools/call',
|
|
1401
|
+
params: {
|
|
1402
|
+
name: 'resume_translation',
|
|
1403
|
+
arguments: { jobId }
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
try {
|
|
1408
|
+
const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
|
|
1409
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1410
|
+
timeout: 30000
|
|
1411
|
+
});
|
|
1412
|
+
|
|
1413
|
+
if (response.data.error) {
|
|
1414
|
+
throw new Error(`Resume translation error: ${response.data.error.message || response.data.error}`);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
return response.data.result;
|
|
1418
|
+
} catch (error) {
|
|
1419
|
+
console.error('Resume translation error:', error);
|
|
1420
|
+
|
|
1421
|
+
// Handle 503 service unavailable
|
|
1422
|
+
if (error.response?.status === 503) {
|
|
1423
|
+
throw new Error(`i18n-agent encountered unexpected problem, and we are working on it, try again later.`);
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
// Handle 404 not found
|
|
1427
|
+
if (error.response?.status === 404) {
|
|
1428
|
+
throw new Error(`Translation job ${jobId} not found. The job may have expired or the ID is incorrect.`);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
// Handle timeout
|
|
1432
|
+
if (error.code === 'ECONNABORTED') {
|
|
1433
|
+
throw new Error(`Resume request timed out. The service may be experiencing high load. Please try again.`);
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// Generic error
|
|
1437
|
+
throw new Error(`Unable to resume translation: ${error.message}`);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1367
1441
|
// Start the server
|
|
1368
1442
|
async function main() {
|
|
1369
1443
|
const transport = new StdioServerTransport();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-agent/mcp-client",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"description": "MCP client for i18n-agent translation service with async job support and enhanced progress tracking - supports Claude, Cursor, VS Code, and other AI IDEs",
|
|
5
5
|
"main": "mcp-client.js",
|
|
6
6
|
"bin": {
|