zhenai-yapi-mcp
v1.0.3
Published
MCP server for YApi documentation management - retrieve API docs and collections from YApi
Downloads
29
Maintainers
Readme
yapi-mcp-server
一个用于YApi的 MCP (Model Context Protocol) 服务器,允许 Claude 和其他 AI 助手获取 API 文档和集合信息。
功能特性
- 🔍 getApiDoc: 获取指定接口的详细文档
- 📚 getApiList: 获取指定接口集合
- 🔐 支持 Cookie 认证
- 📝 结构化的 API 文档格式
- ⚡ 基于 MCP 协议的高效通信
安装
npm install yapi-mcp-server配置
在使用前,需要设置以下环境变量:
export COOKIE="yapi_cookie_string"
export BASE_URL="https://your-yapi-domain.com"Claude Desktop 配置
在 Claude Desktop 的配置文件中添加:
{
"mcpServers": {
"zhenai-yapi-mcp": {
"command": "/Users/mac/.nvm/versions/node/v20.18.1/bin/node", // 本地node路径
"args": [
"/Users/mac/.nvm/versions/node/v20.18.1/bin/npx", // 本地npx路径
"zhenai-yapi-mcp"
],
"disabled": false,
"env": {
"BASE_URL": "https://xxx.com", // yapi地址
"COOKIE": "" // yapi cookie
}
}
}
}配置文件位置
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
使用方法
获取 API 文档
通过 Claude 调用 getApiDoc 工具:
{
"name": "getApiDoc",
"arguments": {
"id": "123"
}
}返回结果示例:
{
"success": true,
"id": "123",
"title": "获取用户信息",
"path": "/api/user/info",
"method": "GET",
"queryParmas": {
"userId": {
"type": "string",
"description": "用户ID"
}
},
"responseBody": {
"code": {
"type": "number",
"description": "状态码"
},
"data": {
"type": "object",
"description": "用户信息"
}
}
}获取 API 集合
通过 Claude 调用 getApiList 工具:
{
"name": "getApiList",
"arguments": {
"id": "456"
}
}返回结果示例:
{
"success": true,
"id": "456",
"list": [
{
"name": "获取用户信息",
"path": "/api/user/info",
"method": "GET"
},
{
"name": "更新用户信息",
"path": "/api/user/update",
"method": "POST"
}
]
}开发
本地开发
# 克隆项目
git clone https://github.com/yourusername/yapi-mcp-server.git
cd yapi-mcp-server
# 安装依赖
npm install
# 开发模式(直接运行源码)
npm run dev
# 构建项目
npm run build
# 测试MCP服务器
npm test项目结构
yapi-mcp-server/
├── dist/ # 构建输出目录
├── src/ # 源代码目录
│ └── index.js # 主入口文件
├── bin/ # 可执行文件
│ └── yapi-mcp # CLI工具
├── scripts/ # 构建脚本
│ └── build.js # 构建脚本
├── README.md # 项目文档
├── LICENSE # 许可证文件
└── package.json # 项目配置环境变量说明
| 变量名 | 描述 | 示例 |
| ---------- | ---------------- | -------------------------------- |
| COOKIE | YApi 登录 Cookie | _yapi_token=xxx; _yapi_uid=xxx |
| BASE_URL | YApi 服务地址 | https://yapi.example.com |
获取 Cookie 的方法
- 在浏览器中登录 YApi
- 打开开发者工具 → Network
- 刷新页面,找到任意 API 请求
- 复制请求头中的
Cookie值
故障排除
常见问题
认证失败
- 检查 Cookie 是否过期
- 确认 BASE_URL 是否正确
连接错误
- 确保 YApi 服务可访问
- 检查网络连接
权限问题
- 确认用户有访问对应 API 的权限
版本历史
- 1.0.0: 初始版本
- 支持
getApiDoc和getApiList工具 - 基本的 MCP 协议实现
- 支持
