@bearst/yapi-mcp-server
v0.1.3
Published
A robust MCP server for YApi with token and cookie authentication.
Downloads
586
Maintainers
Readme
yapi-mcp-server
中文 | English
一个面向 YApi 的现代 MCP Server。目标是提供开箱即用、配置简单、读写完整、适合日常接口管理工作流的 YApi MCP 接入。
特性
- 基于官方
@modelcontextprotocol/sdk构建,支持标准 stdio MCP 传输。 - 支持通过
npx -y @bearst/yapi-mcp-server启动。 - 支持项目 Token 和浏览器 Cookie 两种认证方式。
- 支持单项目和多项目 Token,格式简单直观。
- 支持读取项目、分类、接口菜单、接口列表和接口详情。
- 支持按标题、路径、方法搜索接口。
- 支持创建分类、创建接口、更新接口、保存接口。
- 支持导入 Swagger/OpenAPI 数据。
- 提供
yapi_raw_request作为高级扩展工具,用于兼容自定义 YApi API。
快速开始
npx -y @bearst/yapi-mcp-serverGitHub 方式:
npx -y github:BearstOzawa/yapi-mcp-serverCodex 配置
单项目 Token:
{
"command": "npx",
"args": ["-y", "@bearst/yapi-mcp-server"],
"env": {
"YAPI_BASE_URL": "https://your-yapi.example.com",
"YAPI_TOKEN": "project-token"
}
}带项目 ID 的 Token:
{
"command": "npx",
"args": ["-y", "@bearst/yapi-mcp-server"],
"env": {
"YAPI_BASE_URL": "https://your-yapi.example.com",
"YAPI_TOKEN": "40:project-token"
}
}多项目 Token:
{
"command": "npx",
"args": ["-y", "@bearst/yapi-mcp-server"],
"env": {
"YAPI_BASE_URL": "https://your-yapi.example.com",
"YAPI_TOKEN": "40:project-token-a,41:project-token-b"
}
}Cookie:
{
"command": "npx",
"args": ["-y", "@bearst/yapi-mcp-server"],
"env": {
"YAPI_BASE_URL": "https://your-yapi.example.com",
"YAPI_COOKIE": "_yapi_token=xxx; _yapi_uid=158"
}
}Cookie 不包含项目 ID。只配置 Cookie 时,查询项目、分类、接口列表等项目级数据需要在工具调用中传 project_id。
环境变量
YAPI_TOKEN 和 YAPI_COOKIE 至少设置一个。
YAPI_BASE_URL:YApi 服务地址,例如https://yapi.example.com。YAPI_TOKEN:YApi 项目 Token。支持普通 token,也支持项目ID:token,项目ID:token多项目格式。YAPI_COOKIE:YApi 登录态 Cookie,例如_yapi_token=...; _yapi_uid=...。YAPI_REQUEST_TIMEOUT_MS:可选的请求超时时间,默认30000。YAPI_DEBUG:可选调试日志,输出到 stderr,不打印 token 和 cookie 原文。
如果 YAPI_TOKEN 只配置了一个 项目ID:token,该项目会自动作为默认项目。多项目时,项目级工具需要传 project_id。
工具
只读工具:
yapi_list_configured_projectsyapi_get_projectyapi_get_category_menuyapi_list_menuyapi_list_interfacesyapi_list_category_interfacesyapi_search_interfacesyapi_get_interface
写入工具:
yapi_add_categoryyapi_add_interfaceyapi_update_interfaceyapi_save_interfaceyapi_import_data
高级工具:
yapi_raw_request:调用自定义/api/*接口,会自动附带已配置的认证信息。
yapi_list_configured_projects 会返回当前认证配置摘要,包括 hasToken、hasCookie、projectIdRequired 和从 YAPI_TOKEN 中解析出的项目 ID。
开发
npm install
npm run typecheck
npm run build
npm run lint
npm run smoke本地运行:
YAPI_BASE_URL="https://your-yapi.example.com" \
YAPI_TOKEN="40:project-token" \
npm run dev发布
发布由 GitHub Actions 完成:
- 在 GitHub 仓库 Settings -> Secrets and variables -> Actions 中添加
NPM_TOKEN。 NPM_TOKEN使用 npm granular access token,需具备发布@bearst/yapi-mcp-server的权限。- 更新
package.json版本并合并到main。 - 在 GitHub 创建 Release,或手动运行
Publishworkflow。
CI 会在 push 和 pull request 时运行:
npm cinpm run typechecknpm run lintnpm run smokenpm pack --dry-run
English
A modern MCP server for YApi. It is designed to be easy to configure, convenient to run with npx, and complete enough for everyday API management workflows.
Features
- Built with the official
@modelcontextprotocol/sdk. - Standard stdio MCP transport.
- Starts with
npx -y @bearst/yapi-mcp-server. - Supports project token and browser cookie authentication.
- Supports single-project and multi-project tokens with a simple format.
- Reads projects, categories, interface menus, interface lists, and interface details.
- Searches interfaces by title, path, or method.
- Creates categories and creates, updates, or saves interfaces.
- Imports Swagger/OpenAPI data.
- Provides
yapi_raw_requestas an advanced extension tool for custom YApi APIs.
Quick Start
npx -y @bearst/yapi-mcp-serverGitHub package:
npx -y github:BearstOzawa/yapi-mcp-serverCodex Configuration
Single project token:
{
"command": "npx",
"args": ["-y", "@bearst/yapi-mcp-server"],
"env": {
"YAPI_BASE_URL": "https://your-yapi.example.com",
"YAPI_TOKEN": "project-token"
}
}Token with project ID:
{
"command": "npx",
"args": ["-y", "@bearst/yapi-mcp-server"],
"env": {
"YAPI_BASE_URL": "https://your-yapi.example.com",
"YAPI_TOKEN": "40:project-token"
}
}Multi-project token:
{
"command": "npx",
"args": ["-y", "@bearst/yapi-mcp-server"],
"env": {
"YAPI_BASE_URL": "https://your-yapi.example.com",
"YAPI_TOKEN": "40:project-token-a,41:project-token-b"
}
}Cookie:
{
"command": "npx",
"args": ["-y", "@bearst/yapi-mcp-server"],
"env": {
"YAPI_BASE_URL": "https://your-yapi.example.com",
"YAPI_COOKIE": "_yapi_token=xxx; _yapi_uid=158"
}
}Cookies do not contain project IDs. With cookie-only configuration, project-scoped tools such as project, category, and interface-list queries should pass project_id.
Environment Variables
Set at least one of YAPI_TOKEN and YAPI_COOKIE.
YAPI_BASE_URL: YApi base URL, for examplehttps://yapi.example.com.YAPI_TOKEN: YApi project token. Supports a plain token orprojectId:token,projectId:token.YAPI_COOKIE: YApi login cookie, for example_yapi_token=...; _yapi_uid=....YAPI_REQUEST_TIMEOUT_MS: optional request timeout, default30000.YAPI_DEBUG: optional request logging to stderr. Token and cookie values are not printed.
If YAPI_TOKEN contains exactly one projectId:token, that project is used as the default project automatically. With multiple projects, project-scoped tools should pass project_id.
Tools
Read tools:
yapi_list_configured_projectsyapi_get_projectyapi_get_category_menuyapi_list_menuyapi_list_interfacesyapi_list_category_interfacesyapi_search_interfacesyapi_get_interface
Write tools:
yapi_add_categoryyapi_add_interfaceyapi_update_interfaceyapi_save_interfaceyapi_import_data
Advanced:
yapi_raw_request: calls custom/api/*endpoints with configured authentication attached.
yapi_list_configured_projects returns the current authentication configuration summary, including hasToken, hasCookie, projectIdRequired, and project IDs parsed from YAPI_TOKEN.
Development
npm install
npm run typecheck
npm run build
npm run lint
npm run smokeRun locally:
YAPI_BASE_URL="https://your-yapi.example.com" \
YAPI_TOKEN="40:project-token" \
npm run devPublishing
Publishing is handled by GitHub Actions:
- Add
NPM_TOKENin GitHub repository Settings -> Secrets and variables -> Actions. - Use an npm granular access token with permission to publish
@bearst/yapi-mcp-server. - Update the version in
package.jsonand merge tomain. - Create a GitHub Release, or manually run the
Publishworkflow.
CI runs on push and pull request:
npm cinpm run typechecknpm run lintnpm run smokenpm pack --dry-run
