io.github.pavelpiha/specrun
编码与调试by pavelpiha
可将 OpenAPI specs 转换为工具的 MCP 服务器,用于查询并调用各类 API endpoints。
什么是 io.github.pavelpiha/specrun?
可将 OpenAPI specs 转换为工具的 MCP 服务器,用于查询并调用各类 API endpoints。
README
Built with FastMCP for TypeScript.
✨ Features
- Zero Configuration: Filesystem is the interface - just drop OpenAPI specs in a folder
- Supports OpenAPI 3.0 and 2.0: Works with both OpenAPI 3.x and Swagger 2.0 specs
- Namespace Isolation: Multiple APIs coexist cleanly
- Full OpenAPI Support: Handles parameters, request bodies, authentication, and responses
- Run Any Tool to Interact with APIs: For example,
cars_addCarto callPOST /carsfromcars.jsonspec to create a new car, orgithub_get_user_reposto callGET /user/reposfromgithub.yamlspec to list repos. - Run Any Tool with Custom Inputs: Pass structured JSON inputs for parameters and request bodies
- Run Any Tool to see Spec Details: Get the original OpenAPI spec details for any tool, including parameters, request body schema, and response schema
- Run Any Tool to get API responses as resources: Each tool call returns a JSON resource containing request URL, request body, and response
- Run Any Tool in Batch: One
specrun_batchtool can execute any tool with multiple inputs and returns a consolidated JSON resource - Auto Authentication: Simple
.envfile with{API_NAME}_API_KEYpattern - Auto .env Placeholders: Adds
{API_NAME}_SERVER_URLand{API_NAME}_BEARER_TOKENentries when missing - Multiple Transports: Support for stdio and HTTP streaming
- Built-in Debugging: List command to see loaded specs and tools
- MCP Prompts: Built-in prompts for listing tools, generating inputs, and explaining schemas
- Agent: configured agent for using SpecRun tools to explore and operate APIs in a guided way (
.github/agents/specrun.agent.md)
Quick Start
Requirements
- Node.js 22 or newer
1️⃣ Install (optional)
npm install -g specrun
2️⃣ Create a specs folder where the server can read OpenAPI spec files. For example:
mkdir ~/specs
3️⃣ Add OpenAPI specs
Drop any .json, .yaml, or .yml OpenAPI specification files into your specs folder
4️⃣ Configure authentication (optional)
Create a .env file in your specs folder:
# ~/specs/.env
CARS_API_KEY=your_api_key_here
SpecRun will also ensure {API_NAME}_SERVER_URL and {API_NAME}_BEARER_TOKEN entries exist for each spec, adding empty placeholders when missing.
When {API_NAME}_SERVER_URL has a value, SpecRun updates the spec file on load:
- OpenAPI 3.0: updates the first
serversentry. - OpenAPI 2.0 (formerly Swagger 2.0): updates
host,schemes, andbasePath(noserverssection in OpenAPI 2.0).
SpecRun also watches the .env file and refreshes server URLs and auth config automatically after changes.
5️⃣ Add to MCP client configuration
Add to your MCP configuration:
If installed on your machine:
{
"mcpServers": {
"specrun": {
"command": "specrun",
"args": ["--specs", "/path/to/your/specs/folder"]
}
}
}
Otherwise:
{
"mcpServers": {
"specrun": {
"command": "npx",
"args": ["-y", "specrun", "--specs", "/absolute/path/to/your/specs"]
}
}
}
or with specific Node version:
{
"mcpServers": {
"specrun": {
"command": "/Users/YOUR_USER_NAME/.local/bin/mcp-npx-node22",
"args": ["specrun@latest", "--specs", "/absolute/path/to/your/specs"],
"type": "stdio"
}
}
}
The mcp-npx-node22 script file uses nvm to run specrun with Node.js 22.14.0, ensuring compatibility regardless of the default Node version on your system.:
#!/bin/bash
# Set the PATH to include NVM's Node.js v22.14.0 installation
export PATH="/Users/YOUR_USER_NAME/.nvm/versions/node/v22.14.0/bin:$PATH"
# Execute npx with all passed arguments
exec npx "$@"
💻 CLI Usage
🚀 Start the server
# Default: stdio transport, current directory
specrun
# Custom specs folder
specrun --specs ~/specs
# HTTP transport mode
specrun --transport httpStream --port 8080
Run with Node 22 using npx
If your default node is older than 22, run SpecRun with Node 22 directly:
npx -y node@22 ...runs the Node.js runtime, so the next argument must be a script path (for example./node_modules/.bin/specrun).specrun@latestis an npm package spec and works directly withnpxonly when your current Node version already satisfies SpecRun requirements.
# Or list tools
npx -y node@22 ./node_modules/.bin/specrun list --specs ~/specs
# If your default Node is already 22+, this also works
npx -y specrun@latest --specs ~/specs
📋 List loaded specs and tools
# List all loaded specifications and their tools
specrun list
# List specs from custom folder
specrun list --specs ~/specs
🔑 Authentication Patterns
The server automatically detects authentication from environment variables using these patterns:
| Pattern | Auth Type | Usage |
|---|---|---|
{API_NAME}_API_KEY | 🗝️ API Key | X-API-Key header |
{API_NAME}_TOKEN | 🎫 Bearer Token | Authorization: Bearer {token} |
{API_NAME}_BEARER_TOKEN | 🎫 Bearer Token | Authorization: Bearer {token} |
{API_NAME}_USERNAME + {API_NAME}_PASSWORD | 👤 Basic Auth | Authorization: Basic {base64} |
SpecRun also creates .env placeholders for:
| Pattern | Purpose |
|---|---|
{API_NAME}_SERVER_URL | Base URL for the API |
{API_NAME}_BEARER_TOKEN | Token placeholder if missing |
If {API_NAME}_SERVER_URL is set, SpecRun writes that value into the spec before generating tools:
- OpenAPI 3.0: writes the first
serversentry. - OpenAPI 2.0 (formerly Swagger 2.0): writes
host,schemes, andbasePath.
Updates to .env are applied automatically without restarting the MCP server.
The {API_NAME} is derived from the filename of your OpenAPI spec:
cars.json→CARS_API_KEYgithub-api.yaml→GITHUB_TOKENmy_custom_api.yml→MY_CUSTOM_API_KEY
🏷️ Tool Naming
Tools are automatically named using this pattern:
- With operationId:
{operation_id} - Without operationId:
{method}_{path_segments}
Name normalization rules:
- Converted to
snake_case - Lowercased
- Non-alphanumeric characters normalized to
_ - Truncated at the end when longer than 52 characters. (For VS Code/Copilot compatibility, stays within the practical 64-char internal limit.)
- Adds short suffixes only when needed to resolve collisions
Specs:
get_car_by_id(from operationId)get_user_repos(generated fromGET /user/repos)
Use the shared batch tool to run any tool with an array of inputs:
{
"toolName": "cars_getCarById",
"items": [{ "id": "123" }, { "id": "456" }],
"failFast": false
}
Batch responses return a consolidated JSON resource with per-item outputs.
For batches over 200 items, SpecRun requires explicit confirmation. This is to prevent accidental large runs that could cause performance issues or unintended consequences. The server will return a message asking for confirmation, and you can retry with confirmLargeBatch: true and the provided confirmLargeBatchToken to proceed.
📦 Resource Outputs
Tool responses are returned as MCP resources with application/json content. Each resource includes:
- Request URL
- Request body
- Response status and body
Example resource payload:
{
"requestUrl": "https://api.example.com/v1/users/123",
"requestBody": null,
"response": {
"status": 200,
"body": {
"id": "123",
"name": "Jane Doe"
}
}
}
Batch runs return a single consolidated resource containing all item results.
📁 File Structure
your-project/
── specs/ # Your OpenAPI specs folder
├── .env # Authentication credentials
└── custom-api.yml # Your OpenAPI spec files
🧭 MCP Prompts
SpecRun exposes MCP prompts for common workflows:
Detailed prompt guide with examples: PROMPTS_README.md
list_apis: List loaded APIs/tools and ask the user to choose an endpointgenerate_api_call: Generate a ready-to-run JSON input payload for a toolexplain_api_schema: Explain parameters and request body schema with examplesgenerate_random_data: Generate random ready-to-run JSON payload samples for a tool
📄 Example OpenAPI Spec
Here's a minimal example that creates two tools:
# ~/specs/example.yaml
openapi: 3.0.0
info:
title: Example API
version: 1.0.0
servers:
- url: https://api-server.placeholder
paths:
/users/{id}:
get:
operationId: getUser
summary: Get user by ID
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: User found
/users:
post:
operationId: createUser
summary: Create a new user
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
email:
type: string
responses:
"201":
description: User created
This creates tools named:
example_getUserexample_createUser
🔧 Troubleshooting
❌ No tools appearing?
-
Check that your OpenAPI specs are valid:
bashspecrun list --specs /path/to/specs -
Ensure files have correct extensions (
.json,.yaml,.yml) -
Check the server logs for parsing errors
⚠️ Note: SpecRun works best when you use absolute paths (with no spaces) for the
--specsargument and other file paths. Relative paths or paths containing spaces may cause issues on some platforms or with some MCP clients.
🔐 Authentication not working?
- Verify your
.envfile is in the specs directory - Check the naming pattern matches your spec filename
- Use the list command to verify auth configuration:
bash
specrun list
🔄 Tools not updating after spec changes?
- Restart the MCP server to reload the specs
- Check file permissions
- Restart the MCP client if needed
🛠️ Development
# Clone and install
git clone git@github.com:Pavel-Piha/specrun.git
cd specrun
npm install
# Build
npm run build
npm run dev -- list --specs ./specs
🤝 Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
常见问题
io.github.pavelpiha/specrun 是什么?
可将 OpenAPI specs 转换为工具的 MCP 服务器,用于查询并调用各类 API endpoints。
相关 Skills
网页构建器
by anthropics
面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。
✎ 在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。
前端设计
by anthropics
面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。
✎ 想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。
网页应用测试
by anthropics
用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。
✎ 借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。
相关 MCP Server
GitHub
编辑精选by GitHub
GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。
✎ 这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。
Context7 文档查询
编辑精选by Context7
Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。
✎ 它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。
by tldraw
tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。
✎ 这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。