@i18n-agent/mcp-client 1.8.4 → 1.8.6

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/install.js +68 -24
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -195,60 +195,99 @@ exec node "${mcpClientPath}"`;
195
195
  return wrapperPath;
196
196
  }
197
197
 
198
- function updateClaudeConfig(configPath) {
198
+ function updateClaudeConfig(configPath, ideKey = 'claude') {
199
199
  let config = {};
200
-
200
+ let existingApiKey = "";
201
+
201
202
  // Read existing config if it exists
202
203
  if (fs.existsSync(configPath)) {
203
204
  try {
204
205
  const content = fs.readFileSync(configPath, 'utf8');
205
206
  config = JSON.parse(content);
207
+
208
+ // Preserve existing API key if present
209
+ if (config.mcpServers?.["i18n-agent"]?.env?.API_KEY) {
210
+ existingApiKey = config.mcpServers["i18n-agent"].env.API_KEY;
211
+ console.log(' 🔑 Preserving existing API key');
212
+ }
206
213
  } catch (error) {
207
214
  console.warn(`Warning: Could not parse existing config at ${configPath}`);
208
215
  }
209
216
  }
210
-
217
+
211
218
  // Ensure mcpServers exists
212
219
  if (!config.mcpServers) {
213
220
  config.mcpServers = {};
214
221
  }
215
-
216
- // Detect if we need a wrapper script (for nvm users)
222
+
217
223
  const nodeEnv = detectNodeEnvironment();
218
- const claudeDir = path.join(os.homedir(), '.claude');
219
-
220
- if (nodeEnv.isNvm) {
221
- // Create wrapper script for nvm users
222
- console.log(' 🔧 Detected nvm environment, creating wrapper script...');
223
- const wrapperPath = createWrapperScript(claudeDir);
224
-
225
- config.mcpServers["i18n-agent"] = {
226
- command: wrapperPath,
227
- env: {
228
- MCP_SERVER_URL: "https://mcp.i18nagent.ai",
229
- API_KEY: ""
224
+ const { mcpClientPath } = getMcpClientPaths();
225
+
226
+ // Claude Code CLI works better with command+args format (not wrapper)
227
+ if (ideKey === 'claude-code') {
228
+ if (nodeEnv.isNvm) {
229
+ // For nvm, use absolute node path with args
230
+ console.log(' 🔧 Using direct node path for Claude Code CLI');
231
+ config.mcpServers["i18n-agent"] = {
232
+ command: nodeEnv.nodePath,
233
+ args: [mcpClientPath],
234
+ env: {
235
+ MCP_SERVER_URL: "https://mcp.i18nagent.ai",
236
+ API_KEY: existingApiKey || ""
237
+ }
238
+ };
239
+ } else {
240
+ // For system node, use 'node' with args
241
+ const baseConfig = createMCPConfig();
242
+ config.mcpServers["i18n-agent"] = baseConfig.mcpServers["i18n-agent"];
243
+ if (existingApiKey) {
244
+ config.mcpServers["i18n-agent"].env.API_KEY = existingApiKey;
230
245
  }
231
- };
246
+ }
232
247
  } else {
233
- // Standard configuration for system node
234
- const baseConfig = createMCPConfig();
235
- config.mcpServers["i18n-agent"] = baseConfig.mcpServers["i18n-agent"];
248
+ // Claude Desktop - use wrapper script for compatibility
249
+ if (nodeEnv.isNvm) {
250
+ const claudeDir = path.join(os.homedir(), '.claude');
251
+ console.log(' 🔧 Detected nvm environment, creating wrapper script...');
252
+ const wrapperPath = createWrapperScript(claudeDir);
253
+
254
+ config.mcpServers["i18n-agent"] = {
255
+ command: wrapperPath,
256
+ env: {
257
+ MCP_SERVER_URL: "https://mcp.i18nagent.ai",
258
+ API_KEY: existingApiKey || ""
259
+ }
260
+ };
261
+ } else {
262
+ const baseConfig = createMCPConfig();
263
+ config.mcpServers["i18n-agent"] = baseConfig.mcpServers["i18n-agent"];
264
+ if (existingApiKey) {
265
+ config.mcpServers["i18n-agent"].env.API_KEY = existingApiKey;
266
+ }
267
+ }
236
268
  }
237
-
269
+
238
270
  // Write updated config
239
271
  fs.mkdirSync(path.dirname(configPath), { recursive: true });
240
272
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
241
-
273
+
242
274
  return config;
243
275
  }
244
276
 
245
277
  function updateGenericMCPConfig(configPath) {
246
278
  let config = {};
279
+ let existingApiKey = "";
247
280
 
248
281
  if (fs.existsSync(configPath)) {
249
282
  try {
250
283
  const existing = fs.readFileSync(configPath, 'utf8');
251
284
  config = JSON.parse(existing);
285
+
286
+ // Preserve existing API key if present
287
+ if (config.mcpServers?.["i18n-agent"]?.env?.API_KEY) {
288
+ existingApiKey = config.mcpServers["i18n-agent"].env.API_KEY;
289
+ console.log(' 🔑 Preserving existing API key');
290
+ }
252
291
  } catch (error) {
253
292
  console.warn(`Warning: Could not parse existing config at ${configPath}`);
254
293
  }
@@ -261,6 +300,11 @@ function updateGenericMCPConfig(configPath) {
261
300
  const baseConfig = createMCPConfig();
262
301
  config.mcpServers["i18n-agent"] = baseConfig.mcpServers["i18n-agent"];
263
302
 
303
+ // Preserve existing API key
304
+ if (existingApiKey) {
305
+ config.mcpServers["i18n-agent"].env.API_KEY = existingApiKey;
306
+ }
307
+
264
308
  // Write config
265
309
  fs.mkdirSync(path.dirname(configPath), { recursive: true });
266
310
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
@@ -314,7 +358,7 @@ For manual setup instructions, visit: https://docs.i18nagent.ai/setup
314
358
  console.log(`⚙️ Configuring ${ide.name}...`);
315
359
 
316
360
  if (ide.key === 'claude' || ide.key === 'claude-code') {
317
- updateClaudeConfig(ide.configPath);
361
+ updateClaudeConfig(ide.configPath, ide.key);
318
362
  } else {
319
363
  updateGenericMCPConfig(ide.configPath);
320
364
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-agent/mcp-client",
3
- "version": "1.8.4",
3
+ "version": "1.8.6",
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": "mcp-client.js",
6
6
  "bin": {