BYOB MCP服务器🚀
自带二进制文件:基于Cloudflare Workers、Containers和D1构建的动态MCP服务器。
使AI代理能够发现和调用在运行时注册的容器化工具,无需重新部署。
快速开始
# Install dependencies
npm install
# Start local dev server
npm run dev
# In another terminal, test the API
bash test-api.sh
# Deploy to production
npm run deploy这是什么
概念证明,证明:
- ✅ 动态工具注册表 -存储在D1中的工具,由MCP服务器查询
- ✅ 容器化执行 -每个工具都在隔离的Cloudflare容器中运行
- ✅ MCP协议 -AI代理通过模型上下文协议发现工具
- ✅ HTTP注册API -注册新工具而无需重新部署
- ✅ 缩放到零 -容器仅在调用工具时运行
建筑
AI Agent (Claude) ──[MCP]──> Cloudflare Worker ──[HTTP]──> Universal Container
│ (ToolRunner)
└──[SQL]──> D1 Registry
Supports:
• Echo
• Uppercase
• JQ
• Git Clone预构建演示工具
所有四个工具都在一个通用容器中运行:
- echo消息 -回显任何JSON输入
- 为什么大喊大叫 -将文本转换为大写
- query_json -使用jq过滤器处理JSON
- 总结报告 -克隆GitHub仓库并总结其README
API终点
得到/
健康检查和服务器信息
GET/api/工具
列出所有已注册的工具
POST/api/注册工具
注册新工具
{
"name": "my_tool",
"description": "What this tool does",
"containerClass": "echo",
"schema": {
"type": "object",
"properties": {
"input": {"type": "string"}
}
}
}POST/mcp
MCP协议端点(在此处连接您的AI代理)
示例:注册工具
curl -X POST http://localhost:8787/api/register-tool \
-H "Content-Type: application/json" \
-d '{
"name": "whisper",
"description": "Echoes message in lowercase",
"containerClass": "toolrunner",
"schema": {
"type": "object",
"properties": {
"message": {"type": "string"}
},
"required": ["message"]
}
}'连接到克劳德桌面
编辑您的Claude Desktop配置:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"byob-server": {
"url": "http://localhost:8787/mcp"
}
}
}重新启动Claude Desktop,然后问:
- “你们有什么工具?”
- “你能回应一下‘你好,毕博!’吗?”
- “使用why_are_we_shring和文本:你好,世界”
- “总结READMEhttps://github.com/fiberplane/mcp-lite"
文档
- 项目\_ SUMMARY.md -高级概述
- 哈克顿.md -完整的架构和设置指南
- DEMO.md -分步演示脚本
- CLAUDE.md -开发说明(适用于AI助手)
项目结构
├── src/
│ ├── index.ts # Main Worker + MCP server
│ ├── containers.ts # Container class definitions
│ └── types.ts # TypeScript interfaces
├── containers/
│ ├── Dockerfile # Universal container image
│ ├── server.js # Multi-tool HTTP server
│ └── README.md # Container documentation
├── migrations/
│ ├── 0001_initial_schema.sql
│ └── 0002_seed_example_tools.sql
└── wrangler.jsonc # Cloudflare configuration添加新工具
由于所有工具都使用相同的通用容器,因此添加新工具很简单:
选项1:通过API(无需重新部署)
curl -X POST http://localhost:8787/api/register-tool \
-H "Content-Type: application/json" \
-d '{"name":"my_tool", "description":"...", ...}'选项2:扩展容器
要添加新的操作类型,请执行以下操作:
- 编辑
containers/server.js处理新的输入模式 - 将新工具定义添加到
migrations/0002_seed_example_tools.sql - 重新部署
单容器方法使演示变得简单,同时仍演示BYOB架构。
技术栈
- 运行时间: Cloudflare Workers(V8隔离)
- MCP: mcp-lite(不是@modelcontextprotocol/sdk)
- Web框架: 荣誉
- 数据库: Cloudflare D1(SQLite)
- 容器: Cloudflare容器(持久对象)
- 架构: Zod+JSON模式
部署
地方发展
npm run dev
# Server runs on http://localhost:8787生产部署
- 在远程数据库上运行迁移:
npx wrangler d1 execute byob-tools-registry --remote \
--file=./migrations/0001_initial_schema.sql
npx wrangler d1 execute byob-tools-registry --remote \
--file=./migrations/0002_seed_example_tools.sql- 部署Worker和容器:
npm run deploy注: 首次部署需要2-5分钟来构建Docker镜像。
- 使用您的生产URL更新Claude Desktop配置:
{
"mcpServers": {
"byob-server": {
"url": "https://byob-mcp-server.YOUR_ACCOUNT.workers.dev/mcp"
}
}
}测试
# Automated API tests
bash test-api.sh
# Manual health check
curl http://localhost:8787/
# List tools
curl http://localhost:8787/api/tools | jq
# Test MCP protocol
curl -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'主要特点
动态发现
在D1中注册的工具会立即显示给所有连接的AI代理,无需重新部署。
安全隔离
每个容器都在一个具有资源限制和临时存储的隔离沙箱中运行。
无服务器规模
容器在空闲时缩放到零。仅为实际工具调用付费。
标准接口
所有容器暴露 POST /execute 端点接受/返回JSON。
局限性
必须在部署时定义容器类 在 wrangler.jsonc真正的运行时BYOB需要在注册新容器时自动重建/重新部署Worker。
解决方法: 多个逻辑工具可以共享同一个容器类,无需重新部署即可实现极大的灵活性。
资源
许可证
麻省理工学院-专为黑客马拉松演示而建
贡献
这是一个黑客马拉松原型。如有疑问或建议,请打开一个问题!
______________________________________________________________________
内置 ☁️ Cloudflare员工|🐳 集装箱|🗄️ D1|🤖 主控程序
