R

REST转Postman

@runninghare/rest-to-postman
0 Stars 402 次浏览 runninghare 更新于 2026-08-23

将REST API代码(例如NestJS控制器或FastAPI端点)转换为Postman集合和环境,帮助开发人员自动将其API端点与Postman同步。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

REST-to-Postman MCP

smithery badge

这是一个将 REST API 代码(例如 NestJS 控制器、FastAPI/Flask 端点)转换为 Postman 集合和环境的 Model Context Protocol (MCP) 服务器。此工具帮助开发人员自动将其 REST API 端点和环境配置与 Postman 同步。

功能

  • 将 REST API 端点转换为 Postman 集合
  • 与 Postman 环境同步环境变量
  • 支持多种认证方法(例如,Bearer token)
  • 智能合并新端点与现有集合
  • 自动处理敏感环境变量
  • 支持 stdio 和 SSE 传输模式

前提条件

  • Bun v1.2.2 或更高版本
  • Postman API 密钥
  • Postman 工作区 ID

安装与使用

这是一个需要访问您的 Postman 工作区以创建/更新集合和环境的 Model Context Protocol (MCP) stdio 服务器。

通过 Smithery 安装

要通过 Smithery 自动为 Claude Desktop 安装 REST-to-Postman MCP:

npx -y @smithery/cli install @runninghare/rest-to-postman-mcp --client claude

使用 npx 运行 MCP 服务器

要使用 npx 使用 MCP 服务器:

npx -y rest-to-postman@latest --postman-api-key your_api_key --postman-workspace-id your_workspace_id

或者使用环境变量:

export POSTMAN_API_KEY=your_api_key
export POSTMAN_ACTIVE_WORKSPACE_ID=your_workspace_id
npx -y rest-to-postman@latest 

您可以将此命令与支持 MCP 的各种 AI 代码编辑器集成:

  • Claude Desktop
  • Cursor
  • Windsurf
  • Roo Cline Editor

重要提示:服务器需要 Postman API 凭证才能运行。请确保在启动服务器之前准备好 API 密钥和工作区 ID。

工具描述

该服务器提供了两个主要工具:

1. REST 到 Postman 环境 (rest_to_postman_env)

使用应用程序的环境变量创建或更新 Postman 环境。

输入参数:

  • envName (字符串): Postman 环境名称
  • envVars (对象): 环境变量的键值对

示例输入:

{
    "envName": "REST Environment",
    "envVars": {
        "API_URL": "https://api.example.com",
        "API_TOKEN": "secret-token-1"
    }
}

2. REST 到 Postman 集合 (rest_to_postman_collection)

使用您的 REST API 端点创建或更新 Postman 集合。

输入参数:

  • collectionRequest (对象): 包含以下内容的 Postman 集合配置
    • info: 集合元数据
    • auth: 认证设置
    • item: API 端点数组

示例输入:

{
    "info": {
        "name": "REST Collection",
        "description": "REST Collection", 
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "auth": {
        "type": "bearer",
        "bearer": [
            {   
                "key": "Authorization",
                "value": "Bearer {{API_TOKEN}}",
                "type": "string"
            }
        ]
    },  
    "item": [
        {
            "name": "Get Users",
            "request": {
                "method": "GET",    
                "url": {
                    "raw": "{{API_URL}}/users",
                    "protocol": "https",
                    "host": ["api", "example", "com"],
                    "path": ["users"]
                }   
            }
        }
    ]
}

响应格式

这两个工具都返回一个成功消息,确认已创建/更新 Postman 资源:

{
    "content": [{
        "type": "text",
        "text": "Successfully created/updated Postman environment: REST Environment"
    }]
}

在 Cursor 中使用此 MCP

您可以在 Cursor 中使用此 MCP 服务器。下面是一个基于 Nest.js Typescript 控制器生成 Postman 集合的例子。

提示:

Create a postman collection named "Campaign Endpoints" based on this next.js controller. The baseUrl is `http://localhost:7022`. The collection should have a Bear token which applies to all the endpoints

这是自动生成的 Postman 集合:

注意Campaign控制器生成的所有端点,以及Bear令牌设置。

开发

本地设置

  1. 克隆仓库:
git clone https://github.com/runninghare/rest-to-postman.git
cd rest-to-postman
  1. 安装依赖项:
bun install
  1. 创建一个.env文件:
POSTMAN_API_KEY=your_api_key_here
POSTMAN_ACTIVE_WORKSPACE_ID=your_workspace_id_here

在开发模式下运行

在开发过程中,你可以直接使用Bun来运行服务器:

# Start in stdio mode (default)
bun run src/mcp.ts

# Start in SSE mode
bun run src/mcp.ts --sse

构建

要构建项目:

bun run build

这将在dist目录中创建打包后的输出。

脚本

  • bun run build - 构建项目
  • bun run dev - 以开发模式运行服务器
  • bun run startSSE - 以SSE模式启动服务器

贡献

欢迎贡献!请随时提交Pull Request。

许可证

该项目根据MIT许可证授权 - 详情请参阅LICENSE文件。

相关 MCP 服务