yapi-mcp-server
An MCP server that enables fetching YApi interface details via a tool, allowing AI assistants to generate API code based on YApi documentation.
README
yapi-mcp-server
简介
yapi-mcp-server 是 Model Context Protocol (MCP) 的服务端实现。支持通过 MCP 协议获取 YApi 接口详情。
快速开始
全局
node环境需>=18
配置 mcp.json
在项目根目录下新建或编辑 mcp.json 文件,内容如下:
{
"mcpServers": {
"yapi-mcp-server": {
"command": "npx",
"args": [
"-y",
"yapi-mcp-server",
"--yapiToken=你的YApiToken",
"--yapiHost=https://yapi.xxx.net"
]
}
}
}
你的YApiToken替换为实际的 YApi Token(token 获取路径:yapi 项目->设置->token 配置->工具标识)https://yapi.xxx.net替换为你的 YApi 服务域名
MCP Server 功能
- 工具名:
yapi_get_apis_detail - 功能:批量获取 YApi 接口的详细信息。
- 参数:
apiIds:YApi 接口 ID 组成的数组。例如,接口地址为/project/1/interface/api/66,则 ID 为66。支持同时传入多个 ID。
- 返回值:对应接口的详细信息对象数组,结构与 YApi 返回一致。
实践
mcp配置成功之后,直接对cursor说:
生成接口代码
@api/index.ts
@https://yapi.XXX.net/project/13533/interface/api/1554281
@https://yapi.XXX.net/project/13533/interface/api/1554288
@https://yapi.XXX.net/project/13533/interface/api/1554334
cursor就会调用yapi-mcp-server获取接口的信息,并根据项目代码规范,生成对应的接口代码,比如:
// 删除组织:https://yapi.XXX.net/project/13533/interface/api/1554334
export function deleteOrg(data: { id: number }) {
return axios({
url: "/goapi/admin/org/delete",
method: "post",
data,
headers: {
"Content-Type": "application/json",
},
});
}
ai 可以给 接口函数起名字,爽歪歪!
制定规范,使生成的接口代码更符合规范
在 .cursorrules 文件中,编写接口代码的规范,比如:
// .cursorrules
接口代码规范:
- apiName 驼峰且动词前置,保持简洁
- 使用 axiosInstance
- 注释需包含接口名和 yapi 文档链接
- headers 有需要再加
import { axiosInstance as axios } from '@/api/axiosToken'
// {{$value.title}}:{{$value.yapiDocUrl}}
export function {{$value.apiName}}(data) {
return axios({
url: '{{$value.path}}',
method: '{{$value.method}}',
data,
// headers: { ... } // 如有自定义 header 再补充
})
}
参考链接
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.