|
9 | 9 | from pydantic import Field |
10 | 10 | from fastmcp.server.dependencies import get_http_request |
11 | 11 | from fastmcp import Context |
| 12 | +from fastmcp.exceptions import ToolError |
12 | 13 | from starlette.requests import Request |
13 | 14 | from sysdig_client import ApiException |
14 | 15 | from sysdig_client.api import InventoryApi |
|
18 | 19 | from utils.query_helpers import create_standard_response |
19 | 20 |
|
20 | 21 | # Configure logging |
21 | | -log = logging.getLogger(__name__) |
22 | 22 | logging.basicConfig(format="%(asctime)s-%(process)d-%(levelname)s- %(message)s", level=os.environ.get("LOGLEVEL", "ERROR")) |
| 23 | +log = logging.getLogger(__name__) |
23 | 24 |
|
24 | 25 | # Load app config (expects keys: mcp.host, mcp.port, mcp.transport) |
25 | 26 | app_config = get_app_config() |
@@ -69,12 +70,78 @@ def tool_list_resources( |
69 | 70 | Field( |
70 | 71 | description=( |
71 | 72 | """ |
72 | | - Sysdig Secure filter expression for inventory resources, |
73 | | - base filter: platform in ("GCP", "AWS", "Azure", "Kubernetes"), |
74 | | - Examples: |
75 | | - not isExposed exists; category in ("IAM") and isExposed exists; category in ("IAM","Audit & Monitoring") |
| 73 | + Sysdig Secure query filter expression to filter inventory resources. |
| 74 | +
|
| 75 | + Use the resource://filter-query-language to get the expected filter expression format. |
| 76 | + |
| 77 | + List of supported fields: |
| 78 | + - accountName |
| 79 | + - accountId |
| 80 | + - cluster |
| 81 | + - externalDNS |
| 82 | + - distribution |
| 83 | + - integrationName |
| 84 | + - labels |
| 85 | + - location |
| 86 | + - name |
| 87 | + - namespace |
| 88 | + - nodeType |
| 89 | + - osName |
| 90 | + - osImage |
| 91 | + - organization |
| 92 | + - platform |
| 93 | + - control.accepted |
| 94 | + - policy |
| 95 | + - control.severity |
| 96 | + - control.failed |
| 97 | + - policy.failed |
| 98 | + - policy.passed |
| 99 | + - projectName |
| 100 | + - projectId |
| 101 | + - region |
| 102 | + - repository |
| 103 | + - resourceOrigin |
| 104 | + - type |
| 105 | + - subscriptionName |
| 106 | + - subscriptionId |
| 107 | + - sourceType |
| 108 | + - version |
| 109 | + - zone |
| 110 | + - category |
| 111 | + - isExposed |
| 112 | + - validatedExposure |
| 113 | + - arn |
| 114 | + - resourceId |
| 115 | + - container.name |
| 116 | + - architecture |
| 117 | + - baseOS |
| 118 | + - digest |
| 119 | + - imageId |
| 120 | + - os |
| 121 | + - container.imageName |
| 122 | + - image.registry |
| 123 | + - image.tag |
| 124 | + - package.inUse |
| 125 | + - package.info |
| 126 | + - package.path |
| 127 | + - package.type |
| 128 | + - vuln.cvssScore |
| 129 | + - vuln.hasExploit |
| 130 | + - vuln.hasFix |
| 131 | + - vuln.name |
| 132 | + - vuln.severity |
| 133 | + - machineImage |
76 | 134 | """ |
77 | | - ) |
| 135 | + ), |
| 136 | + examples=[ |
| 137 | + 'zone in ("zone1") and machineImage = "ami-0b22b359fdfabe1b5"', |
| 138 | + '(projectId = "1235495521" or projectId = "987654321") and vuln.severity in ("Critical")', |
| 139 | + 'vuln.name in ("CVE-2023-0049")', |
| 140 | + 'vuln.cvssScore >= "3"', |
| 141 | + 'container.name in ("sysdig-container") and not labels exists', |
| 142 | + 'imageId in ("sha256:3768ff6176e29a35ce1354622977a1e5c013045cbc4f30754ef3459218be8ac")', |
| 143 | + 'platform in ("GCP", "AWS", "Azure", "Kubernetes") and isExposed exists', |
| 144 | + ], |
78 | 145 | ), |
79 | 146 | ] = 'platform in ("GCP", "AWS", "Azure", "Kubernetes")', |
80 | 147 | page_number: Annotated[int, Field(ge=1, description="Page number for pagination (1-based index)")] = 1, |
@@ -112,7 +179,7 @@ def tool_list_resources( |
112 | 179 | response = create_standard_response(results=api_response, execution_time_ms=execution_time) |
113 | 180 |
|
114 | 181 | return response |
115 | | - except ApiException as e: |
| 182 | + except ToolError as e: |
116 | 183 | logging.error("Exception when calling InventoryApi->get_resources: %s\n" % e) |
117 | 184 | raise e |
118 | 185 |
|
@@ -141,6 +208,6 @@ def tool_get_resource( |
141 | 208 | response = create_standard_response(results=api_response, execution_time_ms=execution_time) |
142 | 209 |
|
143 | 210 | return response |
144 | | - except ApiException as e: |
| 211 | + except ToolError as e: |
145 | 212 | log.error(f"Exception when calling InventoryApi->get_resource: {e}") |
146 | 213 | raise e |
0 commit comments