Skip to main content
Glama

Code2Postman MCP

Code2Postman MCP - A Model Context Protocol (MCP) server implementation that automatically converts code directories into Postman collections.

Overview

Code2Postman MCP is an open-source tool that leverages the Model Context Protocol to help developers quickly generate Postman collections from their codebase. This tool analyzes your code files, identifies API endpoints, and creates structured Postman collections that you can use for testing, documentation, and sharing. It is an MCP that generate postman's collection from code and local repositories.

Related MCP server: Postman MCP Generator

Features

  • Code Analysis: Automatically scan your codebase to identify API endpoints and their parameters

  • Collection Generation: Create complete Postman collections with proper structure

  • Folder Organization: Organize endpoints logically in folders based on code structure

  • Variables Support: Add and manage collection variables for greater flexibility

  • Authentication Configuration: Set up authentication methods automatically based on code patterns

  • Event Scripts: Generate pre-request and test scripts when applicable

Supported Tools

  • create_postman_collection - Create a new Postman collection

  • add_postman_collection_item - Add a request item to a collection

  • read_postman_collection - Read an existing Postman collection

  • add_postman_collection_info - Add metadata to a collection

  • add_postman_collection_event - Add pre-request or test scripts

  • add_postman_collection_variable - Add variables to a collection

  • add_postman_collection_auth - Configure authentication for a collection

  • add_postman_collection_protocol_behavior - Configure protocol behaviors

  • delete_postman_collection_item - Remove items from a collection

  • update_postman_collection_variable - Update existing variables

  • add_postman_collection_folder - Create folders for organizing requests

  • add_item_to_folder - Add items to specific folders

  • get_tree_directory_from_path - Get a file tree structure from a directory

  • read_file - Read the contents of a specific file

Installation

pip install code2postman-mcp

Usage with Claude Desktop

  1. Add Code2Postman MCP to your claude_desktop_config.json file:

"code2postman-mcp": {
    "command": "uvx",
    "args": ["code2postman-mcp"]
}
  1. Launch Claude Desktop and start using the MCP tools to analyze your code and generate Postman collections.

Command Line Usage

You can also use Code2Postman MCP directly from the command line:

uvx code2postman-mcp

Examples

Creating a Postman Collection from Source Code

  1. First, analyze your codebase to identify API endpoints.

  2. Create a new Postman collection.

  3. Add identified endpoints as items to the collection.

  4. Configure authentication if needed.

  5. Add collection variables for flexibility.

  6. Export the collection as a JSON file that can be imported into Postman.

Adding to an Existing Collection

You can also extend existing Postman collections by:

  1. Reading an existing collection.

  2. Adding new items or folders.

  3. Updating variables or authentication methods.

  4. Saving the updated collection.

Development

To contribute to Code2Postman MCP:

  1. Clone the repository:

    git clone https://github.com/yourusername/code2postman-mcp.git
  2. Install development dependencies:

    cd code2postman-mcp
    uv pip install -e .
  3. Run tests:

    uv run pytest tests/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Available Tools

14 tools
add_item_to_folderC
Add an item to a specific folder in the Postman collection

Args:
    file_path: The path to the Postman collection file (string)
    folder_name: The name of the folder to add the item to (string)
    item: The item dictionary to add (dict)
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), folder_name (required), item (required).

add_postman_collection_authB
Add or update authentication information for the Postman collection

Args:
    file_path: The path to the Postman collection file (string)
    auth: The auth dictionary with type and necessary auth parameters (dict)
          Example: {
              "type": "bearer",
              "bearer": [
                  {
                      "key": "token",
                      "value": "{{token_variable}}",
                      "type": "string"
                  }
              ]
          }
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), auth (required).

add_postman_collection_eventB
Add an event to the Postman collection

Args:
    file_path: The path to the Postman collection file (string)
    event: The event dictionary with keys like listen, script, etc. (dict)
          Example: {
              "listen": "prerequest",
              "script": {
                  "type": "text/javascript",
                  "exec": ["console.log('This runs before each request');"]
              }
          }
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), event (required).

add_postman_collection_folderB
Add a folder to the Postman collection

Args:
    file_path: The path to the Postman collection file (string)
    folder_name: The name of the folder (string)
    items: Optional list of item dictionaries to add to the folder (list of dicts)
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), folder_name (required), items.

add_postman_collection_infoA
Update or add the info section of a Postman collection

Args:
    file_path: The path to the Postman collection file (string)
    info: The info dictionary to update/add (dict)
          Example: {
              "name": "Updated Collection",
              "description": "Updated description",
              "version": "1.0.0",
              "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
          }
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), info (required).

add_postman_collection_itemB
Add an item to the Postman collection

Args:
    file_path: The path to the Postman collection file (string)
    item: The item dictionary to add (dict containing at least 'name' and 'request' keys)
          Example: {
              "name": "Get User",
              "request": {
                  "method": "GET",
                  "url": "https://api.example.com/users/1"
              }
          }
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), item (required).

add_postman_collection_protocol_behaviorA
Add or update protocol profile behavior settings for the Postman collection

Args:
    file_path: The path to the Postman collection file (string)
    behavior: The protocolProfileBehavior dictionary (dict)
             Example: {
                 "disableBodyPruning": true,
                 "followRedirects": false
             }
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), behavior (required).

add_postman_collection_variableB
Add a variable to the Postman collection

Args:
    file_path: The path to the Postman collection file (string)
    variable: The variable dictionary with keys like key, value, type, etc. (dict)
            Example: {
                "key": "base_url",
                "value": "https://api.example.com",
                "type": "string"
            }
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), variable (required).

create_postman_collectionB
Create a Postman collection from a directory structure. Extension of the file must be .json

Args:
    file_path: The path to the file to create the Postman collection from (string)
    name: The name of the project (string)
    description: The description of the project (string)
Returns:
    The initial Postman collection in JSON format (string)

Inputs: file_path (required), name (required), description (required).

delete_postman_collection_itemA
Delete an item from the Postman collection by name

Args:
    file_path: The path to the Postman collection file (string)
    item_name: The name of the item to delete (string)
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), item_name (required).

get_tree_directory_from_pathA
Generate a tree directory structure as a string, excluding files and directories
based on the specified programming language using regex patterns.

Args:
    path: The root path to start generating the tree from
    language: The programming language to filter files. Possible values: ["python", "javascript", "java", "go", "ruby", "rust", "csharp", "generic"]
    
Returns:
    A formatted string representing the directory tree with line counts for each file

Inputs: path (required), language (required).

read_fileA
Read content from a file with line numbers, validating the file path first.

Args:
    file_path: Path to the file to read
    start_line: Line number to start reading from (0-indexed, default: 0)
    end_line: Line number to end reading at (0-indexed, inclusive, default: None for all lines)
    
Returns:
    A string with numbered lines from the file
    
Raises:
    FileNotFoundError: If the file does not exist
    ValueError: If the line parameters are invalid

Inputs: file_path (required), start_line, end_line.

read_postman_collectionC
Read the Postman collection

Args:
    file_path: The path to the Postman collection file (string)
Returns:
    The Postman collection data (dict)

Inputs: file_path (required).

update_postman_collection_variableA
Update a specific variable in the Postman collection by key

Args:
    file_path: The path to the Postman collection file (string)
    key: The key of the variable to update (string)
    new_value: The new value for the variable (string)
Returns:
    The updated Postman collection data (dict)

Inputs: file_path (required), key (required), new_value (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 14 tools

    Disambiguation4/5

    Most tools have distinct purposes, e.g., adding items to root vs folder, managing variables vs events. The generic file tools (read_file, get_tree_directory) are clearly separate from Postman-specific tools, so agents can distinguish between them.

    Naming Consistency2/5

    Naming is inconsistent: some tools use 'postman_collection' (e.g., add_postman_collection_item) while others omit it (e.g., add_item_to_folder). Verbs vary (add, create, read, delete, update, get) without a consistent pattern, mixing snake_case and multi-word names.

    Tool Count5/5

    14 tools cover the core workflows of creating and managing Postman collections from code. The count is well within the 3-15 range and each tool serves a specific purpose without redundancy.

    Completeness3/5

    The set covers creation, reading, and deletion of items, variables, and folders, but lacks update operations for items and variables, and does not support deleting folders or variables. Some lifecycle steps are missing.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers