createMock
Create a mock server for a Postman collection by providing the collection UID and optionally specifying a target workspace.
Instructions
Creates a mock server for a collection. Use collection UID (ownerId-collectionId). Use workspace param to specify target workspace.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace | No | Workspace ID | |
| mock | No | Mock server configuration with collection UID, name, and settings |
Implementation Reference
- tools/postman_tools.py:749-781 (handler)The CreateMockTool class implements the 'createMock' tool handler. It extends ToolHandler, initializes with name 'createMock', provides input schema (workspace and mock object), and executes by calling POST /mocks on the Postman API with optional workspace parameter and mock body.
class CreateMockTool(ToolHandler): """Create a mock server""" def __init__(self): super().__init__("createMock") def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Creates a mock server for a collection. Use collection UID (ownerId-collectionId). Use workspace param to specify target workspace.", inputSchema={ "type": "object", "properties": { "workspace": { "type": "string", "description": "Workspace ID" }, "mock": { "type": "object", "description": "Mock server configuration with collection UID, name, and settings" } }, }, ) async def run_tool(self, args: dict) -> list[TextContent]: params = {} if args.get("workspace"): params["workspace"] = args["workspace"] body = {"mock": args.get("mock", {})} result = await postman_api_call("POST", "/mocks", body=body, params=params) return [TextContent(type="text", text=json.dumps(result, indent=2))] - tools/postman_tools.py:1858-1862 (registration)The 'createMock' tool is registered in the register_all_tools() function as CreateMockTool() in the Mocks section of the tool list.
CreateMockTool(), GetMockTool(), GetMocksTool(), UpdateMockTool(), PublishMockTool(), - tools/postman_tools.py:21-67 (helper)The postman_api_call helper function is used by CreateMockTool.run_tool() to make the underlying HTTP POST request to the Postman API. It handles authentication via X-Api-Key header, error handling, and response parsing.
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)}") - tools/toolhandler.py:9-23 (helper)The ToolHandler abstract base class provides the interface that CreateMockTool implements. It defines the contract with get_tool_description() and run_tool() abstract methods.
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 - tools/postman_tools.py:755-772 (schema)The input schema for 'createMock' defines two optional properties: 'workspace' (string, workspace ID) and 'mock' (object, mock server configuration with collection UID, name, and settings).
def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Creates a mock server for a collection. Use collection UID (ownerId-collectionId). Use workspace param to specify target workspace.", inputSchema={ "type": "object", "properties": { "workspace": { "type": "string", "description": "Workspace ID" }, "mock": { "type": "object", "description": "Mock server configuration with collection UID, name, and settings" } }, }, )