UNPKG

@cequenceai/mcp-cli

Version:

Cequence MCP CLI - Command-line tool for setting up Cequence MCP servers with AI clients

105 lines (89 loc) 3.02 kB
import * as fs from 'fs-extra'; import * as path from 'path'; import * as os from 'os'; import { McpServerConfig, WindsurfConfig, SetupResult } from '../types'; import { sanitizeServerName } from '../utils/validation'; /** * Gets the Windsurf MCP configuration file path */ function getWindsurfMcpConfigPath(): string { const homeDir = os.homedir(); return path.join(homeDir, '.codeium', 'windsurf', 'mcp_config.json'); } /** * Reads the current Windsurf MCP configuration */ async function readWindsurfMcpConfig(): Promise<any> { const configPath = getWindsurfMcpConfigPath(); try { if (await fs.pathExists(configPath)) { const content = await fs.readFile(configPath, 'utf-8'); return JSON.parse(content); } } catch (error) { // If file doesn't exist or is invalid JSON, return empty object console.warn('Could not read existing Windsurf MCP configuration, creating new configuration'); } return {}; } /** * Writes the Windsurf MCP configuration */ async function writeWindsurfMcpConfig(config: any): Promise<void> { const configPath = getWindsurfMcpConfigPath(); const configDir = path.dirname(configPath); // Ensure the directory exists await fs.ensureDir(configDir); // Write configuration with proper formatting await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8'); } /** * Sets up Cequence MCP server configuration for Windsurf IDE */ export async function setupWindsurf(config: McpServerConfig): Promise<SetupResult> { try { // Sanitize the server name for use as a key const serverKey = sanitizeServerName(config.name).toLowerCase().replace(/\s+/g, '-'); // Read existing MCP configuration const mcpConfig = await readWindsurfMcpConfig(); // Initialize mcpServers if it doesn't exist if (!mcpConfig.mcpServers) { mcpConfig.mcpServers = {}; } // Create the MCP server configuration similar to Composio's working format const serverConfig: any = { command: "npx", args: [ "-y", "@cequenceai/mcp-remote", config.url, "--timeout", "120000", "--retries", "3" ], env: { npm_config_yes: "true" } }; // Add API key as environment variable if provided if (config.apiKey) { serverConfig.env.API_KEY = config.apiKey; serverConfig.env.MCP_API_KEY = config.apiKey; } // Add the server configuration mcpConfig.mcpServers[serverKey] = serverConfig; // Write the updated configuration await writeWindsurfMcpConfig(mcpConfig); return { success: true, message: `Cequence MCP server "${config.name}" configured successfully for Windsurf IDE`, configPath: getWindsurfMcpConfigPath() }; } catch (error) { return { success: false, message: `Failed to configure Cequence MCP server for Windsurf IDE: ${error instanceof Error ? error.message : String(error)}` }; } }