get_threats
Retrieve paginated threat data from Devici MCP Server to analyze and manage threat modeling resources effectively.
Instructions
Get threats from Devici with pagination
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| page | No |
Implementation Reference
- src/devici_mcp_server/server.py:146-151 (handler)MCP tool handler for 'get_threats': registers the tool and implements the logic by calling the API client to fetch threats with pagination and returns as string.@mcp.tool() async def get_threats(limit: int = 20, page: int = 0) -> str: """Get threats from Devici with pagination""" async with create_client_from_env() as client: result = await client.get_threats(limit=limit, page=page) return str(result)
- API client method implementing get_threats: makes a GET request to /threats/ endpoint with limit and page parameters.async def get_threats(self, limit: int = 20, page: int = 0) -> Dict[str, Any]: """Get all threats.""" params = {"limit": limit, "page": page} return await self._make_request("GET", "/threats/", params=params)
- Core helper method for making authenticated HTTP requests to the Devici API, used by get_threats.async def _make_request( self, method: str, endpoint: str, params: Optional[Dict[str, Any]] = None, json_data: Optional[Dict[str, Any]] = None ) -> Dict[str, Any]: """Make authenticated request to Devici API.""" if not self.access_token: await self.authenticate() try: response = await self.client.request( method=method, url=endpoint, params=params, json=json_data ) response.raise_for_status() return response.json() except httpx.HTTPError as e: logger.error(f"API request failed: {method} {endpoint} - {e}") raise
- Factory function to create the DeviciAPIClient from environment variables, used in the handler.def create_client_from_env() -> DeviciAPIClient: """Create API client from environment variables.""" config = DeviciConfig( api_base_url=os.getenv("DEVICI_API_BASE_URL", "https://api.devici.com/api/v1"), client_id=os.getenv("DEVICI_CLIENT_ID", ""), client_secret=os.getenv("DEVICI_CLIENT_SECRET", ""), debug=os.getenv("DEBUG", "false").lower() == "true" ) if not config.client_id or not config.client_secret: raise ValueError("DEVICI_CLIENT_ID and DEVICI_CLIENT_SECRET must be set") return DeviciAPIClient(config)