getSpecFile
Retrieve the contents of a specific file from an API specification. Provide the spec ID and file path to access the file.
Instructions
Gets the contents of an API spec's file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| specId | Yes | Spec ID | |
| filePath | Yes | Path to the file |
Implementation Reference
- tools/postman_tools.py:1161-1191 (handler)GetSpecFileTool class: the handler that implements the 'getSpecFile' tool logic. Calls GET /apis/{specId}/files/{filePath} via postman_api_call utility and returns the contents of an API spec file.
class GetSpecFileTool(ToolHandler): """Get spec file contents""" def __init__(self): super().__init__("getSpecFile") def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Gets the contents of an API spec's file.", inputSchema={ "type": "object", "properties": { "specId": { "type": "string", "description": "Spec ID" }, "filePath": { "type": "string", "description": "Path to the file" } }, "required": ["specId", "filePath"] }, ) async def run_tool(self, args: dict) -> list[TextContent]: spec_id = args["specId"] file_path = args["filePath"] result = await postman_api_call("GET", f"/apis/{spec_id}/files/{file_path}") return [TextContent(type="text", text=json.dumps(result, indent=2))] - tools/postman_tools.py:1167-1185 (schema)get_tool_description method defines the input schema for getSpecFile, requiring specId (string) and filePath (string) parameters.
def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Gets the contents of an API spec's file.", inputSchema={ "type": "object", "properties": { "specId": { "type": "string", "description": "Spec ID" }, "filePath": { "type": "string", "description": "Path to the file" } }, "required": ["specId", "filePath"] }, ) - tools/postman_tools.py:1872-1873 (registration)Registration of GetSpecFileTool() in the register_all_tools function, making it available as an MCP tool.
GetSpecFileTool(), UpdateSpecFileTool(), - tools/postman_tools.py:21-67 (helper)postman_api_call helper function: the generic async HTTP client that handles all Postman API calls including the one made by getSpecFile.
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)}")