apifable

apifable
阅读规范。理解 API。自信地进行集成。
English | 繁體中文
概述
apifable 是一个 MCP 服务器,旨在帮助 AI 更顺畅地将 API 集成到 TypeScript 前端项目中。它使探索 API 结构、搜索端点和生成 TypeScript 类型变得简单,从而为您的 AI 代理提供编写准确集成代码所需的上下文。
Related MCP server: openapi-mcp-proxy
✨ 特性
📦 AI 就绪的 API 上下文 — 为 AI 提供理解和使用您的 API 所需的结构
📘 支持 OpenAPI 3.0 / 3.1 — 作为可靠的事实来源,适用于标准规范
🤖 面向 AI 代理的 MCP 服务器 — 可接入 Claude、Cursor 和 Windsurf
🔍 API 探索工具 — 浏览端点、按关键字搜索并检查完整的请求/响应详情
🏷️ TypeScript 类型生成 — 生成可直接在前端代码中使用的 TypeScript 类型定义
入门指南
安装
运行 apifable init 来设置您的项目配置:
npx apifable@latest init这将在您的项目根目录中创建 apifable.config.json。该配置文件应提交到版本控制中,以便与团队共享规范路径。
命令启动后,您可以选择 手动文件 (Manual file) 或 远程 URL (Remote URL)。
1. 手动文件
如果您的 OpenAPI 规范已经存在于项目中,或者您想自己管理规范更新,请使用此模式。
init 将询问本地文件路径,例如 openapi.yaml。
然后,您需要手动将 OpenAPI 规范放置在该路径下。当后端 API 发生变化时,您也需要手动更新该文件。
2. 远程 URL
如果您的 OpenAPI 规范可以通过稳定的远程 URL 获取(例如后端 API 文档提供的 OpenAPI 规范端点),请使用此模式。
init 将首先询问远程 URL(例如 https://api.example.com/openapi.yaml),然后询问本地输出路径(例如 ./openapi.yaml)。
[!NOTE] 在此模式下,
init还会自动将下载的本地规范路径添加到.gitignore中,因为该文件旨在从远程源刷新。
然后,您可以运行以下命令将 OpenAPI 规范从远程 URL 下载到本地路径(spec.url → spec.path)。每当规范发生变化时,只需再次运行它即可刷新:
npx apifable@latest fetch请求头 (Headers)
对于可以与团队共享的非敏感请求头,请将 spec.headers 添加到 apifable.config.json 中:
{
"spec": {
"path": "openapi.yaml",
"url": "https://example.com/openapi.yaml",
"headers": {
"X-Api-Version": "2"
}
}
}认证请求头 (Secret Tokens)
如果下载远程 OpenAPI 规范需要身份验证(私有 API),请将秘密请求头存储在 .apifable/auth.json 中。此文件不应提交到版本控制中:
{
"headers": {
"Authorization": "Bearer YOUR_SECRET_TOKEN"
}
}apifable.config.json 和 .apifable/auth.json 都支持在请求头值中使用 ${ENV_VAR} 语法。
{
"headers": {
"Authorization": "Bearer ${MY_API_KEY}"
}
}请求头优先级(从高到低)
.apifable/auth.json中的请求头(覆盖同名键)apifable.config.json中的spec.headers
Claude Code
将以下内容添加到您的 .mcp.json 中:
{
"mcpServers": {
"apifable": {
"command": "npx",
"args": ["-y", "apifable@latest", "mcp"]
}
}
}对于 Cursor 和 Windsurf 等其他 AI 代理,您可以按照相同的方法将 apifable 配置为 MCP 服务器。
使用方法
以下是一些可用于探索 API 和构建功能的示例提示词。
探索 API
List all APIsShow me APIs related to postsList APIs under the Post tagShow me the API details for post commentsShow me the API details for GET /posts/{id}/commentsShow me the API details for postComments构建功能
Implement the post comments feature
Post page: src/pages/posts/[id].tsx
Related APIs:
- GET /posts/{id}/comments (list post comments)
- POST /posts/{id}/comments (create a post comment)[!TIP] 在编写构建功能的提示词时,请包含相关上下文:页面路径、组件位置、相关 API 以及任何需要遵循的模式或示例。
AI 代理指南
将以下内容添加到项目的 AGENTS.md 中,以帮助 AI 代理更有效地使用 apifable:
## API Integration (apifable)
- Always use `get_endpoint` to verify the exact path, method, and parameters before writing integration code. Never assume.
- When presenting endpoint list data from apifable tools, display exactly these columns in order: `Method` (Uppercase), `Path`, `Summary`. Keep all values verbatim, including summary prefixes like `[ 32 - 001 ]`. Do not omit, rename, paraphrase, or add extra columns.
- When saving generated types, store them under `src/types/` and name files by domain (e.g., `src/types/auth.ts`, `src/types/user.ts`), not by OpenAPI tag names.以上是推荐的起点。请根据您的项目随意调整端点列表列和类型文件夹路径。
MCP 工具参考
get_spec_info
返回 API 标题、版本、描述、服务器以及所有带有端点计数的标签。从这里开始了解陌生规范的结构。
list_endpoints_by_tag
输入:
tag(string): 要过滤的标签名称limit(number, 可选): 返回的最大端点数offset(number, 可选): 跳过的端点数(默认值:0)
返回属于给定标签的所有端点。响应包含用于分页的 total、offset 和 hasMore 字段。当结果超过 30 项且未指定 limit 时,包含警告。
search_endpoints
输入:
query(string): 要搜索的关键字tag(string, 可选): 将搜索限制在特定标签内limit(number, 可选): 返回的最大结果数(默认值:10)
跨 operationId、路径、摘要和描述进行关键字搜索。结果按相关性排序。如果未找到精确匹配,则自动回退到模糊搜索。响应包含 matchType 字段("exact" 或 "fuzzy");模糊搜索结果还包含每个结果的 score 字段。
get_endpoint
输入(二选一):
method(string) +path(string): HTTP 方法和端点路径(例如get+/users/{id})operationId(string): 操作 ID(例如listUsers)
返回完整的端点对象,包括参数、requestBody 和响应,并解析内联支持的内部组件 $ref。
search_schemas
输入:
query(string): 要搜索的关键字limit(number, 可选): 返回的最大结果数(默认值:10)
跨模式名称和描述进行关键字搜索。结果按相关性排序。如果未找到精确匹配,则自动回退到模糊搜索。响应包含 matchType 字段("exact" 或 "fuzzy");模糊搜索结果还包含每个结果的 score 字段。空结果可能还包含带有下一步指导的 message 字段。
get_schema
输入:
name(string): 来自components/schemas的模式名称
返回解析了支持的内部组件 $ref 的完整模式。
get_types
输入(选择一种模式):
schemas(string[]): 来自components/schemas的模式名称数组method(string) +path(string): HTTP 方法和端点路径operationId(string): 操作 ID(例如listUsers)
生成独立的 TypeScript 声明作为代码文本。在端点模式下,它会在收集模式依赖项之前跟踪支持的内部组件 $ref。它会自动包含传递依赖项,且不包含 import 语句。
模式规则:
每次调用仅使用一种模式:
schemas、method+path或operationId不要在同一次调用中混合使用模式
限制
不支持外部
$ref(例如对其他文件或 URL 的引用)。不支持 OpenAPI 2.0 (Swagger)。仅支持 OpenAPI 3.0 和 3.1 规范。
赞助
如果您认为此包对您有帮助,请考虑 成为赞助者 以支持我的工作~ 您的头像将显示在我的主要项目中。
致谢
@reapi/mcp-openapi — 感谢最初的灵感来源
许可证
Star 历史
Available Tools
7 toolsget_endpointA
Get full details of a specific endpoint including parameters, request body, responses, and security requirements. Supported internal component $refs are resolved inline. Provide either "method" + "path" or "operationId". Use get_types to get TypeScript type declarations for the endpoint.
Inputs: path, method, operationId.
get_schemaA
Get a specific schema from components/schemas by name. Supported internal component $refs are resolved inline. Use get_types to convert schemas to TypeScript type declarations.
Inputs: name (required).
get_spec_infoA
Get general information about the OpenAPI spec: title, version, description, servers, security schemes, and available tags with endpoint counts. Start here to understand an unfamiliar API. Then use list_endpoints_by_tag or search_endpoints to explore specific areas.
Inputs: no named parameters.
get_typesA
Generate self-contained TypeScript type declarations for specified schemas or for all schemas used by a specific endpoint. Endpoint mode follows supported internal component $refs before collecting schema dependencies. Provide exactly one of: "schemas" (array of schema names), "method" + "path" (endpoint), or "operationId". Transitive dependencies are included automatically.
Inputs: path, method, schemas, operationId.
list_endpoints_by_tagA
List all endpoints belonging to a specific tag. Use get_spec_info first to see available tags. Supports pagination via limit and offset. Then use get_endpoint to inspect a specific endpoint in detail.
Inputs: tag (required), limit, offset.
search_endpointsA
Search endpoints by keyword across operationId, path, summary, and description. Results are ranked by relevance. If no exact matches are found, automatically falls back to fuzzy search. The response includes a matchType field ("exact" or "fuzzy"); fuzzy results also include a score field per result. After finding the target endpoint, use get_endpoint for full details or get_types for TypeScript types.
Inputs: query (required), tag, limit.
search_schemasA
Search schemas by keyword across schema name and description. Results are ranked by relevance. If no exact matches are found, automatically falls back to fuzzy search. Empty results may include a guidance message suggesting next steps. Use get_schema to inspect a specific schema in detail.
Inputs: query (required), limit.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a distinct action: spec overview, endpoint search/list/detail, schema search/detail, and TypeScript generation. No two tools overlap in purpose, and cross-references between them make selection clear.
All tools use a consistent lowercase snake_case verb_noun pattern: get_, search_, and list_. Even the longer list_endpoints_by_tag follows the same predictable convention.
Seven tools is well-scoped for an OpenAPI exploration and type-generation server. Each tool fills a distinct role without redundancy or bloat.
The surface covers the core exploration workflow well: discover spec info, find endpoints/schemas, inspect details, and generate TypeScript types. Minor gaps exist such as no way to list all schemas or all endpoints globally, but these are workable through tags and search.
Maintenance
Related MCP Connectors
MCP server for AI access to Swagger by SmartBear.
MCP server for secureFlows: token-free URL builders and integration-linting tools for AI agents.
MCP server for building and testing AI agents with multi-model experimentation and insights.
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that loads multiple OpenAPI specifications and exposes them to LLM-powered IDE integrations, enabling AI to understand and work with your APIs directly in development tools like Cursor.790MIT
- AlicenseAqualityDmaintenanceAn MCP server that provides tools for exploring large OpenAPI schemas without loading entire schemas into LLM context. Perfect for discovering and analyzing endpoints, data models, and API structure efficiently.914MIT
- AlicenseBqualityDmaintenanceMCP server that enables AI assistants to explore and generate code for type-safe OpenAPI clients from various cloud APIs like DigitalOcean, Hetzner Cloud, and Ory.714 npm19MIT
- AlicenseAqualityDmaintenanceA TypeScript-based MCP server that integrates with Swagger/OpenAPI specifications to expose API endpoints as tools for Large Language Models (LLMs), enabling natural language interaction with any OpenAPI-compliant API.49MIT