generateSpecFromCollection
Generates an API specification from a Postman collection. Returns a polling link to track the task status.
Instructions
Generates an API spec for a collection. Returns polling link to task status.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionUid | Yes | Collection unique ID | |
| name | Yes | API spec name | |
| elementType | Yes | The 'spec' value | |
| format | Yes | Format (openapi, asyncapi, etc.) | |
| type | Yes | Specification type |
Implementation Reference
- tools/postman_tools.py:1344-1392 (handler)The GenerateSpecFromCollectionTool class is the handler for the 'generateSpecFromCollection' tool. It defines the tool's schema (input: collectionUid, name, elementType, format, type) and implements run_tool which posts to POST /apis/generate to generate an API spec from a collection.
class GenerateSpecFromCollectionTool(ToolHandler): """Generate spec from collection""" def __init__(self): super().__init__("generateSpecFromCollection") def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Generates an API spec for a collection. Returns polling link to task status.", inputSchema={ "type": "object", "properties": { "collectionUid": { "type": "string", "description": "Collection unique ID" }, "name": { "type": "string", "description": "API spec name" }, "elementType": { "type": "string", "description": "The 'spec' value" }, "format": { "type": "string", "description": "Format (openapi, asyncapi, etc.)" }, "type": { "type": "string", "description": "Specification type" } }, "required": ["collectionUid", "name", "elementType", "format", "type"] }, ) async def run_tool(self, args: dict) -> list[TextContent]: body = { "collectionUid": args["collectionUid"], "name": args["name"], "elementType": args["elementType"], "format": args["format"], "type": args["type"] } result = await postman_api_call("POST", "/apis/generate", body=body) return [TextContent(type="text", text=json.dumps(result, indent=2))] - tools/postman_tools.py:1354-1380 (schema)The input schema for generateSpecFromCollection defines required properties: collectionUid (string), name (string), elementType (string), format (string), and type (string).
inputSchema={ "type": "object", "properties": { "collectionUid": { "type": "string", "description": "Collection unique ID" }, "name": { "type": "string", "description": "API spec name" }, "elementType": { "type": "string", "description": "The 'spec' value" }, "format": { "type": "string", "description": "Format (openapi, asyncapi, etc.)" }, "type": { "type": "string", "description": "Specification type" } }, "required": ["collectionUid", "name", "elementType", "format", "type"] }, ) - tools/postman_tools.py:1878-1878 (registration)GenerateSpecFromCollectionTool() is instantiated and returned in the register_all_tools() function, registering it as an MCP tool.
GenerateSpecFromCollectionTool(), - tests/test_postman.py:90-90 (registration)The test file confirms 'generateSpecFromCollection' is expected as one of the 41 registered tool names.
"generateSpecFromCollection", - tools/toolhandler.py:9-23 (helper)The ToolHandler abstract base class that GenerateSpecFromCollectionTool inherits from. Provides the base __init__ (sets self.name) and defines abstract methods get_tool_description() and run_tool().
class ToolHandler(ABC): """Base class for all Postman tool handlers""" def __init__(self, name: str): self.name = name @abstractmethod def get_tool_description(self) -> Tool: """Return the MCP Tool description for this handler""" pass @abstractmethod async def run_tool(self, arguments: dict) -> list[TextContent | ImageContent | EmbeddedResource]: """Execute the tool with the given arguments""" pass