#!/usr/bin/env node
/**
* Generate VSCode configuration for NDB MCP Server
* This script reads the current .env configuration and generates
* appropriate VSCode settings.json content
*/
import fs from 'fs';
import path from 'path';
import readlineSync from 'readline-sync';
function parseEnvFile(filePath) {
if (!fs.existsSync(filePath)) {
return null;
}
const content = fs.readFileSync(filePath, 'utf-8');
const env = {};
content.split('\n').forEach(line => {
line = line.trim();
if (line && !line.startsWith('#')) {
const [key, ...valueParts] = line.split('=');
if (key && valueParts.length > 0) {
let value = valueParts.join('=');
// Remove quotes if present
if ((value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))) {
value = value.slice(1, -1);
}
env[key.trim()] = value;
}
}
});
return env;
}
function generateVSCodeConfig(env, serverPath) {
const config = {
"mcp.servers": {
"ndb": {
"command": "node",
"args": [serverPath],
"env": {}
}
}
};
// Add required environment variables
if (env.NDB_BASE_URL) config["mcp.servers"]["ndb"]["env"]["NDB_BASE_URL"] = env.NDB_BASE_URL;
if (env.NDB_USERNAME) config["mcp.servers"]["ndb"]["env"]["NDB_USERNAME"] = env.NDB_USERNAME;
if (env.NDB_PASSWORD) config["mcp.servers"]["ndb"]["env"]["NDB_PASSWORD"] = env.NDB_PASSWORD;
if (env.NDB_TOKEN) config["mcp.servers"]["ndb"]["env"]["NDB_TOKEN"] = env.NDB_TOKEN;
if (env.NDB_VERIFY_SSL) config["mcp.servers"]["ndb"]["env"]["NDB_VERIFY_SSL"] = env.NDB_VERIFY_SSL;
// Add custom instructions settings
if (env.NDB_CUSTOM_INSTRUCTIONS) config["mcp.servers"]["ndb"]["env"]["NDB_CUSTOM_INSTRUCTIONS"] = env.NDB_CUSTOM_INSTRUCTIONS;
if (env.NDB_CONFIRM_CHANGES) config["mcp.servers"]["ndb"]["env"]["NDB_CONFIRM_CHANGES"] = env.NDB_CONFIRM_CHANGES;
if (env.NDB_PAUSE_ON_ERROR) config["mcp.servers"]["ndb"]["env"]["NDB_PAUSE_ON_ERROR"] = env.NDB_PAUSE_ON_ERROR;
if (env.NDB_RESPONSE_STYLE) config["mcp.servers"]["ndb"]["env"]["NDB_RESPONSE_STYLE"] = env.NDB_RESPONSE_STYLE;
return config;
}
async function main() {
console.log('š§ VSCode Configuration Generator for NDB MCP Server');
console.log('===================================================\n');
// Find available .env files
const envFiles = ['.env', '.env.production', '.env.development', '.env.test'];
const foundEnvFiles = envFiles.filter(file => fs.existsSync(path.resolve(process.cwd(), file)));
if (foundEnvFiles.length === 0) {
console.log('ā No .env files found. Run "npm run configure" first.');
return;
}
// Let user choose which env file to use
let selectedEnvFile;
if (foundEnvFiles.length === 1) {
selectedEnvFile = foundEnvFiles[0];
console.log(`š Using ${selectedEnvFile}`);
} else {
console.log('š Multiple environment files found:');
foundEnvFiles.forEach((file, index) => {
console.log(` ${index + 1}. ${file}`);
});
const choice = readlineSync.questionInt(`Select environment file (1-${foundEnvFiles.length}): `) - 1;
if (choice < 0 || choice >= foundEnvFiles.length) {
console.log('ā Invalid selection');
return;
}
selectedEnvFile = foundEnvFiles[choice];
}
// Parse the selected env file
const env = parseEnvFile(path.resolve(process.cwd(), selectedEnvFile));
if (!env) {
console.log(`ā Could not parse ${selectedEnvFile}`);
return;
}
// Get server path
const defaultServerPath = path.resolve(process.cwd(), 'dist/index.js');
const serverPath = readlineSync.question(`Server path [${defaultServerPath}]: `) || defaultServerPath;
// Generate configuration
const vscodeConfig = generateVSCodeConfig(env, serverPath);
console.log('\nš Generated VSCode Configuration:');
console.log('===================================');
console.log(JSON.stringify(vscodeConfig, null, 2));
// Ask if user wants to save to file
const saveToFile = readlineSync.question('\nSave to .vscode/settings.json? (yes/no) [no]: ').toLowerCase();
if (saveToFile === 'yes' || saveToFile === 'y') {
const vscodeDir = path.resolve(process.cwd(), '.vscode');
const settingsFile = path.resolve(vscodeDir, 'settings.json');
// Create .vscode directory if it doesn't exist
if (!fs.existsSync(vscodeDir)) {
fs.mkdirSync(vscodeDir, { recursive: true });
}
// Read existing settings if they exist
let existingSettings = {};
if (fs.existsSync(settingsFile)) {
try {
const content = fs.readFileSync(settingsFile, 'utf-8');
existingSettings = JSON.parse(content);
} catch (error) {
console.log('ā ļø Could not parse existing settings.json, will create new file');
}
}
// Merge configurations
const mergedSettings = { ...existingSettings, ...vscodeConfig };
// Write to file
fs.writeFileSync(settingsFile, JSON.stringify(mergedSettings, null, 2));
console.log(`ā
Configuration saved to ${settingsFile}`);
console.log('\nšÆ Next Steps:');
console.log('1. Restart VSCode to load the new configuration');
console.log('2. Open a workspace where you want to use the NDB assistant');
console.log('3. Use Claude Agent features to interact with your NDB environment');
} else {
console.log('\nš” To use this configuration:');
console.log('1. Copy the JSON above');
console.log('2. Add it to your .vscode/settings.json file');
console.log('3. Restart VSCode');
}
console.log('\nš For more information:');
console.log('- Configuration Guide: docs/configuration-guide.md');
console.log('- Custom Instructions: docs/custom-instructions-examples.md');
console.log('- Test configuration: npm run test:configuration');
}
if (import.meta.url === `file://${process.argv[1]}`) {
main().catch(console.error);
}