Sponsored by Deepsite.site

Yapi Mcp

Created By
tianlu2 months ago
这是一个 Model Context Protocol (MCP) 服务器,用于与 YApi 接口管理平台集成,支持自动生成 TypeScript 类型定义、Mock 数据和 API 请求代码。
Content

YApi MCP Server

这是一个 Model Context Protocol (MCP) 服务器,用于与 YApi 接口管理平台集成,支持自动生成 TypeScript 类型定义、Mock 数据和 API 请求代码。

✨ 功能特性

🔧 核心功能

  • 配置文件读取: 自动读取项目中的 yapi.config.json 配置文件
  • YApi 数据获取: 通过配置的 remoteUrl 获取 YApi 项目的完整接口信息(支持缓存)
  • TypeScript 类型生成: 根据接口响应 Schema 自动生成 TypeScript interface 定义
  • Mock 数据生成: 智能生成符合接口结构的 Mock 测试数据
  • API 请求代码生成: 自动生成 Axios 或 Fetch 风格的 API 请求函数
  • 智能缓存机制: 自动缓存 YApi 数据 30 分钟,减少网络请求

✨ 快速开始

1. cursor 中安装 yapi-mcp-server

{
	"mcpServers": {
		"yapi-mcp": {
			"command": "npx",
			"args": ["-y", "@vtian/yapi-mcp-server", "--stdio"]
		}
	}
}

2. 获取 yapi 参数

yapi设置

3. 项目中配置 yapi.config.json

在您的前端项目根目录下创建 yapi.config.json 文件:

{
	"remoteUrl": "https://your-yapi-domain.com/api/open/plugin/export-full?type=json&pid=1437&status=all&token=your-token",
	"type": "yapi",
	"dataKey": "data",
	"mockPath": "src/mocks",
	"typePath": "src/types",
	"apiPath": "src/api"
}

必填字段

  • remoteUrl: YApi 项目导出接口 URL
  • type: 平台类型,固定为 "yapi"

可选字段

  • dataKey: 响应数据字段名,默认 "data"
  • mockPath: Mock 文件输出路径,默认 "src/mocks"
  • typePath: 类型文件输出路径,默认 "src/types"
  • apiPath: API 代码输出路径,默认 "src/api"

✨ 可用工具

本项目提供以下 5 个 MCP 工具,可以通过支持 MCP 协议的客户端(如 Claude Desktop、cursor)调用:

1️⃣ read_config - 读取配置文件

从项目中查找并读取 yapi.config.json 配置文件。

2️⃣ get_yapi_data - 获取 YApi 数据

从 YApi 服务器获取接口数据,支持缓存机制(30 分钟)。

3️⃣ generate_types - 生成 TypeScript 类型

根据接口 JSON Schema 生成 TypeScript 类型定义。

4️⃣ generate_mock_from_yapi - 生成 Mock 数据

根据接口 Schema 智能生成符合结构的 Mock 数据。

5️⃣ generate_api_code - 生成 API 请求代码

生成 Axios 或 Fetch 风格的 API 请求函数代码。

✨ prompt 使用

🔧 yapi 中有哪些接口?

🔧 帮我更新一下 yapi 接口数据

🔧 帮我生成 109220 的 mock 数据

  • 可以是 yapi 上接口对应的 id,也可以直接是接口名称

🔧 帮我根据接口 109220 更新对应的 ts 类型

  • 可以是 yapi 上接口对应的 id,也可以直接是接口名称

🔧 帮我根据接口 109220 生成 axios 代码

  • 效果同上

✨ 生成的文件示例

TypeScript 类型定义

/** 用户信息接口 */
export interface UserInfoData {
	/** 用户ID */
	userId: number
	/** 用户名 */
	username: string
	/** 邮箱 */
	email: string
}

API 请求代码 (Axios)

/**
 * 用户信息接口
 */
export const getUserInfo = async (): Promise<UserInfoData> => {
	const response = await axios.get('/api/user/info')
	return response.data
}

Mock 数据

{
	"code": "200",
	"success": true,
	"message": "操作成功",
	"data": {
		"userId": 12345,
		"username": "测试用户",
		"email": "test@example.com"
	}
}

Server Config

{
  "mcpServers": {
    "yapi-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@vtian/yapi-mcp-server",
        "--stdio"
      ]
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Serper MCP ServerA Serper MCP Server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Playwright McpPlaywright MCP server
Tavily Mcp
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Amap Maps高德地图官方 MCP Server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
WindsurfThe new purpose-built IDE to harness magic
DeepChatYour AI Partner on Desktop
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
ChatWiseThe second fastest AI chatbot™
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
CursorThe AI Code Editor
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.