@i18n-agent/mcp-client
Version:
MCP client for i18n-agent translation service with async job support and enhanced progress tracking - supports Claude, Cursor, VS Code, and other AI IDEs
277 lines (223 loc) โข 7.63 kB
JavaScript
/**
* i18n-agent MCP Client Installer
* Installs the MCP client to work with Claude, Cursor, VS Code and other AI IDEs
*/
import fs from 'fs';
import path from 'path';
import os from 'os';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Supported IDE configurations
const IDE_CONFIGS = {
claude: {
name: 'Claude Desktop',
configPath: path.join(os.homedir(), 'Library/Application Support/Claude/claude_desktop_config.json'),
displayPath: '~/Library/Application Support/Claude/claude_desktop_config.json'
},
cursor: {
name: 'Cursor',
configPath: path.join(os.homedir(), '.cursor/mcp_settings.json'),
displayPath: '~/.cursor/mcp_settings.json'
},
vscode: {
name: 'VS Code (with MCP extension)',
configPath: path.join(os.homedir(), '.vscode/mcp_settings.json'),
displayPath: '~/.vscode/mcp_settings.json'
}
};
console.log(`
๐ i18n-agent MCP Client Installer
===================================
This installer will set up the i18n-agent MCP client for your AI IDE.
Features:
โจ Text translation with cultural context
๐ File translation (JSON, YAML, CSV, MD, etc.)
๐ฐ Credit balance checking
๐ 30+ language support with quality tiers
`);
async function detectAvailableIDEs() {
const available = [];
for (const [key, config] of Object.entries(IDE_CONFIGS)) {
const configDir = path.dirname(config.configPath);
if (fs.existsSync(configDir)) {
available.push({ key, ...config });
}
}
return available;
}
function createMCPConfig() {
const mcpClientPath = path.resolve(__dirname, 'mcp-client.js');
return {
mcpServers: {
"i18n-agent": {
command: "node",
args: [mcpClientPath],
env: {
MCP_SERVER_URL: "https://mcp.i18nagent.ai",
API_KEY: ""
}
}
}
};
}
function detectNodeEnvironment() {
// Check if using nvm or other version managers
const nvmDir = process.env.NVM_DIR || path.join(os.homedir(), '.nvm');
const nodeVersion = process.version;
const nodePath = process.execPath;
return {
isNvm: nodePath.includes('.nvm') || nodePath.includes('nvm'),
nodePath,
nodeVersion
};
}
function createWrapperScript(targetDir) {
const nodeEnv = detectNodeEnvironment();
const wrapperPath = path.join(targetDir, 'run-mcp.sh');
const mcpClientPath = path.join(targetDir, 'node_modules', '@i18n-agent', 'mcp-client', 'mcp-client.js');
let wrapperContent;
if (nodeEnv.isNvm) {
// For nvm users, we need to set up the PATH properly
wrapperContent = `#!/bin/bash
# Wrapper script for i18n-agent MCP client (handles nvm environments)
export PATH="${path.dirname(nodeEnv.nodePath)}:$PATH"
cd "${targetDir}"
exec node "${mcpClientPath}"`;
} else {
// For system node installations
wrapperContent = `#!/bin/bash
# Wrapper script for i18n-agent MCP client
cd "${targetDir}"
exec node "${mcpClientPath}"`;
}
fs.writeFileSync(wrapperPath, wrapperContent, { mode: 0o755 });
return wrapperPath;
}
function updateClaudeConfig(configPath) {
let config = {};
// Read existing config if it exists
if (fs.existsSync(configPath)) {
try {
const content = fs.readFileSync(configPath, 'utf8');
config = JSON.parse(content);
} catch (error) {
console.warn(`Warning: Could not parse existing config at ${configPath}`);
}
}
// Ensure mcpServers exists
if (!config.mcpServers) {
config.mcpServers = {};
}
// Detect if we need a wrapper script (for nvm users)
const nodeEnv = detectNodeEnvironment();
const claudeDir = path.join(os.homedir(), '.claude');
if (nodeEnv.isNvm) {
// Create wrapper script for nvm users
console.log(' ๐ง Detected nvm environment, creating wrapper script...');
const wrapperPath = createWrapperScript(claudeDir);
config.mcpServers["i18n-agent"] = {
command: wrapperPath,
env: {
MCP_SERVER_URL: "https://mcp.i18nagent.ai",
API_KEY: ""
}
};
} else {
// Standard configuration for system node
const mcpClientPath = path.join(claudeDir, 'node_modules', '@i18n-agent', 'mcp-client', 'mcp-client.js');
config.mcpServers["i18n-agent"] = {
command: "node",
args: [mcpClientPath],
cwd: claudeDir,
env: {
MCP_SERVER_URL: "https://mcp.i18nagent.ai",
API_KEY: ""
}
};
}
// Write updated config
fs.mkdirSync(path.dirname(configPath), { recursive: true });
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
return config;
}
function updateGenericMCPConfig(configPath) {
const config = createMCPConfig();
// Write config
fs.mkdirSync(path.dirname(configPath), { recursive: true });
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
return config;
}
async function main() {
try {
console.log('๐ Detecting available AI IDEs...\n');
const availableIDEs = await detectAvailableIDEs();
if (availableIDEs.length === 0) {
console.log(`โ No supported AI IDEs detected.
Supported IDEs:
- Claude Desktop (macOS)
- Cursor
- VS Code (with MCP extension)
Manual setup:
1. Create the configuration file for your IDE
2. Add the i18n-agent MCP server configuration
3. Set your API_KEY environment variable
For manual setup instructions, visit: https://docs.i18nagent.ai/setup
`);
process.exit(1);
}
console.log('โ
Available AI IDEs:');
availableIDEs.forEach((ide, index) => {
console.log(`${index + 1}. ${ide.name}`);
});
console.log('\n๐ Installing for all available IDEs...\n');
let installCount = 0;
for (const ide of availableIDEs) {
try {
console.log(`โ๏ธ Configuring ${ide.name}...`);
if (ide.key === 'claude') {
updateClaudeConfig(ide.configPath);
} else {
updateGenericMCPConfig(ide.configPath);
}
console.log(`โ
${ide.name} configured successfully!`);
console.log(` Config: ${ide.displayPath}\n`);
installCount++;
} catch (error) {
console.error(`โ Failed to configure ${ide.name}: ${error.message}\n`);
}
}
if (installCount > 0) {
console.log(`๐ Installation complete! Configured ${installCount} IDE(s).
๐ Important: Set your API key
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
You need to set your API key to use the translation service:
1. Get your API key from: https://app.i18nagent.ai
2. Set it as an environment variable:
export API_KEY=your-api-key-here
Or add it to your shell profile (~/.bashrc, ~/.zshrc):
echo 'export API_KEY=your-api-key-here' >> ~/.zshrc
๐ Restart your IDE
After setting the API key, restart your AI IDE to load the new configuration.
๐งช Test the installation
Try these commands in your AI IDE:
- "Translate 'Hello world' to Spanish"
- "Check my translation credits"
- "List supported languages"
๐ Documentation: https://docs.i18nagent.ai
๐ Issues: https://github.com/i18n-agent/mcp-client/issues
`);
} else {
console.error('โ Installation failed for all IDEs. Please check the error messages above.');
process.exit(1);
}
} catch (error) {
console.error(`โ Installation failed: ${error.message}`);
process.exit(1);
}
}
// Handle command line execution
if (import.meta.url === `file://${process.argv[1]}`) {
main();
}
export { main, IDE_CONFIGS, createMCPConfig };