npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

apifox-service-mcp

v1.0.0

Published

MCP server for querying Apifox API information

Downloads

169

Readme

MCP Apifox Server

基于 Apifox 开放 API 的 MCP (Model Context Protocol) 服务器,用于查询和管理 Apifox 接口信息。

功能特性

  • 根据接口 ID 查询详情:获取接口的完整信息,包括路径、方法、参数、响应等
  • 批量查询接口:一次性查询多个接口的信息
  • 获取所有接口:获取项目中所有接口的列表
  • 搜索接口:根据关键词搜索接口
  • 生成 Service 代码:根据接口定义自动生成 JavaScript/TypeScript 代码
  • 接口摘要:快速浏览接口的基本信息
  • 动态项目 ID:支持在对话时动态指定项目 ID,无需修改配置文件

安装

cd mcp-apifox
npm install
npm run build

配置

设置环境变量:

# 必需:Apifox 访问令牌
export APIFOX_ACCESS_TOKEN="your_access_token"

# 可选:默认项目 ID(可以在对话时动态指定)
export APIFOX_PROJECT_ID="your_project_id"

# 可选:API 基础 URL(默认:https://api.apifox.com)
export APIFOX_API_BASE_URL="https://api.apifox.com"

# 可选:默认模块 ID
export APIFOX_MODULE_ID="1"

# 可选:默认分支 ID
export APIFOX_BRANCH_ID="1"

注意: APIFOX_PROJECT_ID 是可选的。如果在对话中指定了项目 ID,将优先使用对话中指定的项目 ID。如果经常使用同一个项目,建议设置默认项目 ID。

获取 Apifox API Token

  1. 打开 Apifox
  2. 进入"个人设置" → "API Token"
  3. 创建新的 API Token 并复制

获取项目 ID

在 Apifox 项目 URL 中可以找到项目 ID,例如:

https://app.apifox.com/project/1234560/docs

其中 1234560 就是项目 ID。

使用

直接运行

npm start

在 Claude Desktop 中使用

在 Claude Desktop 配置文件中添加:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "apifox": {
      "command": "npx",
      "args": ["-y", "apifox-service-mcp@latest"],
      "env": {
        "APIFOX_ACCESS_TOKEN": "your_access_token",
        "APIFOX_PROJECT_ID": "your_project_id",
        "APIFOX_API_BASE_URL": "https://api.apifox.com",
        "APIFOX_MODULE_ID": "1",
        "APIFOX_BRANCH_ID": "1"
      }
    }
  }
}

可用工具

1. get_interface_by_id

根据接口 ID 查询接口的详细信息。

参数:

  • endpointId (number, 必需): Apifox 接口 ID
  • projectId (string, 可选): Apifox 项目 ID

示例:

请查询接口 ID 为 12345 的详细信息
请查询项目 1234560 中接口 ID 为 12345 的详细信息

2. get_interfaces_by_ids

批量查询多个接口的详细信息。

参数:

  • endpointIds (array, 必需): Apifox 接口 ID 列表
  • projectId (string, 可选): Apifox 项目 ID

示例:

请查询接口 ID 为 [12345, 12346, 12347] 的信息
请查询项目 1234560 中接口 ID 为 [12345, 12346, 12347] 的信息

3. get_all_interfaces

获取项目中的所有接口列表。

参数:

  • projectId (string, 可选): Apifox 项目 ID
  • limit (number, 可选): 限制返回的接口数量

示例:

获取所有接口列表
获取项目 1234560 的所有接口列表
只获取前 10 个接口

4. search_interfaces

根据关键词搜索接口。

参数:

  • keyword (string, 必需): 搜索关键词
  • projectId (string, 可选): Apifox 项目 ID
  • searchIn (string, 可选): 搜索范围
    • all: 全部(默认)
    • path: 路径
    • summary: 摘要
    • tags: 标签

示例:

搜索包含"用户"的接口
在项目 1234560 中搜索包含"用户"的接口
在接口路径中搜索"login"

5. generate_service_code

根据接口 ID 生成 Service 代码。

参数:

  • endpointId (number, 必需): Apifox 接口 ID
  • projectId (string, 可选): Apifox 项目 ID
  • language (string, 必需): 代码语言类型
    • javascript
    • typescript
  • serviceName (string, 可选): 服务函数名称

示例:

为接口 ID 12345 生成 TypeScript 代码
为项目 1234560 中的接口 ID 12345 生成 TypeScript 代码
为接口 ID 12345 生成 JavaScript 代码,函数名为 getUserInfo

6. get_interface_summary

获取接口的简要信息摘要。

参数:

  • endpointId (number, 必需): Apifox 接口 ID
  • projectId (string, 可选): Apifox 项目 ID

示例:

获取接口 ID 12345 的简要信息
获取项目 1234560 中接口 ID 12345 的简要信息

输出格式

接口详细信息

包含以下内容:

  • 基本信息(路径、方法、标签、目录、状态)
  • 描述
  • 请求参数(路径参数、查询参数、请求头)
  • 请求体
  • 响应信息

代码生成

生成 Service 代码:

  • 使用原生 fetch,零运行时依赖
  • 支持路径参数、查询参数、请求体
  • 包含完整的 JSDoc/TypeScript 类型注释

开发

# 开发模式(带热重载)
npm run dev

# 构建
npm run build

# 运行
npm start

故障排查

1. 初始化失败

检查环境变量是否正确设置:

echo $APIFOX_ACCESS_TOKEN
echo $APIFOX_PROJECT_ID

2. API 请求失败

  • 确认 API Token 是否有效
  • 确认项目 ID 是否正确
  • 检查网络连接

3. 接口不存在

确认接口 ID 是否存在于当前项目中。

许可证

MIT

贡献

欢迎提交 Issue 和 Pull Request!