scripts / setup.js
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const pluginRoot = path.resolve(__dirname, '..');
const mcpServerDir = path.resolve(pluginRoot, '.mcp-server');
function run(cmd, cwd = pluginRoot) {
console.log(`Running: ${cmd} in ${cwd}`);
try {
execSync(cmd, { cwd, stdio: 'inherit' });
} catch (e) {
console.error(`Error executing command: ${cmd}`);
process.exit(1);
}
}
function setup() {
// 1. Ensure source directory exists
if (!fs.existsSync(mcpServerDir)) {
console.log('Cloning mcp-server-tree-sitter...');
run(`git clone https://github.com/wrale/mcp-server-tree-sitter.git .mcp-server`, pluginRoot);
} else {
console.log('.mcp-server directory already exists.');
}
// 2. Force recreate venv to ensure a clean state and correct versions
const venvDir = path.join(mcpServerDir, '.venv');
if (fs.existsSync(venvDir)) {
console.log('Removing existing virtual environment to ensure clean install...');
fs.rmSync(venvDir, { recursive: true, force: true });
}
console.log('Creating new virtual environment...');
// Use relative path '.venv' since cwd is mcpServerDir
run(`python3 -m venv .venv`, mcpServerDir);
const pythonExec = path.join(venvDir, 'bin', 'python');
// Double check if the executable exists before proceeding
if (!fs.existsSync(pythonExec)) {
// Fallback for some systems where it might be in Scripts/python.exe (Windows),
// but we are on Linux. However, let's check if bin/python exists.
console.error(`Error: Python executable not found at ${pythonExec}`);
process.exit(1);
}
console.log(`Installing base tools using ${pythonExec}...`);
run(`${pythonExec} -m pip install --upgrade pip setuptools wheel`, mcpServerDir);
console.log(`Installing compatible MCP version (mcp < 2)...`);
run(`${pythonExec} -m pip install "mcp<2"`, mcpServerDir);
console.log(`Installing project dependencies...`);
run(`${pythonExec} -m pip install .`, mcpServerDir);
console.log('Setup complete.');
}
setup();
scripts / setup.js
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const pluginRoot = path.resolve(__dirname, '..');
const mcpServerDir = path.resolve(pluginRoot, '.mcp-server');
function run(cmd, cwd = pluginRoot) {
console.log(`Running: ${cmd} in ${cwd}`);
try {
execSync(cmd, { cwd, stdio: 'inherit' });
} catch (e) {
console.error(`Error executing command: ${cmd}`);
process.exit(1);
}
}
function setup() {
// 1. Ensure source directory exists
if (!fs.existsSync(mcpServerDir)) {
console.log('Cloning mcp-server-tree-sitter...');
run(`git clone https://github.com/wrale/mcp-server-tree-sitter.git .mcp-server`, pluginRoot);
} else {
console.log('.mcp-server directory already exists.');
}
// 2. Force recreate venv to ensure a clean state and correct versions
const venvDir = path.join(mcpServerDir, '.venv');
if (fs.existsSync(venvDir)) {
console.log('Removing existing virtual environment to ensure clean install...');
fs.rmSync(venvDir, { recursive: true, force: true });
}
console.log('Creating new virtual environment...');
// Use relative path '.venv' since cwd is mcpServerDir
run(`python3 -m venv .venv`, mcpServerDir);
const pythonExec = path.join(venvDir, 'bin', 'python');
// Double check if the executable exists before proceeding
if (!fs.existsSync(pythonExec)) {
// Fallback for some systems where it might be in Scripts/python.exe (Windows),
// but we are on Linux. However, let's check if bin/python exists.
console.error(`Error: Python executable not found at ${pythonExec}`);
process.exit(1);
}
console.log(`Installing base tools using ${pythonExec}...`);
run(`${pythonExec} -m pip install --upgrade pip setuptools wheel`, mcpServerDir);
console.log(`Installing compatible MCP version (mcp < 2)...`);
run(`${pythonExec} -m pip install "mcp<2"`, mcpServerDir);
console.log(`Installing project dependencies...`);
run(`${pythonExec} -m pip install .`, mcpServerDir);
console.log('Setup complete.');
}
setup();