UNPKG

@civic/nexus-bridge

Version:

Stdio <-> HTTP/SSE MCP bridge with Civic auth handling

77 lines 2.85 kB
/** * claude-code.ts * * Installer for Claude Code application */ import * as fs from 'fs/promises'; import * as path from 'path'; import * as os from 'os'; import { extractCommandInfo } from './util.js'; /** * Get the path to the Claude Code config file (~/.claude.json) */ function getClaudeCodeConfigPath() { const homedir = os.homedir(); return path.join(homedir, '.claude.json'); } /** * Install Nexus Bridge for Claude Code */ export async function installForClaudeCode() { console.log('Installing Nexus Bridge for Claude Code...'); // Get config file path const configPath = getClaudeCodeConfigPath(); console.log(`Looking for Claude Code config at: ${configPath}`); try { // Check if the config file exists await fs.access(configPath); console.log('Existing Claude Code config found, updating...'); // Read and parse the existing config const configContent = await fs.readFile(configPath, 'utf-8'); let config; try { config = JSON.parse(configContent); } catch (parseError) { console.error(`Error parsing config file: ${parseError}`); throw new Error(`The Claude Code config file exists but is not valid JSON. Please check the file at ${configPath}`); } // Initialize mcpServers if it doesn't exist if (!config.mcpServers) { config.mcpServers = {}; } // Only add Civic if it doesn't already exist const mcpServers = config.mcpServers; if (!mcpServers.Civic) { console.log('Adding Civic MCP server to configuration...'); // Extract the command that was used to run this installer const { command, args } = extractCommandInfo(); mcpServers.Civic = { type: "stdio", command, args, env: {} }; } else { console.log('Civic MCP server already configured, skipping...'); // No changes needed, exit without writing to the file return; } // Write the updated config back to file try { await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8'); console.log(`Configuration updated successfully at ${configPath}`); } catch (writeError) { console.error(`Error writing config file: ${writeError}`); throw writeError; } } catch { // If file doesn't exist or can't be accessed console.error(`Claude Code config file not found at ${configPath}`); throw new Error(`Could not find Claude Code configuration. Please make sure Claude Code is installed and has been run at least once.`); } } //# sourceMappingURL=claude-code.js.map