npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yapi-to-nestjs-mcp

v1.0.0

Published

一个用于将YAPI接口转换为NestJS接口的MCP服务器

Downloads

103

Readme

YAPI to NestJS MCP Server

一个用于将 YAPI 接口转换为 NestJS 代码的 MCP (Model Context Protocol) 服务器。通过与 AI 编程助手(如 Cursor、Claude Desktop)集成,可以快速从 YAPI 接口文档自动生成 NestJS 代码模板。

✨ 功能特性

  • 🔍 接口查询 - 根据接口 ID 获取 YAPI 接口详细信息
  • 📂 分组管理 - 获取指定分组下的所有接口列表
  • 🚀 代码生成 - 自动生成 NestJS 代码模板(Controller、Service、DTO、Module)
  • 🔐 安全认证 - 通过邮箱密码登录 YAPI,自动管理会话

📦 安装

前置要求

  • Node.js >= 18.0.0
  • pnpm 包管理器

安装步骤


# 安装依赖
pnpm install

# 构建项目
pnpm build

🔧 配置

在 Cursor 中配置

在 Cursor 设置中添加 MCP 服务器配置:

{
  "mcpServers": {
    "yapi-get-interface-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "yapi-get-interface-mcp",
        "--email", "[email protected]",
        "--password", "your-password",
        "--url", "https://yapi.yourcompany.com"
      ],
    }
  }
}

命令行参数

| 参数 | 必填 | 说明 | |------|------|------| | --email | ✅ | YAPI 登录邮箱 | | --password | ✅ | YAPI 登录密码 | | --url | ✅ | YAPI 服务器地址(如:https://yapi.example.com) |

🛠️ 可用工具

1. yapi-get-interface

根据接口 ID 获取 YAPI 接口详情。

参数:

  • id (string) - 接口 ID(数字格式)

使用示例:

获取接口 ID 为 12345 的详情

返回数据:

  • 接口基本信息(标题、路径、方法)
  • 请求参数(query、body、headers)
  • 响应数据结构
  • 接口状态和元数据

2. yapi-get-interfaces-by-category

根据分组标识获取该分组下的所有接口列表。

参数:

  • catid (string) - 分组标识,必须以 cat_ 开头(如:cat_5446
  • page (number, 可选) - 页码,默认为 1
  • limit (number, 可选) - 每页数量,默认为 20

使用示例:

获取分组 cat_5446 下的所有接口

3. yapi-generate-nestjs-code

根据 YAPI 分组标识获取所有接口详情并生成 NestJS 代码模板。

参数:

  • catid (string) - 分组标识,必须以 cat_ 开头(如:cat_5446
  • moduleName (string, 可选) - 模块名称,用于生成文件名和类名

使用示例:

根据分组 cat_5446 生成 NestJS 代码,模块名为 User

生成内容:

  • *.module.ts - NestJS 模块文件
  • *.controller.ts - 控制器,包含路由和 Swagger 装饰器
  • *.service.ts - 服务层,封装 HTTP 请求逻辑
  • *.dto.ts - 数据传输对象,包含验证装饰器

📝 使用示例

示例 1:查询接口详情

在 AI 助手中输入:

帮我查看 YAPI 接口 ID 36839 的详细信息

示例 2:生成 NestJS 代码

在 AI 助手中输入:

请根据 YAPI 分组 cat_5446 生成 NestJS 代码,模块名为 Order

AI 助手将自动调用工具并生成完整的 NestJS 代码模板。

🏗️ 生成的代码示例

Controller

@Controller('order')
@ApiTags('订单服务——Order')
@ApiBasicAuth('JWT-auth')
@UseGuards(AuthGuard)
export class OrderController {
    constructor(private readonly orderService: OrderService) {}

    @Post('create')
    @ApiOperation({ summary: '创建订单' })
    @ApiBody({ type: CreateOrderDto })
    @UseInterceptors(TransformInterceptor)
    async createOrder(@Body() data: CreateOrderDto) {
        return await this.orderService.createOrder(data);
    }
}

Service

@Injectable()
export class OrderService {
    constructor(private httpService: HttpService) {}

    async createOrder(data: CreateOrderDto) {
        try {
            const result = await this.httpService.postWithService(
                'order-service', 
                'order/create', 
                data
            );
            return getResponseFormHomoService(result);
        } catch (error) {
            throw error;
        }
    }
}

DTO

export class CreateOrderDto {
    @ApiProperty({ description: '商品ID' })
    @IsString({ message: 'productId需为String类型' })
    productId: string;

    @ApiProperty({ description: '数量' })
    @IsNumber({}, { message: 'quantity需为Number类型' })
    @Type(() => Number)
    quantity: number;

    @ApiPropertyOptional({ description: '备注' })
    @IsOptional()
    remark?: string;
}

📂 项目结构

yapi-to-nestjs-mcp/
├── src/
│   ├── index.ts              # 入口文件
│   ├── config/
│   │   └── yapi-config.ts    # YAPI 配置管理
│   ├── server/
│   │   ├── server.ts         # MCP 服务器
│   │   ├── tools.ts          # 工具定义和实现
│   └── yapi/
│       └── client.ts         # YAPI API 客户端
├── dist/                     # 构建输出
├── package.json
└── README.md

🔨 开发

# 开发模式(监听文件变化)
pnpm watch

# 构建
pnpm build

# 运行 MCP Inspector 调试
pnpm inspector

# 启动服务
pnpm start

📋 依赖项

| 依赖 | 说明 | |------|------| | @modelcontextprotocol/sdk | MCP 协议 SDK | | axios | HTTP 客户端 | | yargs | 命令行参数解析 | | zod | 类型验证 |