getSpecCollections
Retrieve all collections created from an API specification by providing the spec ID and element type.
Instructions
Gets all collections generated from an API spec.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| specId | Yes | Spec ID | |
| elementType | Yes | Collection element type | |
| cursor | No | Pagination cursor | |
| limit | No | Max rows |
Implementation Reference
- tools/postman_tools.py:1298-1341 (handler)GetSpecCollectionsTool class - the handler that implements the 'getSpecCollections' tool logic. Makes a GET request to /apis/{specId}/collections with optional pagination params.
class GetSpecCollectionsTool(ToolHandler): """Get spec's generated collections""" def __init__(self): super().__init__("getSpecCollections") def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Gets all collections generated from an API spec.", inputSchema={ "type": "object", "properties": { "specId": { "type": "string", "description": "Spec ID" }, "elementType": { "type": "string", "description": "Collection element type" }, "cursor": { "type": "string", "description": "Pagination cursor" }, "limit": { "type": "integer", "description": "Max rows" } }, "required": ["specId", "elementType"] }, ) async def run_tool(self, args: dict) -> list[TextContent]: spec_id = args["specId"] params = {"elementType": args["elementType"]} if args.get("cursor"): params["cursor"] = args["cursor"] if args.get("limit"): params["limit"] = args["limit"] result = await postman_api_call("GET", f"/apis/{spec_id}/collections", params=params) return [TextContent(type="text", text=json.dumps(result, indent=2))] - tools/postman_tools.py:1298-1330 (schema)Input schema for getSpecCollections tool, requiring specId and elementType, with optional cursor and limit for pagination.
class GetSpecCollectionsTool(ToolHandler): """Get spec's generated collections""" def __init__(self): super().__init__("getSpecCollections") def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Gets all collections generated from an API spec.", inputSchema={ "type": "object", "properties": { "specId": { "type": "string", "description": "Spec ID" }, "elementType": { "type": "string", "description": "Collection element type" }, "cursor": { "type": "string", "description": "Pagination cursor" }, "limit": { "type": "integer", "description": "Max rows" } }, "required": ["specId", "elementType"] }, ) - tools/postman_tools.py:1876-1877 (registration)Registration of GetSpecCollectionsTool() in the register_all_tools() function, making it available as an MCP tool.
GenerateCollectionTool(), GetSpecCollectionsTool(), - tools/postman_tools.py:21-67 (helper)Helper function postman_api_call used by GetSpecCollectionsTool.run_tool() to make the actual GET request to the Postman API.
async def postman_api_call( method: str, endpoint: str, body: dict | None = None, params: dict | None = None, headers: dict | None = None ) -> dict: """Make an API call to Postman API""" if not POSTMAN_API_KEY: raise RuntimeError("POSTMAN_API_KEY environment variable is not set") url = f"{POSTMAN_BASE_URL}{endpoint}" # Prepare headers request_headers = { "X-Api-Key": POSTMAN_API_KEY, "Content-Type": "application/json", } if headers: request_headers.update(headers) async with httpx.AsyncClient(timeout=30.0) as client: try: response = await client.request( method=method, url=url, json=body, params=params, headers=request_headers ) response.raise_for_status() if response.status_code == 204: return {"success": True, "message": "Operation completed successfully"} return response.json() if response.content else {"success": True} except httpx.HTTPStatusError as e: error_detail = e.response.text try: error_json = e.response.json() error_detail = json.dumps(error_json, indent=2) except: pass raise RuntimeError(f"Postman API error ({e.response.status_code}): {error_detail}") except Exception as e: raise RuntimeError(f"Request failed: {str(e)}")