API发现服务器

api-mind MCP Server是一个用于从.mind规范文件中发现API的服务,支持与Claude Code、Claude Desktop和任何MCP兼容的AI助手一起使用。

  • by msegoviadev
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 msegoviadev/api-mind-mcp

使用说明

api mind MCP服务器

用于从中发现API的MCP服务器 .mind 规范文件。可与Claude Code、Claude Desktop和任何兼容MCP的AI助手配合使用。

快速开始

# 1. Install spec-mind to generate .mind files from OpenAPI specs
brew install spec-mind

# 2. Run the setup script from your project directory
curl -fsSL https://raw.githubusercontent.com/msegoviadev/api-mind-mcp/main/setup-mcp.sh | bash

# 3. Add your OpenAPI specs and generate .mind files
mkdir specs
cp your-api.yaml specs/
spec-mind sync --no-notation ./specs/

# 4. Restart Claude Code

在克劳德代码中:

What APIs are available?
Show me the endpoints for payments
Call GET /payments/{id} in dev

安装

先决条件

安装 规格思维 生成 .mind OpenAPI规范中的文件:

brew install spec-mind

设置

跑 setup-mcp.sh 从您的项目目录:

curl -fsSL https://raw.githubusercontent.com/msegoviadev/api-mind-mcp/main/setup-mcp.sh | bash

或用于用户范围的安装(所有项目):

curl -fsSL https://raw.githubusercontent.com/msegoviadev/api-mind-mcp/main/setup-mcp.sh | bash -s -- --global

脚本:

  • 创建一个 specs/ 项目中的目录
  • 在Claude Code中使用正确的规范路径注册api mind
  • 支架 ~/.config/api-mind/dev.env 对于环境默认值

用法

1.添加您的API规格

# Copy your OpenAPI/Swagger YAML/JSON files to specs/
cp your-api.yaml specs/

2.生成.mind文件

spec-mind sync --no-notation ./specs/

3.在克劳德代码中使用

User: "What APIs are available?"
Claude: *uses list_apis tool*
"Found 2 APIs: ecommerce, payments"

User: "Show me payment endpoints"
Claude: *uses list_endpoints tool*
"POST /payments [auth: oauth2]
 GET /payments/{id}"

User: "Call GET /payments/{id} in dev"
Claude: *uses get_endpoint_schema + get_call_context tools*
"Resolved base URL: https://api.dev.example.com
 Calling GET /payments/123..."

工具

list_apis

列出从specs文件夹加载的所有API。

Input: none
Output: JSON with API names, titles, base URLs, and environments

list_endpoints

列出所有API的端点。

Input:
  filter (optional): Substring match on method, path, or section
Output: JSON with environments and endpoint list

get_endpoint_schema

返回端点的完整上下文。

Input:
  api: API name
  method: HTTP method
  path: Endpoint path
Output: Text block with base URL, environments, auth, and schema

在构造curl之前调用以了解端点契约。

get_call_context

返回执行API调用所需的运行时上下文。

Input:
  api: API name
  env (optional): Environment to use (dev, stage, uat). Defaults to dev.
Output: Resolved base URL, active environment, and default values for credentials and parameters

当用户想要实际调用端点时,在构造curl之前调用此函数。 阅读来源 ~/.config/api-mind/<env>.env 和 ~/.config/api-mind/<api>/<env>.env.


身份验证模式

当 get_endpoint_schema 显示身份验证要求,构造标头:

架构中的身份验证 curl标头
None 无标题
bearer -H 'Authorization: Bearer <TOKEN>'
oauth2 <scopes> -H 'Authorization: Bearer <TOKEN>'
api_key <header> -H '<header>: <KEY>'
basic -H 'Authorization: Basic <base64>'

环境默认值

get_call_context 从以下位置读取默认值 ~/.config/api-mind/:

~/.config/api-mind/
  dev.env        # base defaults for all APIs (dev environment)
  stage.env      # base defaults for stage
  auth0/
    dev.env      # API-specific overrides for auth0

每 .env 文件用途 key=value 格式(以开头的行 # 被忽略)。这 base_url 键会覆盖规范中的占位符URL。

示例 ~/.config/api-mind/dev.env:

base_url=https://api.dev.example.com
auth0_client_id=abc123
auth0_cacert=/etc/ssl/cert.pem

setup-mcp.sh 在第一次运行时脚手架此文件。


工作流程

list_apis → list_endpoints → get_endpoint_schema → get_call_context → [LLM constructs curl] → bash
  1. list_apis -发现可用的API
  2. list_endpoints -查找相关端点
  3. get_endpoint_schema -获取端点合约(URL、身份验证、模式)
  4. get_call_context -解析目标环境的基本URL和凭据
  5. LLM使用解析值构造curl命令
  6. LLM通过执行 bash 工具

高级配置

Manual installation and team setup

手动安装

claude mcp add --transport stdio api-mind \
  --env SPECS_DIR=/absolute/path/to/specs \
  -- npx -y @msegoviadev/api-mind-mcp

重要提示: 始终使用绝对路径。MCP服务器作为独立进程运行,没有项目上下文。

项目配置(.mcp.json)

创建 .mcp.json 在项目根目录中:

{
  "mcpServers": {
    "api-mind": {
      "command": "npx",
      "args": ["-y", "@msegoviadev/api-mind-mcp"],
      "env": {
        "SPECS_DIR": "/absolute/path/to/specs"
      }
    }
  }
}

注: 每个团队成员都需要自己的 .mcp.json 他们的绝对道路。添加 .mcp.json 到 .gitignore.


发展(贡献者)

git clone https://github.com/msegoviadev/api-mind-mcp
cd api-mind-mcp
npm install
npm run build

# Test locally
node dist/index.js /path/to/specs

相关

许可证

麻省理工学院