使用说明
MCP服务器SSE-多租户
模型上下文协议 (MCP) 服务器使用服务器发送事件 (SSE) 进行通信,并通过 URL 路径支持多租户。
🚀 特征
- Protocolo MCP:实现社交模型上下文协议的协议
- **SSE(服务器发送事件)**通过HTTP实时通信
- 多住户: 通过 URL 路径支持多个客户端
- HTTP 工具外部 HTTP 请求的集成工具
- TypeScript用 TypeScript 开发,具有完整的打字功能
📋 先决条件
- Node.js 18+
- npm瓯纱
🛠️ 安装
- 克隆仓库 :
git clone <repository-url>
cd mcp-server-sse
- 安装依赖关系 :
npm install
- 编译工程 :
npm run build
🚀 执行
开发
npm run dev
生产
npm run build
npm start
🌐 端点
健康检查
GET /health
挂牌租户
GET /tenants
配置 Tenant
GET /{tenant_id}
连接到 MCP 服务器 (SSE)
GET /{tenant_id}/mcp
运行工具
POST /{tenant_id}/execute
🔧 租户配置
- 客户1:
http://localhost:3000/cliente1 - 客户2:
http://localhost:3000/cliente2
📖 谎言
1.租户
curl http://localhost:3000/cliente1
2. 通过SSE连接到MCP服务器
curl -N http://localhost:3000/cliente1/mcp
3. 运行 HTTP 工具
curl -X POST http://localhost:3000/cliente1/execute \
-H "Content-Type: application/json" \
-d '{
"tool": "http_request",
"arguments": {
"method": "GET",
"url": "https://api.exemplo.com/dados"
}
}'
🏗️ 建筑师
src/
├── index.ts # Ponto de entrada
├── http-server.ts # Servidor HTTP Express
├── mcp-server.ts # Servidor MCP principal
├── http-tool.ts # Ferramenta HTTP
├── tenant-manager.ts # Gerenciador de tenants
├── sse-transport.ts # Transport SSE
└── types.ts # Tipos TypeScript
🔌 与N8N集成
使用N8N,配置为分段URL:
- 客户 1:
http://localhost:3000/cliente1 - 客户 2:
http://localhost:3000/cliente2
服务器将根据URL路径自动检测租户并配置相应的数据库。
🛡️ 安全
- 启用 CORS 开发
- 租户验证
- 可配置的 HTTP 请求超时
- 强大的错误处理
📝 日志
服务器提供详细的日志,包括:
- MCP 连接
- 执行工具
- 租户配置
- 错误和例外
🔄 开发
观看模式
npm run watch
构建
npm run build
📄 许可证
麻省理工学院
🤝 贡献
- 分叉工程
- 为您的功能创建分支
- 提交您的更改
- 推动一个分支
- 打开 Pull Request
📞 支持
如有疑问或问题,请在仓库中打开问题。