@i18n-agent/mcp-client 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/mcp-client.js +43 -20
  2. package/package.json +3 -3
package/mcp-client.js CHANGED
@@ -30,8 +30,14 @@ const server = new Server(
30
30
  );
31
31
 
32
32
  // Configuration
33
- const MCP_SERVER_URL = process.env.MCP_SERVER_URL || 'https://mcp.i18nagent.ai';
34
- const API_KEY = process.env.API_KEY || 'sk-prod-fa6e528114c6136c12fcfcee08bb0f5f0ef7a262cfeb8b151bc44b8996336d53';
33
+ if (!process.env.MCP_SERVER_URL) {
34
+ throw new Error('MCP_SERVER_URL environment variable is required');
35
+ }
36
+ if (!process.env.API_KEY) {
37
+ throw new Error('API_KEY environment variable is required');
38
+ }
39
+ const MCP_SERVER_URL = process.env.MCP_SERVER_URL;
40
+ const API_KEY = process.env.API_KEY;
35
41
 
36
42
  // Available tools
37
43
  server.setRequestHandler(ListToolsRequestSchema, async () => {
@@ -298,7 +304,18 @@ async function handleTranslateText(args) {
298
304
  ]
299
305
  };
300
306
  }
301
- throw new Error(`Translation service unavailable: ${error.message}`);
307
+
308
+ // Check if it's actually a service unavailable error (503, timeout, connection issues)
309
+ if (error.code === 'ECONNREFUSED' ||
310
+ error.code === 'ETIMEDOUT' ||
311
+ error.response?.status === 503 ||
312
+ error.response?.status === 502 ||
313
+ error.response?.status === 504) {
314
+ throw new Error(`Translation service unavailable: ${error.message}`);
315
+ }
316
+
317
+ // For other errors (401, 402, 404, etc), throw them as-is without "unavailable" keyword
318
+ throw error;
302
319
  }
303
320
  }
304
321
 
@@ -489,7 +506,18 @@ async function handleTranslateFile(args) {
489
506
  ]
490
507
  };
491
508
  }
492
- throw new Error(`Translation service unavailable: ${error.message}`);
509
+
510
+ // Check if it's actually a service unavailable error
511
+ if (error.code === 'ECONNREFUSED' ||
512
+ error.code === 'ETIMEDOUT' ||
513
+ error.response?.status === 503 ||
514
+ error.response?.status === 502 ||
515
+ error.response?.status === 504) {
516
+ throw new Error(`Translation service unavailable: ${error.message}`);
517
+ }
518
+
519
+ // For other errors, throw them as-is without "unavailable" keyword
520
+ throw error;
493
521
  }
494
522
  }
495
523
 
@@ -568,25 +596,20 @@ async function pollTranslationJob(jobId, estimatedTime) {
568
596
 
569
597
  async function handleGetCredits(args) {
570
598
  try {
571
- const response = await axios.post(`${MCP_SERVER_URL}/api/mcp`, {
572
- name: 'get_credits',
573
- arguments: {
574
- apiKey: API_KEY,
575
- }
576
- }, {
599
+ // Get team info first using the API key
600
+ const teamResponse = await axios.get(`https://platform.i18nagent.ai/api/teams/by-api-key/${API_KEY}`, {
577
601
  headers: {
578
602
  'Content-Type': 'application/json'
579
603
  },
580
604
  timeout: 10000
581
605
  });
582
606
 
583
- const result = response.data;
584
-
585
- if (result.isError) {
586
- throw new Error(result.content[0].text);
607
+ if (!teamResponse.data.success) {
608
+ throw new Error(teamResponse.data.error || 'Failed to get team information');
587
609
  }
588
610
 
589
- const creditsInfo = JSON.parse(result.content[0].text);
611
+ const teamInfo = teamResponse.data.data;
612
+ const approximateWordsAvailable = Math.floor(teamInfo.credits * 1000); // 0.001 credits per word
590
613
 
591
614
  return {
592
615
  content: [
@@ -594,11 +617,11 @@ async function handleGetCredits(args) {
594
617
  type: 'text',
595
618
  text: `💰 **Credits Information**
596
619
 
597
- 🏢 **Team**: ${creditsInfo.teamName}
598
- 💳 **Credits Remaining**: ${creditsInfo.creditsRemaining}
599
- 📝 **Approximate Words Available**: ${creditsInfo.approximateWordsAvailable.toLocaleString()}
600
- 💵 **Cost per Word**: ${creditsInfo.costPerWord} credits
601
- ⏰ **Last Updated**: ${new Date(creditsInfo.timestamp).toLocaleString()}
620
+ 🏢 **Team**: ${teamInfo.name}
621
+ 💳 **Credits Remaining**: ${teamInfo.credits}
622
+ 📝 **Approximate Words Available**: ${approximateWordsAvailable.toLocaleString()}
623
+ 💵 **Cost per Word**: 0.001 credits
624
+ ⏰ **Last Updated**: ${new Date().toLocaleString()}
602
625
 
603
626
  Note: Word count is approximate and may vary based on actual content complexity and translation requirements.`,
604
627
  },
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@i18n-agent/mcp-client",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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": "./install.js"
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
+ }