@i18n-agent/mcp-client 1.7.9 → 1.8.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 (4) hide show
  1. package/README.md +54 -35
  2. package/install.js +124 -43
  3. package/mcp-client.js +133 -14
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -13,7 +13,7 @@ Professional translation service client for Claude, Cursor, VS Code, and other A
13
13
  - **🔄 Timeout Improvements**: Extended timeouts (5-10 min) for large translations
14
14
  - **📊 Progress Tracking**: Real-time job status and completion monitoring
15
15
  - **💰 Credit Tracking**: Real-time credit balance and word count estimates
16
- - **🌐 30+ Languages**: Multi-tier language support with quality ratings
16
+ - **🌐 48 Languages**: Comprehensive language support with regional variants
17
17
  - **🔧 Easy Setup**: One-command installation for major AI IDEs
18
18
 
19
19
  ## 🚀 Quick Installation
@@ -71,53 +71,69 @@ List supported languages with quality ratings
71
71
 
72
72
  ### Content Analysis
73
73
  ```
74
- Analyze content for translation readiness and get improvement suggestions
74
+ Analyze "Hello world! This is a test." for translation to Spanish
75
75
  ```
76
76
 
77
77
  ## 🛠 Supported AI IDEs
78
78
 
79
- | IDE | Status | Config Location |
80
- |-----|--------|----------------|
81
- | **Claude Desktop** | ✅ Auto-configured | `~/Library/Application Support/Claude/claude_desktop_config.json` |
82
- | **Cursor** | ✅ Auto-configured | `~/.cursor/mcp_settings.json` |
83
- | **VS Code** | ✅ Auto-configured | `~/.vscode/mcp_settings.json` |
84
- | **Other MCP IDEs** | 🔧 Manual setup | Varies |
79
+ | IDE | Status | macOS | Windows | Linux |
80
+ |-----|--------|-------|---------|-------|
81
+ | **Claude Desktop** | ✅ Auto-configured | `~/Library/Application Support/Claude/` | `%APPDATA%\Claude\` | `~/.config/Claude/` |
82
+ | **Claude Code CLI** | ✅ Auto-configured | `~/.claude.json` | `~/.claude.json` | `~/.claude.json` |
83
+ | **Cursor** | ✅ Auto-configured | `~/.cursor/mcp_settings.json` | `~/.cursor/mcp_settings.json` | `~/.cursor/mcp_settings.json` |
84
+ | **VS Code** | Auto-configured | `~/.vscode/mcp_settings.json` | `~/.vscode/mcp_settings.json` | `~/.vscode/mcp_settings.json` |
85
+ | **Codex (OpenAI)** | ✅ Auto-configured | `~/.codex/mcp_settings.json` | `~/.codex/mcp_settings.json` | `~/.codex/mcp_settings.json` |
85
86
 
86
- ## 🌐 Language Support
87
- - **en**: English
88
- - **fr**: French
87
+ **Note:** The installer automatically detects your platform and uses the correct config paths.
88
+
89
+ ## 🌐 Language Support (48 Languages)
90
+ - **bg**: Bulgarian
91
+ - **ca**: Catalan
92
+ - **cs**: Czech
93
+ - **da**: Danish
89
94
  - **de**: German
95
+ - **el**: Greek
96
+ - **en**: English
97
+ - **en-AU**: English (Australia)
98
+ - **en-CA**: English (Canada)
99
+ - **en-GB**: English (United Kingdom)
100
+ - **en-US**: English (United States)
90
101
  - **es**: Spanish
102
+ - **es-MX**: Spanish (Mexico)
103
+ - **et**: Estonian
104
+ - **fi**: Finnish
105
+ - **fr**: French
106
+ - **fr-CA**: French (Canada)
107
+ - **hi**: Hindi
108
+ - **hr**: Croatian
109
+ - **hu**: Hungarian
110
+ - **id**: Indonesian
111
+ - **is**: Icelandic
91
112
  - **it**: Italian
92
- - **pt**: Portuguese
93
- - **ru**: Russian
94
113
  - **ja**: Japanese
95
114
  - **ko**: Korean
96
- - **zh-CN**: Chinese (Simplified)
115
+ - **lt**: Lithuanian
116
+ - **lv**: Latvian
117
+ - **ms**: Malay
97
118
  - **nl**: Dutch
98
- - **pl**: Polish
99
- - **cs**: Czech
100
- - **ar**: Arabic
101
- - **he**: Hebrew
102
- - **hi**: Hindi
103
- - **zh-TW**: Chinese (Traditional)
104
- - **sv**: Swedish
105
- - **da**: Danish
106
119
  - **no**: Norwegian
107
- - **fi**: Finnish
108
- - **tr**: Turkish
109
- - **hu**: Hungarian
110
- - **th**: Thai
111
- - **vi**: Vietnamese
112
- - **uk**: Ukrainian
113
- - **bg**: Bulgarian
120
+ - **pl**: Polish
121
+ - **pt**: Portuguese
122
+ - **pt-BR**: Portuguese (Brazil)
114
123
  - **ro**: Romanian
115
- - **hr**: Croatian
124
+ - **ru**: Russian
116
125
  - **sk**: Slovak
117
126
  - **sl**: Slovenian
118
- - **et**: Estonian
119
- - **lv**: Latvian
120
- - **lt**: Lithuanian
127
+ - **sr**: Serbian
128
+ - **sv**: Swedish
129
+ - **th**: Thai
130
+ - **tl**: Filipino
131
+ - **tr**: Turkish
132
+ - **uk**: Ukrainian
133
+ - **vi**: Vietnamese
134
+ - **zh-Hans**: Chinese (Simplified)
135
+ - **zh-Hant-HK**: Chinese (Traditional, Hong Kong)
136
+ - **zh-Hant-TW**: Chinese (Traditional, Taiwan)
121
137
 
122
138
  ## 📁 Supported File Formats
123
139
 
@@ -128,8 +144,11 @@ Analyze content for translation readiness and get improvement suggestions
128
144
  | CSV | `.csv` | Handles quoted fields, commas |
129
145
  | XML/HTML | `.xml`, `.html` | Extracts text content |
130
146
  | Markdown | `.md` | Preserves formatting, skips code |
131
- | Properties | `.properties` | Key-value pairs |
147
+ | Properties | `.properties` | Java properties key-value pairs |
132
148
  | Plain Text | `.txt` | Direct translation |
149
+ | PDF | `.pdf` | Text extraction and translation |
150
+ | Word | `.docx`, `.doc` | Document translation |
151
+ | Gettext | `.po`, `.pot`, `.mo` | Localization file formats |
133
152
 
134
153
  ## 🔧 Manual Setup
135
154
 
@@ -347,7 +366,7 @@ Translate files while preserving structure and format.
347
366
  - `outputFormat` (string): Output format (same, json, yaml, txt)
348
367
 
349
368
  ### analyze_content
350
- Analyze content for translation readiness and get improvement suggestions before translation.
369
+ Analyze content for translation readiness and get improvement suggestions before translation. This helps identify potential issues and optimize content before spending credits on translation.
351
370
 
352
371
  **Parameters:**
353
372
  - `content` (string/array/object): Content to analyze
package/install.js CHANGED
@@ -12,12 +12,42 @@ import { fileURLToPath } from 'url';
12
12
 
13
13
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
14
 
15
+ // Helper to get platform-specific paths
16
+ function getClaudeDesktopPath() {
17
+ const platform = process.platform;
18
+ if (platform === 'darwin') {
19
+ // macOS
20
+ return {
21
+ configPath: path.join(os.homedir(), 'Library/Application Support/Claude/claude_desktop_config.json'),
22
+ displayPath: '~/Library/Application Support/Claude/claude_desktop_config.json'
23
+ };
24
+ } else if (platform === 'win32') {
25
+ // Windows
26
+ return {
27
+ configPath: path.join(os.homedir(), 'AppData/Roaming/Claude/claude_desktop_config.json'),
28
+ displayPath: '%APPDATA%\\Claude\\claude_desktop_config.json'
29
+ };
30
+ } else {
31
+ // Linux
32
+ return {
33
+ configPath: path.join(os.homedir(), '.config/Claude/claude_desktop_config.json'),
34
+ displayPath: '~/.config/Claude/claude_desktop_config.json'
35
+ };
36
+ }
37
+ }
38
+
15
39
  // Supported IDE configurations
40
+ const claudePaths = getClaudeDesktopPath();
16
41
  const IDE_CONFIGS = {
17
42
  claude: {
18
43
  name: 'Claude Desktop',
19
- configPath: path.join(os.homedir(), 'Library/Application Support/Claude/claude_desktop_config.json'),
20
- displayPath: '~/Library/Application Support/Claude/claude_desktop_config.json'
44
+ configPath: claudePaths.configPath,
45
+ displayPath: claudePaths.displayPath
46
+ },
47
+ 'claude-code': {
48
+ name: 'Claude Code CLI',
49
+ configPath: path.join(os.homedir(), '.claude.json'),
50
+ displayPath: '~/.claude.json'
21
51
  },
22
52
  cursor: {
23
53
  name: 'Cursor',
@@ -28,6 +58,11 @@ const IDE_CONFIGS = {
28
58
  name: 'VS Code (with MCP extension)',
29
59
  configPath: path.join(os.homedir(), '.vscode/mcp_settings.json'),
30
60
  displayPath: '~/.vscode/mcp_settings.json'
61
+ },
62
+ codex: {
63
+ name: 'Codex (OpenAI)',
64
+ configPath: path.join(os.homedir(), '.codex/mcp_settings.json'),
65
+ displayPath: '~/.codex/mcp_settings.json'
31
66
  }
32
67
  };
33
68
 
@@ -41,9 +76,18 @@ Features:
41
76
  ✨ Text translation with cultural context
42
77
  📁 File translation (JSON, YAML, CSV, MD, etc.)
43
78
  💰 Credit balance checking
44
- 🌐 30+ language support with quality tiers
79
+ 🌐 48 languages supported with regional variants
80
+
81
+ 🔑 IMPORTANT: Get your API key at https://app.i18nagent.ai
82
+ (Required for the MCP client to work)
45
83
  `);
46
84
 
85
+ const getMcpClientPaths = () => {
86
+ const mcpClientPath = path.resolve(__dirname, 'mcp-client.js');
87
+ const packageDir = path.dirname(mcpClientPath);
88
+ return { mcpClientPath, packageDir };
89
+ };
90
+
47
91
  async function detectAvailableIDEs() {
48
92
  const available = [];
49
93
 
@@ -58,13 +102,14 @@ async function detectAvailableIDEs() {
58
102
  }
59
103
 
60
104
  function createMCPConfig() {
61
- const mcpClientPath = path.resolve(__dirname, 'mcp-client.js');
62
-
105
+ const { mcpClientPath, packageDir } = getMcpClientPaths();
106
+
63
107
  return {
64
108
  mcpServers: {
65
109
  "i18n-agent": {
66
110
  command: "node",
67
111
  args: [mcpClientPath],
112
+ cwd: packageDir,
68
113
  env: {
69
114
  MCP_SERVER_URL: "https://mcp.i18nagent.ai",
70
115
  API_KEY: ""
@@ -90,25 +135,27 @@ function detectNodeEnvironment() {
90
135
  function createWrapperScript(targetDir) {
91
136
  const nodeEnv = detectNodeEnvironment();
92
137
  const wrapperPath = path.join(targetDir, 'run-mcp.sh');
93
- const mcpClientPath = path.join(targetDir, 'node_modules', '@i18n-agent', 'mcp-client', 'mcp-client.js');
94
-
138
+ const { mcpClientPath, packageDir } = getMcpClientPaths();
139
+
140
+ fs.mkdirSync(targetDir, { recursive: true });
141
+
95
142
  let wrapperContent;
96
-
143
+
97
144
  if (nodeEnv.isNvm) {
98
145
  // For nvm users, we need to set up the PATH properly
99
146
  wrapperContent = `#!/bin/bash
100
147
  # Wrapper script for i18n-agent MCP client (handles nvm environments)
101
148
  export PATH="${path.dirname(nodeEnv.nodePath)}:$PATH"
102
- cd "${targetDir}"
149
+ cd "${packageDir}"
103
150
  exec node "${mcpClientPath}"`;
104
151
  } else {
105
152
  // For system node installations
106
153
  wrapperContent = `#!/bin/bash
107
154
  # Wrapper script for i18n-agent MCP client
108
- cd "${targetDir}"
155
+ cd "${packageDir}"
109
156
  exec node "${mcpClientPath}"`;
110
157
  }
111
-
158
+
112
159
  fs.writeFileSync(wrapperPath, wrapperContent, { mode: 0o755 });
113
160
  return wrapperPath;
114
161
  }
@@ -139,7 +186,7 @@ function updateClaudeConfig(configPath) {
139
186
  // Create wrapper script for nvm users
140
187
  console.log(' 🔧 Detected nvm environment, creating wrapper script...');
141
188
  const wrapperPath = createWrapperScript(claudeDir);
142
-
189
+
143
190
  config.mcpServers["i18n-agent"] = {
144
191
  command: wrapperPath,
145
192
  env: {
@@ -149,17 +196,8 @@ function updateClaudeConfig(configPath) {
149
196
  };
150
197
  } else {
151
198
  // Standard configuration for system node
152
- const mcpClientPath = path.join(claudeDir, 'node_modules', '@i18n-agent', 'mcp-client', 'mcp-client.js');
153
-
154
- config.mcpServers["i18n-agent"] = {
155
- command: "node",
156
- args: [mcpClientPath],
157
- cwd: claudeDir,
158
- env: {
159
- MCP_SERVER_URL: "https://mcp.i18nagent.ai",
160
- API_KEY: ""
161
- }
162
- };
199
+ const baseConfig = createMCPConfig();
200
+ config.mcpServers["i18n-agent"] = baseConfig.mcpServers["i18n-agent"];
163
201
  }
164
202
 
165
203
  // Write updated config
@@ -170,12 +208,28 @@ function updateClaudeConfig(configPath) {
170
208
  }
171
209
 
172
210
  function updateGenericMCPConfig(configPath) {
173
- const config = createMCPConfig();
174
-
211
+ let config = {};
212
+
213
+ if (fs.existsSync(configPath)) {
214
+ try {
215
+ const existing = fs.readFileSync(configPath, 'utf8');
216
+ config = JSON.parse(existing);
217
+ } catch (error) {
218
+ console.warn(`Warning: Could not parse existing config at ${configPath}`);
219
+ }
220
+ }
221
+
222
+ if (!config.mcpServers) {
223
+ config.mcpServers = {};
224
+ }
225
+
226
+ const baseConfig = createMCPConfig();
227
+ config.mcpServers["i18n-agent"] = baseConfig.mcpServers["i18n-agent"];
228
+
175
229
  // Write config
176
230
  fs.mkdirSync(path.dirname(configPath), { recursive: true });
177
231
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
178
-
232
+
179
233
  return config;
180
234
  }
181
235
 
@@ -190,8 +244,10 @@ async function main() {
190
244
 
191
245
  Supported IDEs:
192
246
  - Claude Desktop (macOS)
247
+ - Claude Code CLI
193
248
  - Cursor
194
249
  - VS Code (with MCP extension)
250
+ - Codex (OpenAI)
195
251
 
196
252
  Manual setup:
197
253
  1. Create the configuration file for your IDE
@@ -209,45 +265,70 @@ For manual setup instructions, visit: https://docs.i18nagent.ai/setup
209
265
  });
210
266
 
211
267
  console.log('\n📝 Installing for all available IDEs...\n');
212
-
268
+
213
269
  let installCount = 0;
214
-
270
+ const installedIDEs = [];
271
+
215
272
  for (const ide of availableIDEs) {
216
273
  try {
217
274
  console.log(`⚙️ Configuring ${ide.name}...`);
218
-
219
- if (ide.key === 'claude') {
275
+
276
+ if (ide.key === 'claude' || ide.key === 'claude-code') {
220
277
  updateClaudeConfig(ide.configPath);
221
278
  } else {
222
279
  updateGenericMCPConfig(ide.configPath);
223
280
  }
224
-
281
+
225
282
  console.log(`✅ ${ide.name} configured successfully!`);
226
283
  console.log(` Config: ${ide.displayPath}\n`);
227
284
  installCount++;
228
-
285
+ installedIDEs.push(ide);
286
+
229
287
  } catch (error) {
230
288
  console.error(`❌ Failed to configure ${ide.name}: ${error.message}\n`);
231
289
  }
232
290
  }
233
-
291
+
234
292
  if (installCount > 0) {
293
+ // Show config file paths for ONLY installed IDEs
294
+ const configPaths = installedIDEs.map(ide => ` - ${ide.name}: ${ide.displayPath}`).join('\n');
295
+
296
+ // Platform-specific environment variable instructions
297
+ const isWindows = process.platform === 'win32';
298
+ const envVarInstructions = isWindows
299
+ ? ` Windows PowerShell:
300
+ $env:API_KEY="your-api-key-here"
301
+
302
+ Or set permanently via System Environment Variables:
303
+ 1. Search "Environment Variables" in Windows
304
+ 2. Click "New" under User variables
305
+ 3. Variable name: API_KEY
306
+ 4. Variable value: your-api-key-here`
307
+ : ` macOS/Linux:
308
+ export API_KEY=your-api-key-here
309
+
310
+ Add to shell profile for persistence (~/.bashrc, ~/.zshrc):
311
+ echo 'export API_KEY=your-api-key-here' >> ~/.zshrc`;
312
+
235
313
  console.log(`🎉 Installation complete! Configured ${installCount} IDE(s).
236
314
 
237
- 🔑 Important: Set your API key
315
+ 🔑 NEXT STEP: Add your API key
238
316
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
239
- You need to set your API key to use the translation service:
240
-
241
317
  1. Get your API key from: https://app.i18nagent.ai
242
- 2. Set it as an environment variable:
243
318
 
244
- export API_KEY=your-api-key-here
319
+ 2. Add it to your config file(s):
320
+ ${configPaths}
321
+
322
+ Open the file and add your API key to the "env" section:
323
+ "env": {
324
+ "MCP_SERVER_URL": "https://mcp.i18nagent.ai",
325
+ "API_KEY": "your-api-key-here" ← Add your key here
326
+ }
245
327
 
246
- Or add it to your shell profile (~/.bashrc, ~/.zshrc):
247
- echo 'export API_KEY=your-api-key-here' >> ~/.zshrc
328
+ OR set as environment variable:
329
+ ${envVarInstructions}
248
330
 
249
- 🔄 Restart your IDE
250
- After setting the API key, restart your AI IDE to load the new configuration.
331
+ 3. Restart your IDE to load the configuration
251
332
 
252
333
  🧪 Test the installation
253
334
  Try these commands in your AI IDE:
@@ -274,4 +355,4 @@ if (import.meta.url === `file://${process.argv[1]}`) {
274
355
  main();
275
356
  }
276
357
 
277
- export { main, IDE_CONFIGS, createMCPConfig };
358
+ export { main, IDE_CONFIGS, createMCPConfig };
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.9';
8
+ const MCP_CLIENT_VERSION = '1.8.1';
9
9
 
10
10
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
11
11
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
@@ -117,8 +117,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
117
117
  },
118
118
  fileType: {
119
119
  type: 'string',
120
- description: 'File type: json, yaml, yml, xml, csv, txt, md, html, properties',
121
- enum: ['json', 'yaml', 'yml', 'xml', 'csv', 'txt', 'md', 'html', 'properties', 'auto'],
120
+ description: 'File type: json, yaml, yml, xml, csv, txt, md, html, properties (Java), pdf, docx, doc, po (gettext), pot (gettext), mo (gettext), auto',
121
+ enum: ['json', 'yaml', 'yml', 'xml', 'csv', 'txt', 'md', 'html', 'properties', 'pdf', 'docx', 'doc', 'po', 'pot', 'mo', 'auto'],
122
122
  default: 'auto',
123
123
  },
124
124
  targetLanguages: {
@@ -164,6 +164,46 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
164
164
  required: ['targetLanguages'],
165
165
  },
166
166
  },
167
+ {
168
+ name: 'analyze_content',
169
+ description: 'Analyze content for translation readiness and get improvement suggestions. Returns detailed analysis including content type, quality score, and specific recommendations. Costs the same credits as translation.',
170
+ inputSchema: {
171
+ type: 'object',
172
+ properties: {
173
+ content: {
174
+ type: ['string', 'array', 'object'],
175
+ description: 'Content to analyze (text string, array of texts, or structured object)',
176
+ },
177
+ fileType: {
178
+ type: 'string',
179
+ description: 'Optional file type if content is from a file (json, yaml, xml, etc.)',
180
+ },
181
+ sourceLanguage: {
182
+ type: 'string',
183
+ description: 'Source language code (auto-detected if not provided)',
184
+ },
185
+ targetLanguage: {
186
+ type: 'string',
187
+ description: 'Target language code for translation',
188
+ },
189
+ industry: {
190
+ type: 'string',
191
+ description: 'Industry context (e.g., "technology", "healthcare", "finance")',
192
+ default: 'general',
193
+ },
194
+ targetAudience: {
195
+ type: 'string',
196
+ description: 'Target audience (e.g., "general", "technical", "professional")',
197
+ default: 'general',
198
+ },
199
+ region: {
200
+ type: 'string',
201
+ description: 'Specific region for localization (e.g., "Spain", "Mexico", "Brazil")',
202
+ },
203
+ },
204
+ required: ['content', 'targetLanguage'],
205
+ },
206
+ },
167
207
  {
168
208
  name: 'get_credits',
169
209
  description: 'Get remaining credits for the user and approximate word count available at 0.001 credits per word',
@@ -265,15 +305,18 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
265
305
  case 'translate_file':
266
306
  return await handleTranslateFile(args);
267
307
 
308
+ case 'analyze_content':
309
+ return await handleAnalyzeContent(args);
310
+
268
311
  case 'get_credits':
269
312
  return await handleGetCredits(args);
270
-
313
+
271
314
  /*
272
315
  * TOKEN USAGE TOOLS - BLOCKED FOR SECURITY
273
316
  * These cases are intentionally removed to prevent access to sensitive analytics data
274
317
  * through MCP interfaces. See tool definition comments above for details.
275
318
  */
276
-
319
+
277
320
  case 'check_translation_status':
278
321
  return await handleCheckTranslationStatus(args);
279
322
 
@@ -911,10 +954,86 @@ async function pollTranslationJob(jobId, estimatedTime) {
911
954
  throw new Error(`Translation job ${jobId} timed out after ${maxPolls * pollInterval / 1000} seconds. Please retry with a smaller chunk or split the content into multiple requests.`);
912
955
  }
913
956
 
957
+ async function handleAnalyzeContent(args) {
958
+ const {
959
+ content,
960
+ fileType,
961
+ sourceLanguage,
962
+ targetLanguage,
963
+ industry = 'general',
964
+ targetAudience = 'general',
965
+ region
966
+ } = args;
967
+
968
+ if (!content) {
969
+ throw new Error('content is required');
970
+ }
971
+
972
+ if (!targetLanguage) {
973
+ throw new Error('targetLanguage is required');
974
+ }
975
+
976
+ // Use MCP JSON-RPC protocol for analyze_content
977
+ const mcpRequest = {
978
+ jsonrpc: '2.0',
979
+ id: Date.now(),
980
+ method: 'tools/call',
981
+ params: {
982
+ name: 'analyze_content',
983
+ arguments: {
984
+ apiKey: API_KEY,
985
+ content,
986
+ fileType,
987
+ sourceLanguage,
988
+ targetLanguage,
989
+ industry,
990
+ targetAudience,
991
+ region
992
+ }
993
+ }
994
+ };
995
+
996
+ try {
997
+ const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
998
+ headers: {
999
+ 'Content-Type': 'application/json',
1000
+ },
1001
+ timeout: 60000, // 1 minute timeout for analysis
1002
+ });
1003
+
1004
+ if (response.data.error) {
1005
+ const errorMsg = response.data.error.message || response.data.error;
1006
+ throw new Error(`Content analysis error: ${errorMsg}`);
1007
+ }
1008
+
1009
+ return response.data.result;
1010
+ } catch (error) {
1011
+ // Handle 401 unauthorized
1012
+ if (error.response?.status === 401) {
1013
+ const authErrorDetails = error.response.data?.message || error.response.data?.result?.content?.[0]?.text || error.message;
1014
+ throw new Error(`❌ Invalid API key (401)\nDetails: ${authErrorDetails}\nPlease check your API key at https://app.i18nagent.ai\n[MCP v${MCP_CLIENT_VERSION}/STDIO/analyze_content]`);
1015
+ }
1016
+
1017
+ // Handle 402 payment required
1018
+ if (error.response?.status === 402) {
1019
+ const creditErrorDetails = error.response.data?.message || error.response.data?.result?.content?.[0]?.text || error.message;
1020
+ throw new Error(`⚠️ Insufficient credits (402)\nDetails: ${creditErrorDetails}\nPlease top up at https://app.i18nagent.ai\n[MCP v${MCP_CLIENT_VERSION}/STDIO/analyze_content]`);
1021
+ }
1022
+
1023
+ // Handle 503 service unavailable
1024
+ if (error.response?.status === 503) {
1025
+ throw new Error(`i18n-agent encountered unexpected problem, and we are working on it, try again later.`);
1026
+ }
1027
+
1028
+ console.error('Content analysis error:', error);
1029
+ throw new Error(`Unable to analyze content: ${error.message}`);
1030
+ }
1031
+ }
1032
+
914
1033
  async function handleGetCredits(args) {
915
1034
  const { apiKey } = args;
916
1035
  const creditsApiKey = apiKey || API_KEY;
917
-
1036
+
918
1037
  // Use MCP JSON-RPC protocol for get_credits
919
1038
  const mcpRequest = {
920
1039
  jsonrpc: '2.0',
@@ -927,7 +1046,7 @@ async function handleGetCredits(args) {
927
1046
  }
928
1047
  }
929
1048
  };
930
-
1049
+
931
1050
  try {
932
1051
  const response = await axios.post(MCP_SERVER_URL, mcpRequest, {
933
1052
  headers: {
@@ -938,13 +1057,13 @@ async function handleGetCredits(args) {
938
1057
 
939
1058
  if (response.data.error) {
940
1059
  const errorMsg = response.data.error.message || response.data.error;
941
- const isAuthError = errorMsg.toString().toLowerCase().includes('api key') ||
1060
+ const isAuthError = errorMsg.toString().toLowerCase().includes('api key') ||
942
1061
  errorMsg.toString().toLowerCase().includes('api_key') ||
943
1062
  errorMsg.toString().toLowerCase().includes('unauthorized');
944
- const isCreditError = errorMsg.toString().toLowerCase().includes('credit') ||
1063
+ const isCreditError = errorMsg.toString().toLowerCase().includes('credit') ||
945
1064
  errorMsg.toString().toLowerCase().includes('quota') ||
946
1065
  errorMsg.toString().toLowerCase().includes('limit exceeded');
947
-
1066
+
948
1067
  let finalErrorMsg = `Credits service error: ${errorMsg}`;
949
1068
  if (!isAuthError && !isCreditError) {
950
1069
  finalErrorMsg += `. Please check the service status or contact support.`;
@@ -955,12 +1074,12 @@ async function handleGetCredits(args) {
955
1074
  const result = response.data.result;
956
1075
  if (result && result.content && result.content[0]) {
957
1076
  const textContent = result.content[0].text;
958
-
1077
+
959
1078
  // Try to parse as JSON for structured data
960
1079
  try {
961
1080
  const parsed = JSON.parse(textContent);
962
1081
  const approximateWordsAvailable = parsed.credits ? Math.floor(parsed.credits * 1000) : 0;
963
-
1082
+
964
1083
  return {
965
1084
  content: [
966
1085
  {
@@ -979,7 +1098,7 @@ async function handleGetCredits(args) {
979
1098
  return result;
980
1099
  }
981
1100
  }
982
-
1101
+
983
1102
  return result;
984
1103
  } catch (error) {
985
1104
  // Handle 401 unauthorized
@@ -987,7 +1106,7 @@ async function handleGetCredits(args) {
987
1106
  const creditsAuthErrorDetails = error.response.data?.message || error.response.data?.result?.content?.[0]?.text || error.message;
988
1107
  throw new Error(`❌ Invalid API key (401)\nDetails: ${creditsAuthErrorDetails}\nPlease check your API key at https://app.i18nagent.ai\n[MCP v${MCP_CLIENT_VERSION}/STDIO/get_credits]`);
989
1108
  }
990
-
1109
+
991
1110
  console.error('Credits check error:', error);
992
1111
  throw new Error(`Unable to check credits: ${error.message}`);
993
1112
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@i18n-agent/mcp-client",
3
- "version": "1.7.9",
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",
3
+ "version": "1.8.1",
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": "mcp-client.js",
6
6
  "bin": {
7
7
  "i18n-agent-install": "install.js"