uns-mcp-server
Version:
Pure JavaScript MCP server for Unstructured.io - No Python required!
132 lines (116 loc) • 4.33 kB
JavaScript
/**
* Post-install setup script for uns-mcp-server
* Checks Python dependencies and provides setup instructions
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
let chalk;
try {
chalk = require('chalk');
} catch (e) {
// Fallback if chalk is not available
chalk = {
green: (text) => text,
red: (text) => text,
yellow: (text) => text,
blue: (text) => text,
bold: {
blue: (text) => text
},
gray: (text) => text,
cyan: (text) => text
};
}
function checkPython() {
try {
const version = execSync('python3 --version', { encoding: 'utf8' });
console.log(chalk.green(`✓ Python installed: ${version.trim()}`));
return true;
} catch (e) {
console.log(chalk.red('✗ Python 3.8+ not found'));
console.log(chalk.yellow('Please install Python 3.8 or higher from https://python.org'));
return false;
}
}
function checkPip() {
try {
execSync('python3 -m pip --version', { encoding: 'utf8', stdio: 'ignore' });
console.log(chalk.green('✓ pip is available'));
return true;
} catch (e) {
console.log(chalk.red('✗ pip not found'));
console.log(chalk.yellow('Installing pip...'));
try {
execSync('python3 -m ensurepip', { stdio: 'inherit' });
return true;
} catch (e2) {
console.log(chalk.red('Failed to install pip automatically'));
return false;
}
}
}
function installPythonPackage() {
try {
console.log(chalk.blue('Checking for uns_mcp Python package...'));
execSync('python3 -c "import uns_mcp"', { stdio: 'ignore' });
console.log(chalk.green('✓ uns_mcp Python package already installed'));
} catch (e) {
console.log(chalk.yellow('Installing uns_mcp Python package...'));
try {
execSync('python3 -m pip install uns_mcp', { stdio: 'inherit' });
console.log(chalk.green('✓ uns_mcp installed successfully'));
} catch (e2) {
console.log(chalk.red('Failed to install uns_mcp automatically'));
console.log(chalk.yellow('Please run manually: pip install uns_mcp'));
}
}
}
function createEnvFile() {
const envPath = path.join(process.cwd(), '.env');
const examplePath = path.join(__dirname, '..', '.env.example');
if (!fs.existsSync(envPath) && fs.existsSync(examplePath)) {
console.log(chalk.blue('Creating .env file from template...'));
const content = fs.readFileSync(examplePath, 'utf8');
fs.writeFileSync(envPath, content);
console.log(chalk.green('✓ Created .env file'));
console.log(chalk.yellow('⚠ Please edit .env and add your API keys'));
}
}
function printInstructions() {
console.log('\n' + chalk.bold.blue('='.repeat(60)));
console.log(chalk.bold.blue('Unstructured MCP Server Setup Complete!'));
console.log(chalk.bold.blue('='.repeat(60)) + '\n');
console.log(chalk.bold('Quick Start:'));
console.log(chalk.gray('1. Set your API key:'));
console.log(chalk.cyan(' export UNSTRUCTURED_API_KEY=your_key_here'));
console.log(chalk.gray(' Or add it to .env file\n'));
console.log(chalk.gray('2. Run the server:'));
console.log(chalk.cyan(' npx uns-mcp-server # STDIO mode (for Claude Desktop)'));
console.log(chalk.cyan(' npx uns-mcp-server --sse # SSE mode (for development)\n'));
console.log(chalk.gray('3. Add to Claude Desktop config:'));
console.log(chalk.cyan(' claude mcp add uns-mcp npx uns-mcp-server\n'));
console.log(chalk.bold('Documentation:'));
console.log(chalk.gray('- README: https://github.com/yourusername/uns-mcp-server'));
console.log(chalk.gray('- Agent: See agents/document-processor.md'));
console.log(chalk.gray('- Examples: See examples/ directory\n'));
console.log(chalk.bold('Get API Key:'));
console.log(chalk.gray('Sign up at: https://unstructured.io\n'));
}
// Main setup
async function setup() {
console.log(chalk.bold.blue('\n🚀 Setting up Unstructured MCP Server...\n'));
const pythonOk = checkPython();
if (pythonOk) {
const pipOk = checkPip();
if (pipOk) {
installPythonPackage();
}
}
createEnvFile();
printInstructions();
}
// Run setup if called directly or as post-install
if (require.main === module || process.env.npm_lifecycle_event === 'postinstall') {
setup().catch(console.error);
}