mcpboot
从自然语言提示符生成并提供MCP服务器。
将mcpbot指向API文档(或者只是描述您想要的内容),它生成一个工作 主控程序 服务器。不需要SDK知识。没有样板。无需维护代码。
使用LLM 仅在启动时 用于代码生成。在运行时,工具调用执行缓存的JavaScript,不涉及LLM,也不需要每次调用API成本。
安装
npm install -g mcpboot需要Node.js 18+。
快速开始
# Set your LLM API key
export ANTHROPIC_API_KEY=sk-ant-...
# Generate an MCP server for the Hacker News API
mcpboot --prompt "Create MCP tools for the Hacker News API: https://github.com/HackerNews/API"mcpbot获取API文档,生成工具处理程序,并开始在 http://localhost:8000/mcp.
用法
mcpboot [options]
Options:
--prompt Generation prompt (inline)
--prompt-file
Generation prompt from file
--provider LLM provider: anthropic | openai (default: anthropic)
--model LLM model ID (default: provider-specific)
--api-key LLM API key (env: ANTHROPIC_API_KEY | OPENAI_API_KEY)
--port HTTP server port (default: 8000)
--cache-dir
Cache directory (default: .mcpboot-cache)
--no-cache Disable caching, regenerate on every startup
--verbose Verbose logging (structured JSON to stderr)
--log-file
Write full verbose log to file (JSON lines, untruncated)
--dry-run Show generation plan without starting server例子
# Wrap the Hacker News API
mcpboot --prompt "Create MCP tools for the Hacker News API: https://github.com/HackerNews/API"
# Wrap an API from an OpenAPI spec
mcpboot --prompt "Create MCP tools from https://petstore.swagger.io/v2/swagger.json"
# Create specific tools from a known API
mcpboot --prompt "Using the GitHub REST API (https://docs.github.com/en/rest), \
create tools for listing repos, creating issues, and searching code"
# Create utility tools (no external API needed)
mcpboot --prompt "Create tools for JSON manipulation: pretty-print, validate, diff, and JSONPath extraction"
# Complex prompt from file
mcpboot --prompt-file ./my-api-prompt.txt --port 9000
# Preview what would be generated
mcpboot --prompt "Create MCP tools for https://github.com/HackerNews/API" --dry-run演练:黑客新闻API
以下是为生成MCP服务器的完整示例 黑客新闻API.
1.启动mcpboot:
mcpboot --model claude-haiku-4-5 --port 8100 --verbose \
--prompt "Create MCP tools for the Hacker News API. The API docs are at
https://github.com/HackerNews/API . Figure out what tools are appropriate
to expose — things like getting top stories, new stories, getting an item
by ID, getting a user profile, etc."mcpbot从GitHub获取API文档,使用LLM规划和编译10个工具,并开始提供:
[mcpboot] Found 1 URL(s) in prompt
[mcpboot] Fetched 1 page(s)
[mcpboot] Cache miss — generating tools via LLM
[mcpboot] Plan: 10 tool(s)
[mcpboot] Compiled 10 handler(s)
[mcpboot] Listening on http://localhost:8100/mcp
[mcpboot] Serving 10 tool(s)随着 --verbose,每个步骤还向stderr发出结构化JSON事件(每行一个JSON对象),其中包含时间戳、请求相关性ID和详细的有效载荷:
{"ts":"...","event":"llm_call_start","req_id":"startup","call_id":1,"provider":"anthropic","model":"claude-haiku-4-5",...}
{"ts":"...","event":"llm_call_end","req_id":"startup","call_id":1,"elapsed_ms":2100,"prompt_tokens":1240,"completion_tokens":892,...}使用 --log-file mcpboot.log 捕获完整的未截断输出(stderr将长字符串截断为500个字符)。
2.使用MCP检查员进行测试:
npx @modelcontextprotocol/inspector --transport http --server-url http://localhost:8100/mcp或者使用CLI进行测试 麦克波特:
# List all generated tools
npx mcporter list http://localhost:8100/mcp --schema --allow-http
# Get the top 5 stories (returns story IDs)
npx mcporter call 'http://localhost:8100/mcp.get_top_stories' limit=5 --allow-http
# Fetch details for a story
npx mcporter call 'http://localhost:8100/mcp.get_item_by_id' item_id=42345678 --allow-http
# Look up a user profile
npx mcporter call 'http://localhost:8100/mcp.get_user_profile' username=dang --allow-http生成的工具: get_top_stories, get_new_stories, get_best_stories, get_ask_stories, get_show_stories, get_job_stories, get_item_by_id, get_user_profile, get_max_item_id, get_recent_changes
后续使用相同提示的运行将完全跳过LLM,并立即从缓存中启动。
从MCP主机连接
mcpboot运行后,将任何与MCP兼容的主机连接到 http://localhost:8000/mcp例如,在Claude Desktop的配置中:
{
"mcpServers": {
"my-api": {
"url": "http://localhost:8000/mcp"
}
}
}运作原理
mcpboot遵循两阶段启动,然后在运行时提供工具:
启动(LLM协助):
- 获取 -从提示中提取URL,获取其内容(API文档、自述文件、OpenAPI规范),并构建用于运行时网络访问的域白名单。
- 计划 -将提示和提取的文档发送到LLM,LLM生成结构化的生成计划:创建什么工具,它们的模式,它们使用哪些API端点。
- 编译 -将每个计划的工具发送回LLM,LLM生成一个JavaScript处理程序函数,该函数调用API、解析响应并格式化结果。
- 缓存 --将计划和编译的处理程序存储在磁盘上,按提示哈希+内容哈希键控。后续具有相同提示和不变文档的初创公司完全跳过LLM。
运行时(无LLM):
- 服务 --通过StreamableHTTP将生成的工具作为MCP服务器公开。工具调用在沙盒中执行缓存的JavaScript处理程序
vm获取权限仅限于白名单域。
Prompt + API Docs
│
▼
URL Fetcher ──► Planner (LLM) ──► Compiler (LLM) ──► Cache
│
▼
MCP Host ◄──► Exposed Server ◄──► Executor ◄──► Sandbox (vm + fetch)
│
▼
External APIs安全模型
生成的处理程序在Node.js中运行 vm 沙盒:
- 允许: 标准JS全局,
fetch(仅限白名单域名)、URL、URLSearchParams - 此 路 不通:
require,import,process,fs,net,child_process - 超时: 每次工具调用30秒
域白名单是根据提示中的URL和在获取的文档中发现的URL自动构建的。
与mcpblox的比较
mcpboot和 mcpblox 是互补的:
|| mcpblox | mcpboot| |--|---------|---------| | 输入 |现有MCP服务器+转换提示|自然语言提示+可选API文档| | 输出 |改造后的MCP服务器|从头开始新的MCP服务器| | LLM生成 |转换函数(输入/输出映射器)|工具处理程序函数(API完整集成)| | 用例 |自定义现有服务器|创建尚不存在的服务器|
它们可以被链接:使用mcpboot引导服务器,然后使用mcpblox对其进行转换。
# Bootstrap an MCP server for the HN API
mcpboot --prompt "Create MCP tools for https://github.com/HackerNews/API" --port 8001
# Transform it with mcpblox to add higher-level tools
mcpblox --upstream-url http://localhost:8001/mcp \
--prompt "Create a 'daily_digest' tool that gets top 10 stories with their top comments" \
--port 8002发展
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
# Run from source
npx tsx src/index.ts --prompt "..."许可证
阿帕奇-2.0
