UNPKG

lmstudio-mcp-server

Version:

LM Studio MCP server with concurrent multi-agent support and memory safety

61 lines (50 loc) 1.74 kB
#!/usr/bin/env node /** * LM Studio MCP Server - Main Entry Point * This is the main module that can be required or executed */ const path = require('path'); const { spawn } = require('child_process'); // Export the main functionality for programmatic use class LMStudioMCP { constructor(options = {}) { this.options = { apiBase: options.apiBase || process.env.LMSTUDIO_API_BASE || 'http://localhost:1234/v1', logLevel: options.logLevel || process.env.LOG_LEVEL || 'INFO', installDir: options.installDir || path.join(require('os').homedir(), '.lmstudio-mcp'), ...options }; } async start() { // Delegate to the main runner const runnerPath = path.join(__dirname, 'bin', 'lmstudio-mcp.js'); const env = { ...process.env, LMSTUDIO_API_BASE: this.options.apiBase, LOG_LEVEL: this.options.logLevel }; const args = []; if (this.options.installDir) { args.push('--install-dir', this.options.installDir); } const child = spawn('node', [runnerPath, ...args], { env, stdio: 'inherit' }); return new Promise((resolve, reject) => { child.on('close', (code) => { if (code === 0) resolve(); else reject(new Error(`Process exited with code ${code}`)); }); child.on('error', reject); }); } } // Export for require() usage module.exports = LMStudioMCP; module.exports.LMStudioMCP = LMStudioMCP; // CLI execution if (require.main === module) { // Run the CLI version require('./bin/lmstudio-mcp.js'); }