Super Gateway 可将 MCP 标准输入服务器转换为 SSE(Server-Sent Events)或 WebSocket 服务,极大简化了与网页或远程客户端的集成与调试工作。借助 Super Gateway,您能轻松地将任意 MCP 标准输入服务器以现代网络协议接口的形式对外暴露。
创建一个简单的 MCP 服务器:
import { createServer } from 'http';
import { Server } from 'supergateway';
createServer((req, res) => {
// 处理请求逻辑
}).listen(8000);
// 初始化 Super Gateway 服务
const superGateway = new Server({
input: process.stdin,
output: process.stdout,
onError: (error) => console.error('Super Gateway 错误:', error),
});
运行 MCP 服务器:
node index.js
npm install -g supergateway
import { createServer } from 'http';
import { Server } from 'supergateway';
createServer((req, res) => {
if (req.url === '/api') {
// 发送实时更新
setInterval(() => {
res.write(`data: ${new Date().toISOString()}\n\n`);
}, 1000);
}
}).listen(8000);
const superGateway = new Server({
input: process.stdin,
output: process.stdout,
});
import { createServer } from 'http';
import { WebSocketServer } from 'ws';
import { Server } from 'supergateway';
const server = createServer();
const wss = new WebSocketServer(server);
wss.on('connection', (ws) => {
// 处理 WebSocket 连接逻辑
});
server.listen(8000);
const superGateway = new Server({
input: process.stdin,
output: process.stdout,
});
以下是 Super Gateway 的完整配置参数:
属性 | 详情 |
---|---|
port |
监听的端口,默认值为 8000。 |
mode |
运行模式,可选值为 'ssea' 或 'ws' 。 |
input |
标准输入流(默认为 process.stdin )。 |
output |
标准输出流(默认为 process.stdout )。 |
onError |
错误处理回调函数。 |
项目采用 MIT 许可证,详见 LICENSE 文件。
感谢您使用 Super Gateway!如需更多帮助,请参考我们的 GitHub 仓库。