Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
workspaceNoWorkspace ID
mockNoMock server configuration with collection UID, name, and settings

Implementation Reference

  • 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))]
  • 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(),
  • 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)}")
  • 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
  • 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"
                    }
                },
            },
        )
Behavior3/5

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

With no annotations, the description carries full burden. It discloses the UID format and workspace requirement, but lacks details on permissions, side effects, success/failure outcomes, or whether the collection must exist. The nested object's internal structure is partially described but could be more explicit.

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

Conciseness5/5

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

The description is two sentences: the first states the primary action clearly, and the second provides key parameter guidance. No unnecessary words, fully front-loaded, and efficient for an AI agent.

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?

The tool creates a mock server with a nested object parameter and no output schema. The description covers the input format and workspace, but does not explain what happens after creation (e.g., return value, how to access the mock) or provide expected behavior. Adequate but incomplete for a creation tool.

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?

Schema description coverage is 100%, so the description adds only modest value by specifying the collection UID format (ownerId-collectionId). The workspace param description is essentially restated. Overall, it supplements rather than significantly extends the schema.

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 verb 'Creates' and the resource 'mock server for a collection', and distinguishes it from sibling tools like updateMock and publishMock by focusing on creation. It also specifies the unique identifier format (collection UID as ownerId-collectionId), adding precision.

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

Usage Guidelines3/5

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

The description implies usage by stating to use workspace param and collection UID, but does not explicitly contrast with alternatives like createCollection or updateMock. No when-to-use or when-not-to-use guidance is provided, leaving the agent to infer context.

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/Sourav4670/postman-mcp'

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