@i18n-agent/mcp-client 1.15.6 → 1.16.0

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/i18n-agent.js +34 -43
  2. package/package.json +1 -1
package/i18n-agent.js CHANGED
@@ -7,6 +7,14 @@
7
7
 
8
8
  const MCP_CLIENT_VERSION = '1.13.0';
9
9
 
10
+ // CLI argument routing — must run before MCP server initialization
11
+ const _cliCommand = process.argv[2];
12
+ if (_cliCommand === 'install' || _cliCommand === 'setup') {
13
+ const { main } = await import('./install.js');
14
+ await main();
15
+ process.exit(0);
16
+ }
17
+
10
18
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
11
19
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
12
20
  import {
@@ -43,6 +51,19 @@ if (!process.env.I18N_AGENT_API_KEY) {
43
51
  const MCP_SERVER_URL = process.env.MCP_SERVER_URL;
44
52
  const I18N_AGENT_API_KEY = process.env.I18N_AGENT_API_KEY;
45
53
 
54
+ // Pre-configured axios client for all MCP JSON-RPC tool calls.
55
+ // Centralises auth header so individual handlers never need to repeat it.
56
+ const mcpAxios = axios.create({
57
+ baseURL: MCP_SERVER_URL,
58
+ headers: {
59
+ 'Content-Type': 'application/json',
60
+ 'Authorization': `Bearer ${I18N_AGENT_API_KEY}`,
61
+ },
62
+ });
63
+
64
+ // Auth header object reused by REST (non-JSON-RPC) calls that also need auth.
65
+ const authHeader = { 'Authorization': `Bearer ${I18N_AGENT_API_KEY}` };
66
+
46
67
  // Heavy load detection - matches error message from service-mcp error-message-sanitizer
47
68
  // Exact message: 'Our system is under heavy load, please resume your job later.'
48
69
  const HEAVY_LOAD_PATTERNS = [
@@ -609,7 +630,6 @@ async function handleTranslateText(args) {
609
630
  params: {
610
631
  name: 'translate_text',
611
632
  arguments: {
612
- apiKey: I18N_AGENT_API_KEY,
613
633
  texts: texts,
614
634
  targetLanguages: targetLanguages,
615
635
  sourceLanguage: sourceLanguage && sourceLanguage !== 'auto' ? sourceLanguage : undefined,
@@ -626,10 +646,7 @@ async function handleTranslateText(args) {
626
646
  };
627
647
 
628
648
  try {
629
- const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
630
- headers: {
631
- 'Content-Type': 'application/json',
632
- },
649
+ const response = await mcpAxios.post('', mcpRequest, {
633
650
  timeout: isLargeRequest ? 600000 : 300000, // 10 minutes for large requests, 5 minutes for normal
634
651
  });
635
652
 
@@ -773,10 +790,7 @@ async function handleListLanguages(args) {
773
790
  };
774
791
 
775
792
  try {
776
- const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
777
- headers: {
778
- 'Content-Type': 'application/json',
779
- },
793
+ const response = await mcpAxios.post('', mcpRequest, {
780
794
  timeout: 30000,
781
795
  });
782
796
 
@@ -952,7 +966,6 @@ async function handleTranslateFile(args) {
952
966
 
953
967
  // Build arguments object, filtering out undefined values (they get stripped by JSON.stringify)
954
968
  const requestArgs = {
955
- apiKey: I18N_AGENT_API_KEY,
956
969
  filePath,
957
970
  fileContent: content,
958
971
  fileType,
@@ -984,10 +997,7 @@ async function handleTranslateFile(args) {
984
997
  };
985
998
 
986
999
  try {
987
- const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
988
- headers: {
989
- 'Content-Type': 'application/json',
990
- },
1000
+ const response = await mcpAxios.post('', mcpRequest, {
991
1001
  timeout: isLargeFile ? 600000 : 300000, // 10 minutes for large files, 5 minutes for normal
992
1002
  });
993
1003
 
@@ -1163,8 +1173,7 @@ async function pollTranslationJob(jobId, estimatedTime) {
1163
1173
  }
1164
1174
  };
1165
1175
 
1166
- const response = await axios.post(MCP_SERVER_URL, statusRequest, {
1167
- headers: { 'Content-Type': 'application/json' },
1176
+ const response = await mcpAxios.post('', statusRequest, {
1168
1177
  timeout: 30000
1169
1178
  });
1170
1179
 
@@ -1261,7 +1270,6 @@ async function handleAnalyzeContent(args) {
1261
1270
  params: {
1262
1271
  name: 'analyze_content',
1263
1272
  arguments: {
1264
- apiKey: I18N_AGENT_API_KEY,
1265
1273
  content,
1266
1274
  fileType,
1267
1275
  sourceLanguage,
@@ -1274,10 +1282,7 @@ async function handleAnalyzeContent(args) {
1274
1282
  };
1275
1283
 
1276
1284
  try {
1277
- const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
1278
- headers: {
1279
- 'Content-Type': 'application/json',
1280
- },
1285
+ const response = await mcpAxios.post('', mcpRequest, {
1281
1286
  timeout: 60000, // 1 minute timeout for analysis
1282
1287
  });
1283
1288
 
@@ -1311,9 +1316,6 @@ async function handleAnalyzeContent(args) {
1311
1316
  }
1312
1317
 
1313
1318
  async function handleGetCredits(args) {
1314
- const { apiKey } = args;
1315
- const creditsApiKey = apiKey || I18N_AGENT_API_KEY;
1316
-
1317
1319
  // Use MCP JSON-RPC protocol for get_credits
1318
1320
  const mcpRequest = {
1319
1321
  jsonrpc: '2.0',
@@ -1321,17 +1323,12 @@ async function handleGetCredits(args) {
1321
1323
  method: 'tools/call',
1322
1324
  params: {
1323
1325
  name: 'get_credits',
1324
- arguments: {
1325
- apiKey: creditsApiKey
1326
- }
1326
+ arguments: {}
1327
1327
  }
1328
1328
  };
1329
1329
 
1330
1330
  try {
1331
- const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
1332
- headers: {
1333
- 'Content-Type': 'application/json',
1334
- },
1331
+ const response = await mcpAxios.post('', mcpRequest, {
1335
1332
  timeout: 30000,
1336
1333
  });
1337
1334
 
@@ -1778,8 +1775,7 @@ async function handleCheckTranslationStatus(args) {
1778
1775
  };
1779
1776
 
1780
1777
  try {
1781
- const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
1782
- headers: { 'Content-Type': 'application/json' },
1778
+ const response = await mcpAxios.post('', mcpRequest, {
1783
1779
  timeout: 30000
1784
1780
  });
1785
1781
 
@@ -1841,8 +1837,7 @@ async function handleResumeTranslation(args) {
1841
1837
  };
1842
1838
 
1843
1839
  try {
1844
- const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
1845
- headers: { 'Content-Type': 'application/json' },
1840
+ const response = await mcpAxios.post('', mcpRequest, {
1846
1841
  timeout: 30000
1847
1842
  });
1848
1843
 
@@ -1900,7 +1895,6 @@ async function handleDownloadTranslations(args) {
1900
1895
  params: {
1901
1896
  name: 'download_translations',
1902
1897
  arguments: {
1903
- apiKey: I18N_AGENT_API_KEY,
1904
1898
  jobId
1905
1899
  }
1906
1900
  }
@@ -1908,8 +1902,7 @@ async function handleDownloadTranslations(args) {
1908
1902
 
1909
1903
  try {
1910
1904
  // Step 1: Get download URLs from MCP server
1911
- const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
1912
- headers: { 'Content-Type': 'application/json' },
1905
+ const response = await mcpAxios.post('', mcpRequest, {
1913
1906
  timeout: 30000
1914
1907
  });
1915
1908
 
@@ -2151,7 +2144,7 @@ async function handleSingleFileUpload(args) {
2151
2144
  formData,
2152
2145
  {
2153
2146
  headers: {
2154
- 'Authorization': `Bearer ${I18N_AGENT_API_KEY}`,
2147
+ ...authHeader,
2155
2148
  ...formData.getHeaders()
2156
2149
  },
2157
2150
  timeout: 60000
@@ -2264,7 +2257,7 @@ async function handleParallelDocumentUpload(args) {
2264
2257
  formData,
2265
2258
  {
2266
2259
  headers: {
2267
- 'Authorization': `Bearer ${I18N_AGENT_API_KEY}`,
2260
+ ...authHeader,
2268
2261
  ...formData.getHeaders()
2269
2262
  },
2270
2263
  timeout: 120000
@@ -2325,9 +2318,7 @@ async function handleListUploadedTranslations(args) {
2325
2318
  const response = await axios.get(
2326
2319
  `${MCP_SERVER_URL}/namespaces/${namespace}/translations/files?${params.toString()}`,
2327
2320
  {
2328
- headers: {
2329
- 'Authorization': `Bearer ${I18N_AGENT_API_KEY}`
2330
- },
2321
+ headers: authHeader,
2331
2322
  timeout: 30000
2332
2323
  }
2333
2324
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-agent/mcp-client",
3
- "version": "1.15.6",
3
+ "version": "1.16.0",
4
4
  "description": "🌍 i18n-agent MCP Client - 48 languages, AI-powered translation for Claude, Claude Code, Cursor, VS Code, Codex. Get API key at https://app.i18nagent.ai",
5
5
  "main": "i18n-agent.js",
6
6
  "bin": "i18n-agent.js",