Skip to main content
Glama
runninghare

REST-to-Postman MCP

by runninghare

rest_to_postman_collection

Convert REST API endpoints to Postman collections, synchronizing API definitions with Postman while preserving existing customizations during updates.

Instructions

Creates or updates a Postman collection with the provided collection configuration. This tool helps synchronize your REST API endpoints with Postman. When updating an existing collection, it intelligently merges the new endpoints with existing ones, avoiding duplicates while preserving custom modifications made in Postman. Here's an example:

{ "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"] }
} }, { "name": "Create User", "request": { "method": "POST", "url": { "raw": "{{API_URL}}/users" }, "body": { "mode": "raw", "raw": "{"name":"John Doe","email":"john.doe@example.com"}" } }
} ] }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionRequestYesThe Postman collection configuration containing info, items, and other collection details

Implementation Reference

  • Core handler function that creates or updates a Postman collection by calling the Postman API. Handles merging new items with existing collection without duplicates, preserving custom modifications.
    export async function pushCollection(collectionRequest: PostmanCollectionRequest, postmanApiKey?: string, workspaceId?: string): Promise<void> {
        try {
            const apiKey = postmanApiKey || process.env.POSTMAN_API_KEY;
            const activeWorkspaceId = workspaceId || process.env.POSTMAN_ACTIVE_WORKSPACE_ID;
    
            // Create collection container
            const containerRequestBody = {
                collection: collectionRequest,
                workspace: activeWorkspaceId
            };
    
            // Check if collection already exists
            try {
                const workspaceResponse = await axios({
                    method: 'get',
                    url: `https://api.getpostman.com/workspaces/${activeWorkspaceId}`,
                    headers: {
                        'X-Api-Key': apiKey
                    }
                });
        
                const workspaceData = workspaceResponse.data as PostmanWorkspaceResponse;
                var existingCollection = workspaceData.workspace.collections?.find(
                    collection => collection.name === collectionRequest.info.name
                );   
            } catch (error) {
                console.error('Error in pushCollection:', error);
            }
    
            let response;
            if (existingCollection) {
                // Reuse getCollection to fetch existing collection data
                const existingCollectionData = await getCollection(collectionRequest.info.name, apiKey, activeWorkspaceId);
                
                // Helper function to normalize request for comparison
                const normalizeRequest = (request: PostmanRequest) => {
                    const normalized = JSON.parse(JSON.stringify(request));
                    // Remove id and uid
                    delete normalized.id;
                    delete normalized.uid;
                    // Remove empty arrays
                    if (normalized.response && normalized.response.length === 0) delete normalized.response;
                    if (normalized.request?.header && normalized.request.header.length === 0) delete normalized.request.header;
                    return JSON.stringify(normalized);
                };
    
                // Deduplicate items while merging
                const existingItems = existingCollectionData.item || [];
                const newItems = collectionRequest.item || [];
                const uniqueItems = [...existingItems];
                
                for (const newItem of newItems) {
                    const normalizedNew = normalizeRequest(newItem);
                    const isDuplicate = uniqueItems.some(existingItem => 
                        normalizeRequest(existingItem) === normalizedNew
                    );
                    if (!isDuplicate) {
                        uniqueItems.push(newItem);
                    }
                }
    
                // Merge the collections
                const mergedCollection: PostmanCollectionRequest = {
                    info: {
                        ...existingCollectionData.info,
                        ...collectionRequest.info
                    },
                    auth: collectionRequest.auth || existingCollectionData.auth,
                    item: uniqueItems,
                    event: [...(existingCollectionData.event || []), ...(collectionRequest.event || [])]
                };
    
                // remove `auth` if it is empty
                if (mergedCollection.auth && Object.keys(mergedCollection.auth).length === 0) {
                    delete mergedCollection.auth;
                }
    
                // console.log(JSON.stringify(mergedCollection, null, 2));
    
                // Update with merged data
                response = await axios({
                    method: 'put',
                    url: `https://api.getpostman.com/collections/${existingCollection.id}`,
                    headers: {
                        'X-Api-Key': apiKey,
                        'Content-Type': 'application/json'
                    },
                    data: {
                        collection: mergedCollection,
                        workspace: activeWorkspaceId
                    }
                });
            } else {
                // Remove `auth` if it is empty
                if (containerRequestBody.collection.auth && Object.keys(containerRequestBody.collection.auth).length === 0) {
                    delete containerRequestBody.collection.auth;
                }
    
                response = await axios({
                    method: 'post',
                    url: 'https://api.getpostman.com/collections',
                    headers: {
                        'X-Api-Key': apiKey,
                        'Content-Type': 'application/json'
                    },
                    data: containerRequestBody
                });
            }
    
        } catch (error) {
            console.error('Error in pushCollection:', error);
            throw error;
        }
    }
  • src/mcp.ts:103-333 (registration)
    Tool registration in the tools array, including name, description, and input schema for listTools request.
      {
        "name": "rest_to_postman_collection",
        "description": "Creates or updates a Postman collection with the provided collection configuration. This tool helps synchronize your REST API endpoints with Postman. When updating an existing collection, it intelligently merges the new endpoints with existing ones, avoiding duplicates while preserving custom modifications made in Postman. Here's an example: \n\n" + collectionExample,
        "inputSchema": {
          "type": "object",
          "properties": {
            "collectionRequest": {
              "type": "object",
              "description": "The Postman collection configuration containing info, items, and other collection details",
              "properties": {
                "info": {
                  "type": "object",
                  "description": "Collection information including name and schema",
                  "properties": {
                    "name": {
                      "type": "string",
                      "description": "Name of the collection"
                    },
                    "description": {
                      "type": "string",
                      "description": "Description of the collection"
                    },
                    "schema": {
                      "type": "string",
                      "description": "Schema version of the collection"
                    }
                  },
                  "required": ["name", "description", "schema"]
                },
                "auth": {
                  "type": "object",
                  "description": "Authentication settings for the collection",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Type of authentication (e.g., 'bearer')"
                    },
                    "bearer": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string",
                            "description": "Key for the bearer token"
                          },
                          "value": {
                            "type": "string",
                            "description": "Value of the bearer token"
                          },
                          "type": {
                            "type": "string",
                            "description": "Type of the bearer token"
                          }
                        },
                        "required": ["key", "value", "type"]
                      }
                    }
                  },
                  "required": ["type"]
                },
                "item": {
                  "type": "array",
                  "description": "Array of request items in the collection",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "description": "Name of the request"
                      },
                      "request": {
                        "type": "object",
                        "properties": {
                          "method": {
                            "type": "string",
                            "description": "HTTP method of the request"
                          },
                          "url": {
                            "type": "object",
                            "properties": {
                              "raw": {
                                "type": "string",
                                "description": "Raw URL string"
                              },
                              "protocol": {
                                "type": "string",
                                "description": "URL protocol (e.g., 'http', 'https')"
                              },
                              "host": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                },
                                "description": "Host segments"
                              },
                              "path": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                },
                                "description": "URL path segments"
                              },
                              "query": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "key": {
                                      "type": "string",
                                      "description": "Query parameter key"
                                    },
                                    "value": {
                                      "type": "string",
                                      "description": "Query parameter value"
                                    }
                                  },
                                  "required": ["key", "value"]
                                }
                              }
                            },
                            "required": ["raw", "protocol", "host", "path"]
                          },
                          "auth": {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type of authentication"
                              },
                              "bearer": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "key": {
                                      "type": "string"
                                    },
                                    "value": {
                                      "type": "string"
                                    },
                                    "type": {
                                      "type": "string"
                                    }
                                  },
                                  "required": ["key", "value", "type"]
                                }
                              }
                            },
                            "required": ["type"]
                          },
                          "description": {
                            "type": "string",
                            "description": "Description of the request"
                          }
                        },
                        "required": ["method", "url"]
                      },
                      "event": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "listen": {
                              "type": "string",
                              "description": "Event type to listen for"
                            },
                            "script": {
                              "type": "object",
                              "properties": {
                                "type": {
                                  "type": "string",
                                  "description": "Type of script"
                                },
                                "exec": {
                                  "type": "array",
                                  "items": {
                                    "type": "string"
                                  },
                                  "description": "Array of script lines to execute"
                                }
                              },
                              "required": ["type", "exec"]
                            }
                          },
                          "required": ["listen", "script"]
                        }
                      }
                    },
                    "required": ["name", "request"]
                  }
                },
                "event": {
                  "type": "array",
                  "description": "Collection-level event scripts",
                  "items": {
                    "type": "object",
                    "properties": {
                      "listen": {
                        "type": "string",
                        "description": "Event type to listen for"
                      },
                      "script": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "description": "Type of script"
                          },
                          "exec": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Array of script lines to execute"
                          }
                        },
                        "required": ["type", "exec"]
                      }
                    },
                    "required": ["listen", "script"]
                  }
                }
              },
              "required": ["info", "item"]
            }
          },
          "required": ["collectionRequest"]
        }
      }
    ];
  • Input schema definition for the tool, defining the structure of collectionRequest parameter matching PostmanCollectionRequest type.
    "inputSchema": {
      "type": "object",
      "properties": {
        "collectionRequest": {
          "type": "object",
          "description": "The Postman collection configuration containing info, items, and other collection details",
          "properties": {
            "info": {
              "type": "object",
              "description": "Collection information including name and schema",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "Name of the collection"
                },
                "description": {
                  "type": "string",
                  "description": "Description of the collection"
                },
                "schema": {
                  "type": "string",
                  "description": "Schema version of the collection"
                }
              },
              "required": ["name", "description", "schema"]
            },
            "auth": {
              "type": "object",
              "description": "Authentication settings for the collection",
              "properties": {
                "type": {
                  "type": "string",
                  "description": "Type of authentication (e.g., 'bearer')"
                },
                "bearer": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "key": {
                        "type": "string",
                        "description": "Key for the bearer token"
                      },
                      "value": {
                        "type": "string",
                        "description": "Value of the bearer token"
                      },
                      "type": {
                        "type": "string",
                        "description": "Type of the bearer token"
                      }
                    },
                    "required": ["key", "value", "type"]
                  }
                }
              },
              "required": ["type"]
            },
            "item": {
              "type": "array",
              "description": "Array of request items in the collection",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name of the request"
                  },
                  "request": {
                    "type": "object",
                    "properties": {
                      "method": {
                        "type": "string",
                        "description": "HTTP method of the request"
                      },
                      "url": {
                        "type": "object",
                        "properties": {
                          "raw": {
                            "type": "string",
                            "description": "Raw URL string"
                          },
                          "protocol": {
                            "type": "string",
                            "description": "URL protocol (e.g., 'http', 'https')"
                          },
                          "host": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Host segments"
                          },
                          "path": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "URL path segments"
                          },
                          "query": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "key": {
                                  "type": "string",
                                  "description": "Query parameter key"
                                },
                                "value": {
                                  "type": "string",
                                  "description": "Query parameter value"
                                }
                              },
                              "required": ["key", "value"]
                            }
                          }
                        },
                        "required": ["raw", "protocol", "host", "path"]
                      },
                      "auth": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "description": "Type of authentication"
                          },
                          "bearer": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "key": {
                                  "type": "string"
                                },
                                "value": {
                                  "type": "string"
                                },
                                "type": {
                                  "type": "string"
                                }
                              },
                              "required": ["key", "value", "type"]
                            }
                          }
                        },
                        "required": ["type"]
                      },
                      "description": {
                        "type": "string",
                        "description": "Description of the request"
                      }
                    },
                    "required": ["method", "url"]
                  },
                  "event": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "listen": {
                          "type": "string",
                          "description": "Event type to listen for"
                        },
                        "script": {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string",
                              "description": "Type of script"
                            },
                            "exec": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Array of script lines to execute"
                            }
                          },
                          "required": ["type", "exec"]
                        }
                      },
                      "required": ["listen", "script"]
                    }
                  }
                },
                "required": ["name", "request"]
              }
            },
            "event": {
              "type": "array",
              "description": "Collection-level event scripts",
              "items": {
                "type": "object",
                "properties": {
                  "listen": {
                    "type": "string",
                    "description": "Event type to listen for"
                  },
                  "script": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "description": "Type of script"
                      },
                      "exec": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "description": "Array of script lines to execute"
                      }
                    },
                    "required": ["type", "exec"]
                  }
                },
                "required": ["listen", "script"]
              }
            }
          },
          "required": ["info", "item"]
        }
      },
      "required": ["collectionRequest"]
    }
  • Dispatch handler in the MCP CallToolRequestSchema that invokes pushCollection for this specific tool name.
    } else if (request.params.name === "rest_to_postman_collection") {
      if (!request.params.arguments) {
        throw new McpError(ErrorCode.InvalidParams, "Missing arguments");
      }
      const { collectionRequest } = request.params.arguments as { collectionRequest: PostmanCollectionRequest };
      await pushCollection(collectionRequest, process.env.POSTMAN_API_KEY, process.env.POSTMAN_ACTIVE_WORKSPACE_ID);
      return {
        content: [{
          type: "text",
          text: `Successfully created/updated Postman collection: ${collectionRequest.info.name}`
        }]
      };
  • TypeScript interface defining the PostmanCollectionRequest used in the tool schema and handler.
    export interface PostmanCollectionRequest {
        info: {
            name: string,
            description: string,
            schema: string
        },
        auth?: Auth,
        item: PostmanRequest[],
        event?: ScriptEvent[]
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes key behaviors: it can create or update collections, intelligently merges endpoints to avoid duplicates, and preserves custom modifications. However, it lacks details on permissions, error handling, or rate limits, which are important for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose but includes a lengthy example that may not be necessary for understanding the tool's function. While the example is helpful, it makes the description less concise, and some details could be moved to documentation.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (1 parameter with nested objects, no annotations, no output schema), the description is moderately complete. It covers the tool's purpose and behavior but lacks information on return values, error cases, or prerequisites, which are important for a tool that mutates data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, so the baseline is 3. The description adds minimal parameter semantics by mentioning 'collection configuration' and providing an example, but it does not explain parameter constraints or usage beyond what the schema already documents.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Creates or updates a Postman collection with the provided collection configuration.' It specifies the verb ('creates or updates'), the resource ('Postman collection'), and distinguishes it from sibling tools by mentioning synchronization with REST API endpoints, unlike the sibling 'rest_to_postman_env' which likely handles environments.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for usage: 'This tool helps synchronize your REST API endpoints with Postman.' It explains when to use it (for creating or updating collections) and hints at the update behavior (intelligent merging). However, it does not explicitly state when not to use it or name specific alternatives beyond the sibling tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/runninghare/rest-to-postman'

If you have feedback or need assistance with the MCP directory API, please join our Discord server