* 启动服务器
()
| 65 | * 启动服务器 |
| 66 | */ |
| 67 | async start(): Promise<void> { |
| 68 | const port = this.config.port || 3001; |
| 69 | const host = this.config.host || 'localhost'; |
| 70 | |
| 71 | if (this.config.transport === 'ws') { |
| 72 | this.server = createServer(); |
| 73 | this.wsServer = new WebSocketServer({ server: this.server }); |
| 74 | |
| 75 | this.wsServer.on('connection', (ws, request) => { |
| 76 | this.handleConnection(ws, request); |
| 77 | }); |
| 78 | |
| 79 | this.server.listen(port, host, () => { |
| 80 | console.log(`MCP Server listening on ws://${host}:${port}`); |
| 81 | this.emit('started', { host, port }); |
| 82 | }); |
| 83 | } else if (this.config.transport === 'stdio') { |
| 84 | this.handleStdioConnection(); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * 停止服务器 |
no test coverage detected