consultant-mcp-server
Version:
MCP Server for Enterprise Architecture Consultants
65 lines (55 loc) • 1.56 kB
JavaScript
/**
* Consultant MCP Server CLI
* 符合MCP规范的命令行入口
*/
const ConsultantMcpServer = require('../index');
const path = require('path');
const fs = require('fs');
// 解析命令行参数
const args = process.argv.slice(2);
let port = process.env.PORT || 3201; // 使用固定端口3201,避免与其他服务冲突
// 基本参数解析
for (let i = 0; i < args.length; i++) {
if (args[i] === '--port' && i + 1 < args.length) {
port = parseInt(args[i + 1], 10);
i++; // 跳过下一个参数
}
}
// 启动服务器
async function main() {
try {
// 确保日志目录存在
const logsDir = path.join(__dirname, '../../logs');
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir, { recursive: true });
}
// 配置服务器
const server = new ConsultantMcpServer({
port,
agentPath: path.join(__dirname, '../../consultant-agent/index.js')
});
// 启动服务器
const actualPort = await server.start();
console.log(JSON.stringify({
status: "running",
port: actualPort
}));
// 处理退出信号
process.on('SIGINT', async () => {
console.log('Shutting down server...');
await server.stop();
process.exit(0);
});
process.on('SIGTERM', async () => {
console.log('Shutting down server...');
await server.stop();
process.exit(0);
});
} catch (error) {
console.error('Error starting server:', error);
process.exit(1);
}
}
// 执行主函数
main();