createEnvironment
Create a new Postman environment with name and values, optionally specifying a workspace. If no workspace is provided, the environment is created in your oldest personal workspace.
Instructions
Creates an environment. Max size 30MB. If workspace not specified, creates in oldest personal workspace.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace | No | Workspace ID | |
| environment | No | Environment object with name and values |
Implementation Reference
- tools/postman_tools.py:618-650 (handler)The CreateEnvironmentTool class implements the 'createEnvironment' tool. It registers with name 'createEnvironment', defines input schema with optional 'workspace' and 'environment' fields, and makes a POST call to /environments endpoint to create a new Postman environment.
class CreateEnvironmentTool(ToolHandler): """Create an environment""" def __init__(self): super().__init__("createEnvironment") def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Creates an environment. Max size 30MB. If workspace not specified, creates in oldest personal workspace.", inputSchema={ "type": "object", "properties": { "workspace": { "type": "string", "description": "Workspace ID" }, "environment": { "type": "object", "description": "Environment object with name and values" } }, }, ) async def run_tool(self, args: dict) -> list[TextContent]: params = {} if args.get("workspace"): params["workspace"] = args["workspace"] body = {"environment": args.get("environment", {})} result = await postman_api_call("POST", "/environments", body=body, params=params) return [TextContent(type="text", text=json.dumps(result, indent=2))] - tools/postman_tools.py:1852-1855 (registration)Registration of CreateEnvironmentTool() in the register_all_tools() function that returns all tool handlers.
CreateEnvironmentTool(), GetEnvironmentTool(), GetEnvironmentsTool(), PutEnvironmentTool(), - tools/postman_tools.py:624-641 (schema)Input schema for createEnvironment: accepts optional 'workspace' (string) and 'environment' (object with name and values).
def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Creates an environment. Max size 30MB. If workspace not specified, creates in oldest personal workspace.", inputSchema={ "type": "object", "properties": { "workspace": { "type": "string", "description": "Workspace ID" }, "environment": { "type": "object", "description": "Environment object with name and values" } }, }, ) - tools/toolhandler.py:9-24 (helper)Abstract base class ToolHandler that CreateEnvironmentTool inherits from. Defines the interface with get_tool_description() and run_tool() 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:21-67 (helper)The postman_api_call helper function used by CreateEnvironmentTool.run_tool() to make the actual HTTP POST 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)}")