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

mcp-api-gen

v0.2.1

Published

一个前端 API 生成工具,支持 AI 编辑器直接生成、内网 OpenAPI 2/3 解析、1000+ 接口约 1 秒生成。

Readme

mcp-api-gen

npm license node TypeScript MCP

OpenAPI 接口生成工具,支持在 AI 编辑器中生成前端 API 。

  • 🌐 支持内网 OpenAPI 2 / 3 文档解析
  • ⚡ 1000+ 接口约 1 分钟完成
  • 🧩 用户提供示例(基于模板批量生成)

功能演示

默认模板生成(axios):

用户提供 API 示例生成:

快速开始

请确保已安装 Node.js(>= 20)。

1、配置 MCP:

在你的 AI 编辑器(如 Cursor / Trae)中添加 MCP 配置:

{
  "mcpServers": {
    "mcp-api-gen": {
      "command": "npx",
      "args": ["-y", "mcp-api-gen@latest"]
    }
  }
}

2、一句话生成

在 AI 编辑器中输入提问:

默认输出(生成到 ./api.ts

使用MCP根据 http://localhost:3000/api-docs.json 生成前端API文件,不要自行生成代码

指定输出位置

使用MCP根据 http://localhost:3000/api-docs.json 生成前端API文件到 ./service/api.ts,不要自行生成代码

说明:http://localhost:3000/api-docs.json 地址需本地运行此项目的 playground 文档服务

3、自定义生成风格(提供 API 示例)

在 AI 编辑器中输入提问:

使用 MCP 根据 http://localhost:3000/api-docs.json 生成 API,不要自行生成代码。

参考示例:
import request from 'axios';

// API 前缀
const prefix = '/user'

/**
 * 根据ID获取用户
 */
export function getUserById(params: { id: number }): Promise<UserDetail> {
  return request.get(`${prefix}/user/${params.id}`, { params })
}

为什么做 mcp-api-gen?

因为当我尝试使用 AI 编辑器来生成 api 文件时,遇到了这几个问题:

  • ❌ 内网 OpenAPI 文档无法读取
  • ❌ 大量接口生成结果不稳定(上下文截断、格式可能变)
  • ❌ Token 消耗高、生成耗时长

我依次尝试了这几类方法:

  • V0:AI 编辑器直接读取 OpenAPI 地址(初次尝试 AI 接入开发流)。
  • V1:MCP 读取内网接口提供给 AI 编辑器(解决内网解析问题)
  • V2:MCP 分段读取内网接口提供给 AI(解决大量接口上下文截断问题)
  • 当前:MCP 直接生成 API 文件(解决上述问题,且生成极快、Token 消耗极低、结果稳定)

最终诞生了 mcp-api-gen

功能特性

  • ✅ 内网文档解析
  • ✅ 基于示例解析 + 模板渲染
  • ✅ AI 编辑器直接生成 API 文件(Cursor / Trae)
  • ✅ 支持用户提供请求示例
  • ✅ 生成完整 TypeScript 类型
  • ✅ 支持 OpenAPI 2 / 3
  • ✅ Token 消耗极低
  • ✅ 大量接口生成极快(1000+ 接口约 1 秒生成)

请求方式说明

默认按 axios 风格生成,生成结果由示例代码决定,不做额外结构转换。

request.get(url, { params });
request.post(url, { data });

本地开发

1、启动项目

要求 Node.js 版本 >= 20。

# 安装依赖
pnpm i

# 构建(开发模式)
pnpm dev

# Tool 测试
pnpm debug

# MCP 调试
pnpm debug:mcp

2、运行文档示例

启动 playground 文档服务,确认以下地址可访问:

http://localhost:3000/api-docs.json
# 启动文档
pnpm docs:playground

基准测试

./playground/README.md#基准测试