toolcast
Turn any API into an AI agent tool. One command.
Point at an OpenAPI spec. Get a working MCP server in 10 seconds.
Your AI agent can now call Stripe, GitHub, Slack, Notion — or any API with a spec.
Quick Start •
Registry •
How It Works •
Examples •
Contributing
问题
您希望您的人工智能代理调用API。今天你必须:
- 为特定的API查找或构建MCP服务器
- 编写工具定义、参数模式、身份验证处理
- 测试、调试、部署
- 对每个新的API重复
toolcast在一个命令中完成所有这些。
快速开始```bash
Try it right now with the demo Petstore API (no auth needed)
npx toolcast serve https://petstore3.swagger.io/api/v3/openapi.json
就是这样。你的人工智能代理现在有19个工具来管理宠物、订单和用户。
### 添加一个真正的API```bash
# Add Stripe to your Claude Code config
npx toolcast add stripe
# Or point at any OpenAPI spec
npx toolcast serve https://api.example.com/openapi.json --bearer-token $MY_TOKEN
上菜前检查```bash
See what tools would be generated
npx toolcast inspect https://petstore3.swagger.io/api/v3/openapi.json
``````
Swagger Petstore v1.0.27
19 Tools:
addPet POST /pet (1 params)
updatePet PUT /pet (1 params)
findPetsByStatus GET /pet/findByStatus (1 params)
getPetById GET /pet/{petId} (1 params)
getInventory GET /store/inventory (0 params)
placeOrder POST /store/order (1 params)
createUser POST /user (1 params)
...
## 注册表
toolcast附带了流行API的预构建配置。添加它们的一个命令:
|API |命令|获得的内容|
|-----|---------|-------------|
| **GitHub** | `toolcast add github` |repo、问题、PR、操作、用户|
| **条纹** | `toolcast add stripe` |付款、订阅、发票|
| **Slack** | `toolcast add slack` |消息、渠道、用户、反应|
| **概念** | `toolcast add notion` |页面、数据库、块、搜索|
| **线性** | `toolcast add linear` |问题、项目、团队、周期|
| **OpenAI** | `toolcast add openai` |完成、嵌入、图像|
| **宠物店** | `toolcast add petstore` |用于测试的演示API|
```bash
# List all available APIs
toolcast list
# Search by keyword
toolcast search payments
想要添加API吗? 看 贡献.
运作原理```
+-----------------+
OpenAPI Spec ---> | toolcast | ---> MCP Server (stdio)
(URL or file) | | ready for Claude Code,
| 1. Parse spec | Cursor, or any MCP client
| 2. Build tools |
| 3. Handle auth |
+-----------------+
1. **解析** --读取任何OpenAPI 3.0/3.1规范(JSON或YAML、URL或文件)。解决 `$ref`s、 提取端点、参数和身份验证方案。
1. **构建工具** -每个API端点都成为一个MCP工具,具有:
- 人类可读的名称(来自 `operationId`)
- 清晰的描述(来自 `summary` + `description`)
- 类型化的输入模式(来自参数+请求体)
- 正确的参数处理(路径、查询、标头、正文)
1. **服务** -启动一个stdio MCP服务器,该服务器使用正确的身份验证、头和错误格式将工具调用代理到真正的API。
## 例子
### 与Claude Code一起使用
添加到您的 `.mcp.json`:```json
{
"mcpServers": {
"my-api": {
"command": "npx",
"args": ["toolcast", "serve", "https://api.example.com/openapi.json"],
"env": {
"API_TOKEN": "your-token-here"
}
}
}
}
或者使用 add 自动配置命令:```bash
toolcast add github
Adds to .mcp.json automatically
### 与本地规范文件一起使用```bash
toolcast serve ./my-api-spec.yaml --base-url https://localhost:3000
以编程方式使用```typescript
import { parseSpec, createMcpServer } from "toolcast";
const spec = await parseSpec("https://api.example.com/openapi.json");
const server = createMcpServer(spec, {
baseUrl: "https://api.example.com",
auth: { type: "bearer", value: process.env.API_TOKEN },
});
## 认证
toolcast支持三种身份验证方法,可从OpenAPI规范中自动检测:
|方法|环境变量|标志|
|--------|--------------|------|
| **持有者令牌** | `API_TOKEN`, `BEARER_TOKEN`, `AUTH_TOKEN` | `--bearer-token` |
| **API密钥** | `API_KEY`,或源自方案名称| `--api-key` |
| **基本认证** | `API_USER` + `API_PASSWORD` | — |
注册表项指定要使用哪个env变量(例如。, `GITHUB_TOKEN` GitHub)。
## CLI参考```
toolcast serve Start MCP server from OpenAPI spec
--base-url Override base URL
--api-key API key auth
--bearer-token Bearer token auth
toolcast inspect Preview tools without starting server
toolcast add Add registry API to .mcp.json
--config Config file path (default: .mcp.json)
toolcast list List all registry APIs
toolcast search Search registry
toolcast --version Show version
toolcast --help Show help
贡献
将API添加到注册表
- 在中创建一个YAML文件
registry/:```yaml
name: my-api
displayName: My API
description: What this API does
specUrl: https://example.com/openapi.json
baseUrl: https://api.example.com
authType: bearer
authEnvVar: MY_API_KEY
tags:
- category
- keywords
2. 提交PR。就是这样。
### 发展```bash
git clone https://github.com/your-username/toolcast.git
cd toolcast
npm install
npm run build
npm test
# Test locally
node dist/cli.js inspect https://petstore3.swagger.io/api/v3/openapi.json
许可证
麻省理工学院
