Model Context Protocol server for YApi 1.12.0 API management platform
Project description
YApi MCP Server
基于 YApi 1.12.0 接口管理平台的 Model Context Protocol (MCP) 服务器。
使开发者能够在支持 MCP 的 IDE 和编辑器(Claude Code、Cursor 等)中直接搜索、查看、创建和更新 YApi 接口定义,无需离开开发环境。
功能特性
- 🔍 搜索接口: 通过标题、路径或描述查找 API 端点
- 📖 查看定义: 获取完整的接口规范,包括请求/响应结构
- ➕ 创建接口: 向 YApi 项目添加新的 API 定义
- ✏️ 更新接口: 增量更新现有接口配置(先读后写,仅修改传入字段)
- 🔐 Cookie 认证: 基于会话的安全认证
- ⚡ 异步性能: 基于 httpx 实现高效的并发操作
- 🛡️ 启动验证: 服务启动时自动校验 Cookie 有效性,失效时立即报错退出
- 📝 Markdown 支持: 接口描述支持 Markdown 格式,自动转换为 HTML
MCP 工具
yapi_search_interfaces — 搜索接口
在指定项目中通过关键词搜索接口(匹配标题/路径/描述)。
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
project_id |
int | ✅ | YApi 项目 ID |
keyword |
str | ✅ | 搜索关键词 |
返回: 接口摘要数组 JSON(_id, title, path, method)
yapi_get_interface — 获取接口详情
获取单个接口的完整定义,包括请求/响应结构、描述等。
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
interface_id |
int | ✅ | 接口 ID |
返回: 完整接口对象 JSON
yapi_create_interface — 创建接口
在 YApi 项目中创建新接口。
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
project_id |
int | ✅ | 项目 ID |
catid |
int | ✅ | 分类 ID |
title |
str | ✅ | 接口标题 |
path |
str | ✅ | 接口路径(以 / 开头) |
method |
str | ✅ | HTTP 方法(GET/POST/PUT/DELETE/PATCH/HEAD/OPTIONS) |
req_body |
str | — | 请求体(JSON Schema 字符串) |
req_body_type |
str | — | 请求体类型(form/json/raw/file) |
req_body_is_json_schema |
bool | — | 请求体是否为 JSON Schema 格式 |
req_body_form |
str | — | 表单字段(JSON 数组),示例: [{"name":"x","type":"text","required":"1","desc":"说明"}] |
req_query |
str | — | Query 参数(JSON 数组),示例: [{"name":"page","required":"1","desc":"页码"}] |
req_headers |
str | — | 请求头(JSON 数组),示例: [{"name":"Authorization","value":"Bearer token","required":"1"}] |
req_params |
str | — | 路径参数(JSON 数组),示例: [{"name":"id","example":"123","desc":"用户ID"}] |
res_body |
str | — | 响应体(JSON Schema 字符串) |
res_body_type |
str | — | 响应体类型(json/raw) |
res_body_is_json_schema |
bool | — | 响应体是否为 JSON Schema 格式 |
markdown |
str | — | 接口描述(Markdown 格式,自动转 HTML) |
status |
str | — | 接口状态(undone/done) |
tag |
str | — | 标签(JSON 数组) |
api_opened |
bool | — | 是否公开 API |
返回: {"action": "created", "interface_id": <id>}
yapi_update_interface — 更新接口
增量更新接口定义。仅需传入要修改的字段,其余字段自动保留原值(先读后写)。
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
interface_id |
int | ✅ | 接口 ID |
title |
str | — | 新标题 |
path |
str | — | 新路径(以 / 开头) |
method |
str | — | 新 HTTP 方法 |
catid |
int | — | 新分类 ID |
req_body |
str | — | 请求体(JSON Schema) |
req_body_type |
str | — | 请求体类型 |
req_body_is_json_schema |
bool | — | 请求体是否为 JSON Schema 格式 |
req_body_form |
str | — | 表单字段(JSON 数组),示例: [{"name":"x","type":"text","required":"1","desc":"说明"}] |
req_query |
str | — | Query 参数(JSON 数组),示例: [{"name":"page","required":"1","desc":"页码"}] |
req_headers |
str | — | 请求头(JSON 数组),示例: [{"name":"Authorization","value":"Bearer token","required":"1"}] |
req_params |
str | — | 路径参数(JSON 数组),示例: [{"name":"id","example":"123","desc":"用户ID"}] |
res_body |
str | — | 响应体(JSON Schema) |
res_body_type |
str | — | 响应体类型 |
res_body_is_json_schema |
bool | — | 响应体是否为 JSON Schema 格式 |
markdown |
str | — | 接口描述(Markdown 格式) |
status |
str | — | 接口状态 |
tag |
str | — | 标签(JSON 数组) |
api_opened |
bool | — | 是否公开 API |
switch_notice |
bool | — | 是否通知团队成员 |
message |
str | — | 变更说明 |
返回: {"action": "updated", "interface_id": <id>}
环境要求
- Python 3.11 或更高版本
- YApi 1.12.0 实例(可通过 HTTP/HTTPS 访问)
- 有效的 YApi 认证 cookies
配置
1. 获取 YApi Cookies
- 在浏览器中登录 YApi 实例
- 打开开发者工具(F12)
- 导航到 Application → Cookies(Chrome) 或 Storage → Cookies(Firefox)
- 复制以下 cookie 值:
_yapi_token(必需)_yapi_uid(必需)ZYBIPSCAS(可选,仅某些自定义部署需要)
2. 配置 MCP
{
"mcpServers": {
"yapi": {
"command": "uvx",
"args": ["yapi-mcp"],
"env": {
"YAPI_SERVER_URL": "https://your-yapi-instance.com",
"YAPI_TOKEN": "your_token",
"YAPI_UID": "your_uid"
}
}
}
}
注意: 如果你的 YApi 部署需要额外的 CAS 认证,添加
"YAPI_CAS": "your_cas_value"到env中。
开发
运行测试
# 安装开发依赖
pip install -e ".[dev]"
# 运行所有测试
pytest
# 运行并显示覆盖率
pytest --cov=src --cov-report=term-missing
# 运行特定测试文件
pytest tests/test_config.py
代码质量
# 格式化代码
ruff format
# 代码检查
ruff check
# 自动修复检查问题
ruff check --fix
项目结构
yapi-mcp/
├── src/
│ └── yapi_mcp/ # Python 包
│ ├── server.py # MCP 服务器入口 + 工具定义
│ ├── config.py # 配置模型
│ └── yapi/
│ ├── client.py # YApi API 客户端
│ ├── models.py # Pydantic 数据模型
│ └── errors.py # 错误映射
├── tests/ # 测试套件
├── pyproject.toml # 项目配置
├── .env.example # 环境变量模板
└── README.md # 本文件
贡献
欢迎贡献! 我们非常感谢各种形式的贡献,包括但不限于:
- 🐛 报告 Bug
- ✨ 建议新功能
- 📝 改进文档
- 💻 提交代码
在开始贡献之前,请阅读我们的贡献指南。
快速开始
- Fork 本仓库
- 创建功能分支 (
git checkout -b feature/amazing-feature) - 提交更改 (
git commit -m 'feat: 添加惊人的功能') - 推送到分支 (
git push origin feature/amazing-feature) - 创建 Pull Request
代码质量要求
- ✅ 所有测试通过:
pytest - ✅ 代码已格式化:
ruff format - ✅ 无检查错误:
ruff check - ✅ 新功能包含测试
详细信息请参阅 CONTRIBUTING.md。
许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
相关项目
- YApi - API 管理平台
- fastmcp - Python MCP 框架
- Model Context Protocol - MCP 规范
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yapi_mcp-0.1.7.tar.gz.
File metadata
- Download URL: yapi_mcp-0.1.7.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aeeaa97590606367a3997b656a2e1b17865b3a1472f22067cb63d4596ce46014
|
|
| MD5 |
9599b70bac71a6b72fa485cfb1316954
|
|
| BLAKE2b-256 |
e6e31db05b3021d45760a538bd285be3c8f0aca4abd564b4fd16e570cbe25d63
|
File details
Details for the file yapi_mcp-0.1.7-py3-none-any.whl.
File metadata
- Download URL: yapi_mcp-0.1.7-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12b7193f5af132ca4ec5b526d36ac4fcb4e0bcc42be943cd3bab6618157793b8
|
|
| MD5 |
4948bb6104bd4479028acc8ca40d4ac3
|
|
| BLAKE2b-256 |
bd1c6787c42738d969ed877f653f1ee3e96885984a249f92e0420fa639986a47
|