scripts / setup.js
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const os = require('os');
const pluginDir = path.resolve(__dirname, '..');
const mcpDir = path.join(pluginDir, 'sec-edgar-mcp');
const venvDir = path.join(pluginDir, 'venv');
const isWindows = os.platform() === 'win32';
// 如果您的系統預設 python3 版本低於 3.11,請將底下的 'python3' 改為 'python3.11'
const pythonCmd = isWindows ? 'python' : 'python3';
const venvPip = isWindows ? path.join(venvDir, 'Scripts', 'pip.exe') : path.join(venvDir, 'bin', 'pip');
const venvPython = isWindows ? path.join(venvDir, 'Scripts', 'python.exe') : path.join(venvDir, 'bin', 'python');
try {
console.log('Setting up sec-edgar-mcp environment...');
if (!fs.existsSync(mcpDir)) {
console.log('Cloning sec-edgar-mcp...');
execSync(`git clone https://github.com/stefanoamorelli/sec-edgar-mcp.git "${mcpDir}"`, { stdio: 'inherit' });
} else {
console.log('sec-edgar-mcp already exists. Skipping clone.');
}
// 強制刪除舊的 venv 以確保環境乾淨
if (fs.existsSync(venvDir)) {
console.log('Removing existing venv to ensure a clean setup...');
fs.rmSync(venvDir, { recursive: true, force: true });
}
console.log('Creating virtual environment...');
execSync(`${pythonCmd} -m venv "${venvDir}"`, { stdio: 'inherit' });
console.log('Upgrading pip...');
execSync(`"${venvPython}" -m pip install --upgrade pip`, { stdio: 'inherit' });
console.log('Installing dependencies explicitly...');
// 明確安裝依賴,避免 pyproject.toml 解析失敗或使用了舊版快取
execSync(`"${venvPip}" install 'mcp[cli]>=1.7.1' 'edgartools>=4.4.0' 'requests>=2.31.0'`, { stdio: 'inherit' });
console.log('Installing sec-edgar-mcp in editable mode...');
// 使用 --no-deps 避免 pip 再次去解析依賴而可能失敗
// execSync(`"${venvPip}" install -e --no-deps "${mcpDir}"`, { stdio: 'inherit' });
execSync(`"${venvPip}" install -e "${mcpDir}"`, { stdio: 'inherit' });
execSync(`"${venvPip}" install fastmcp "${mcpDir}"`, { stdio: 'inherit' });
console.log('✅ Setup complete.');
} catch (e) {
console.error('❌ Setup failed:', e.message);
console.error('Note: sec-edgar-mcp strictly requires Python 3.11 or higher.');
process.exit(1);
}scripts / setup.js
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const os = require('os');
const pluginDir = path.resolve(__dirname, '..');
const mcpDir = path.join(pluginDir, 'sec-edgar-mcp');
const venvDir = path.join(pluginDir, 'venv');
const isWindows = os.platform() === 'win32';
// 如果您的系統預設 python3 版本低於 3.11,請將底下的 'python3' 改為 'python3.11'
const pythonCmd = isWindows ? 'python' : 'python3';
const venvPip = isWindows ? path.join(venvDir, 'Scripts', 'pip.exe') : path.join(venvDir, 'bin', 'pip');
const venvPython = isWindows ? path.join(venvDir, 'Scripts', 'python.exe') : path.join(venvDir, 'bin', 'python');
try {
console.log('Setting up sec-edgar-mcp environment...');
if (!fs.existsSync(mcpDir)) {
console.log('Cloning sec-edgar-mcp...');
execSync(`git clone https://github.com/stefanoamorelli/sec-edgar-mcp.git "${mcpDir}"`, { stdio: 'inherit' });
} else {
console.log('sec-edgar-mcp already exists. Skipping clone.');
}
// 強制刪除舊的 venv 以確保環境乾淨
if (fs.existsSync(venvDir)) {
console.log('Removing existing venv to ensure a clean setup...');
fs.rmSync(venvDir, { recursive: true, force: true });
}
console.log('Creating virtual environment...');
execSync(`${pythonCmd} -m venv "${venvDir}"`, { stdio: 'inherit' });
console.log('Upgrading pip...');
execSync(`"${venvPython}" -m pip install --upgrade pip`, { stdio: 'inherit' });
console.log('Installing dependencies explicitly...');
// 明確安裝依賴,避免 pyproject.toml 解析失敗或使用了舊版快取
execSync(`"${venvPip}" install 'mcp[cli]>=1.7.1' 'edgartools>=4.4.0' 'requests>=2.31.0'`, { stdio: 'inherit' });
console.log('Installing sec-edgar-mcp in editable mode...');
// 使用 --no-deps 避免 pip 再次去解析依賴而可能失敗
// execSync(`"${venvPip}" install -e --no-deps "${mcpDir}"`, { stdio: 'inherit' });
execSync(`"${venvPip}" install -e "${mcpDir}"`, { stdio: 'inherit' });
execSync(`"${venvPip}" install fastmcp "${mcpDir}"`, { stdio: 'inherit' });
console.log('✅ Setup complete.');
} catch (e) {
console.error('❌ Setup failed:', e.message);
console.error('Note: sec-edgar-mcp strictly requires Python 3.11 or higher.');
process.exit(1);
}