Skip to content

Commit 9009eea

Browse files
committed
Updating overall init config of the client
Signed-off-by: S3B4SZ17 <[email protected]>
1 parent 4dd2a14 commit 9009eea

File tree

12 files changed

+105
-56
lines changed

12 files changed

+105
-56
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ Get up and running with the Sysdig MCP Server quickly using our pre-built Docker
8585

8686
## Available Tools
8787

88+
You can select what group of tools to add when running the server by adding/removing them from the `mcp.allowed_tools` list in the app_config.yaml file
89+
90+
```yaml
91+
...
92+
mcp:
93+
transport: stdio
94+
...
95+
allowed_tools:
96+
- "events-feed"
97+
- "inventory"
98+
- "vulnerability-management"
99+
- "sysdig-sage"
100+
- "sysdig-cli-scanner" # Only available in stdio local transport mode
101+
```
102+
88103
<details>
89104
<summary><strong>Events Feed</strong></summary>
90105

@@ -131,6 +146,15 @@ Get up and running with the Sysdig MCP Server quickly using our pre-built Docker
131146

132147
</details>
133148

149+
<details>
150+
<summary><strong>Sysdig CLI scanner</strong></summary>
151+
152+
| Tool Name | Description | Sample Prompt |
153+
|-----------|-------------|----------------|
154+
| `run_sysdig_cli_scanner` | Run the Sysdig CLI Scanner to analyze a container image or IaC files for vulnerabilities and posture and misconfigurations. | "Scan this image ubuntu:latest for vulnerabilities" |
155+
156+
</details>
157+
134158
### Available Resources
135159

136160
- Sysdig Secure Vulnerability Management Overview:
@@ -171,6 +195,8 @@ This file contains the main configuration for the application, including:
171195
- **sysdig**: The Sysdig Secure host to connect to.
172196
- **mcp**: Transport protocol (stdio, sse, streamable-http), URL, host, and port for the MCP server.
173197
198+
> You can set the path for the app_config.yaml using the `APP_CONFIG_FILE=/path/to/app_config.yaml` env var. By default the app will search the file in the root of the app.
199+
174200
### Environment Variables
175201
176202
The following environment variables are required for configuring the Sysdig SDK:
@@ -250,6 +276,12 @@ configMap:
250276
transport: streamable-http
251277
host: "0.0.0.0"
252278
port: 8080
279+
allowed_tools:
280+
- "events-feed"
281+
- "inventory"
282+
- "vulnerability-management"
283+
- "sysdig-sage"
284+
- "sysdig-cli-scanner" # You need the sysdig-cli-scanner binary installed in your server to use this tool
253285
```
254286
255287
Install the chart

charts/sysdig-mcp/values.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ image:
88
repository: ghcr.io/sysdiglabs/sysdig-mcp-server
99
pullPolicy: IfNotPresent
1010
# Overrides the image tag whose default is the chart appVersion.
11-
tag: "v0.1.2"
11+
tag: "v0.1.3-beta.0"
1212

1313
imagePullSecrets: []
1414
nameOverride: ""
@@ -126,3 +126,9 @@ configMap:
126126
transport: streamable-http
127127
host: "0.0.0.0"
128128
port: 8080
129+
allowed_tools:
130+
- "events-feed"
131+
- "sysdig-cli-scanner" # You need the sysdig-cli-scanner binary installed in your server to use this tool
132+
- "vulnerability-management"
133+
- "inventory"
134+
- "sysdig-sage"

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sysdig-mcp-server"
3-
version = "0.1.2"
3+
version = "0.1.3-beta.0"
44
description = "Sysdig MCP Server"
55
readme = "README.md"
66
requires-python = ">=3.12"
@@ -10,7 +10,7 @@ dependencies = [
1010
"pyyaml==6.0.2",
1111
"sqlalchemy==2.0.36",
1212
"sqlmodel==0.0.22",
13-
"sysdig-sdk @ git+https://github.com/sysdiglabs/sysdig-sdk-python@ccdf3effe27a339deaa04a7248b319443d20e5aa",
13+
"sysdig-sdk @ git+https://github.com/sysdiglabs/sysdig-sdk-python@e9b0d336c2f617f3bbd752416860f84eed160c41",
1414
"dask==2025.4.1",
1515
"oauthlib==3.2.2",
1616
"fastapi==0.115.12",

tools/events_feed/tool.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from utils.sysdig.api import initialize_api_client
2525

2626
logging.basicConfig(format="%(asctime)s-%(process)d-%(levelname)s- %(message)s", level=os.environ.get("LOGLEVEL", "ERROR"))
27-
2827
log = logging.getLogger(__name__)
2928

3029
# Load app config (expects keys: mcp.host, mcp.port, mcp.transport)
@@ -46,12 +45,11 @@ def init_client(self, old_api: bool = False) -> SecureEventsApi | OldSysdigApi:
4645
old_api (bool): If True, initializes the OldSysdigApi client instead of SecureEventsApi.
4746
Returns:
4847
SecureEventsApi | OldSysdigApi: An instance of the SecureEventsApi or OldSysdigApi client.
49-
Raises:
50-
ValueError: If the SYSDIG_SECURE_TOKEN environment variable is not set.
5148
"""
5249
secure_events_api: SecureEventsApi = None
5350
old_sysdig_api: OldSysdigApi = None
54-
if app_config.get("mcp", {}).get("transport", "") == "streamable-http":
51+
transport = os.environ.get("MCP_TRANSPORT", app_config["mcp"]["transport"]).lower()
52+
if transport in ["streamable-http", "sse"]:
5553
# Try to get the HTTP request
5654
log.debug("Attempting to get the HTTP request to initialize the Sysdig API client.")
5755
request: Request = get_http_request()
@@ -60,15 +58,11 @@ def init_client(self, old_api: bool = False) -> SecureEventsApi | OldSysdigApi:
6058
else:
6159
# If running in STDIO mode, we need to initialize the API client from environment variables
6260
log.debug("Running in STDIO mode, initializing the Sysdig API client from environment variables.")
63-
SYSDIG_SECURE_TOKEN = os.environ.get("SYSDIG_SECURE_TOKEN", "")
64-
if not SYSDIG_SECURE_TOKEN:
65-
raise ValueError("Can not initialize client, SYSDIG_SECURE_TOKEN environment variable is not set.")
66-
SYSDIG_HOST = os.environ.get("SYSDIG_HOST", app_config["sysdig"]["host"])
67-
cfg = get_configuration(SYSDIG_SECURE_TOKEN, SYSDIG_HOST)
61+
cfg = get_configuration()
6862
api_client = initialize_api_client(cfg)
6963
secure_events_api = SecureEventsApi(api_client)
7064
# Initialize the old Sysdig API client for process tree requests
71-
old_cfg = get_configuration(SYSDIG_SECURE_TOKEN, SYSDIG_HOST, old_api=True)
65+
old_cfg = get_configuration(old_api=True)
7266
old_sysdig_api = initialize_api_client(old_cfg)
7367
old_sysdig_api = OldSysdigApi(old_sysdig_api)
7468

tools/inventory/tool.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,21 @@ def init_client(self) -> InventoryApi:
3838
using the Sysdig Secure token and host from the environment variables.
3939
Returns:
4040
InventoryApi: An instance of the InventoryApi client.
41-
Raises:
42-
ValueError: If the SYSDIG_SECURE_TOKEN environment variable is not set.
4341
"""
44-
secure_events_api: InventoryApi = None
45-
if app_config.get("mcp", {}).get("transport", "") == "streamable-http":
42+
inventory_api: InventoryApi = None
43+
transport = os.environ.get("MCP_TRANSPORT", app_config["mcp"]["transport"]).lower()
44+
if transport in ["streamable-http", "sse"]:
4645
# Try to get the HTTP request
4746
log.debug("Attempting to get the HTTP request to initialize the Sysdig API client.")
4847
request: Request = get_http_request()
49-
secure_events_api = request.state.api_instances["inventory"]
48+
inventory_api = request.state.api_instances["inventory"]
5049
else:
5150
# If running in STDIO mode, we need to initialize the API client from environment variables
5251
log.debug("Running in STDIO mode, initializing the Sysdig API client from environment variables.")
53-
SYSDIG_SECURE_TOKEN = os.environ.get("SYSDIG_SECURE_TOKEN", "")
54-
if not SYSDIG_SECURE_TOKEN:
55-
raise ValueError("Can not initialize client, SYSDIG_SECURE_TOKEN environment variable is not set.")
56-
SYSDIG_HOST = os.environ.get("SYSDIG_HOST", app_config["sysdig"]["host"])
57-
cfg = get_configuration(SYSDIG_SECURE_TOKEN, SYSDIG_HOST)
52+
cfg = get_configuration()
5853
api_client = initialize_api_client(cfg)
59-
secure_events_api = InventoryApi(api_client)
60-
return secure_events_api
54+
inventory_api = InventoryApi(api_client)
55+
return inventory_api
6156

6257
def tool_list_resources(
6358
self,

tools/sysdig_sage/tool.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,18 @@ def init_client(self) -> OldSysdigApi:
3737
using the Sysdig Secure token and host from the environment variables.
3838
Returns:
3939
OldSysdigApi: An instance of the OldSysdigApi client.
40-
41-
Raises:
42-
ValueError: If the SYSDIG_SECURE_TOKEN environment variable is not set.
4340
"""
4441
old_sysdig_api: OldSysdigApi = None
45-
if app_config.get("mcp", {}).get("transport", "") == "streamable-http":
42+
transport = os.environ.get("MCP_TRANSPORT", app_config["mcp"]["transport"]).lower()
43+
if transport in ["streamable-http", "sse"]:
4644
# Try to get the HTTP request
4745
log.debug("Attempting to get the HTTP request to initialize the Sysdig API client.")
4846
request: Request = get_http_request()
4947
old_sysdig_api = request.state.api_instances["old_sysdig_api"]
5048
else:
5149
# If running in STDIO mode, we need to initialize the API client from environment variables
5250
log.debug("Running in STDIO mode, initializing the Sysdig API client from environment variables.")
53-
SYSDIG_SECURE_TOKEN = os.environ.get("SYSDIG_SECURE_TOKEN", "")
54-
if not SYSDIG_SECURE_TOKEN:
55-
raise ValueError("Can not initialize client, SYSDIG_SECURE_TOKEN environment variable is not set.")
56-
57-
SYSDIG_HOST = os.environ.get("SYSDIG_HOST", app_config["sysdig"]["host"])
58-
cfg = get_configuration(SYSDIG_SECURE_TOKEN, SYSDIG_HOST, old_api=True)
51+
cfg = get_configuration(old_api=True)
5952
api_client = initialize_api_client(cfg)
6053
old_sysdig_api = OldSysdigApi(api_client)
6154
return old_sysdig_api

tools/vulnerability_management/tool.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,18 @@ def init_client(self) -> VulnerabilityManagementApi:
4040
using the Sysdig Secure token and host from the environment variables.
4141
Returns:
4242
VulnerabilityManagementApi: An instance of the VulnerabilityManagementApi client.
43-
Raises:
44-
ValueError: If the SYSDIG_SECURE_TOKEN environment variable is not set.
4543
"""
4644
vulnerability_management_api: VulnerabilityManagementApi = None
47-
if app_config.get("mcp", {}).get("transport", "") == "streamable-http":
45+
transport = os.environ.get("MCP_TRANSPORT", app_config["mcp"]["transport"]).lower()
46+
if transport in ["streamable-http", "sse"]:
4847
# Try to get the HTTP request
4948
log.debug("Attempting to get the HTTP request to initialize the Sysdig API client.")
5049
request: Request = get_http_request()
5150
vulnerability_management_api = request.state.api_instances["vulnerability_management"]
5251
else:
5352
# If running in STDIO mode, we need to initialize the API client from environment variables
5453
log.debug("Running in STDIO mode, initializing the Sysdig API client from environment variables.")
55-
SYSDIG_SECURE_TOKEN = os.environ.get("SYSDIG_SECURE_TOKEN", "")
56-
if not SYSDIG_SECURE_TOKEN:
57-
raise ValueError("Can not initialize client, SYSDIG_SECURE_TOKEN environment variable is not set.")
58-
SYSDIG_HOST = os.environ.get("SYSDIG_HOST", app_config["sysdig"]["host"])
59-
cfg = get_configuration(SYSDIG_SECURE_TOKEN, SYSDIG_HOST)
54+
cfg = get_configuration()
6055
api_client = initialize_api_client(cfg)
6156
vulnerability_management_api = VulnerabilityManagementApi(api_client)
6257
return vulnerability_management_api

utils/mcp_server.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
middlewares = [Middleware(CustomAuthMiddleware)]
4141

42+
MCP_MOUNT_PATH = "/sysdig-mcp-server"
43+
4244

4345
def create_simple_mcp_server() -> FastMCP:
4446
"""
@@ -52,7 +54,6 @@ def create_simple_mcp_server() -> FastMCP:
5254
instructions="Provides Sysdig Secure tools and resources.",
5355
host=app_config["mcp"]["host"],
5456
port=app_config["mcp"]["port"],
55-
debug=True,
5657
tags=["sysdig", "mcp", os.environ.get("MCP_TRANSPORT", app_config["mcp"]["transport"]).lower()],
5758
)
5859

@@ -96,12 +97,12 @@ def run_http():
9697
add_tools(mcp=mcp, allowed_tools=app_config["mcp"]["allowed_tools"], transport_type=app_config["mcp"]["transport"])
9798
# Add resources to the MCP server
9899
add_resources(mcp)
99-
# Mount the MCP HTTP/SSE app at '/sysdig-mcp-server'
100-
mcp_app = mcp.http_app(
101-
path="/mcp", transport=os.environ.get("MCP_TRANSPORT", app_config["mcp"]["transport"]).lower(), middleware=middlewares
102-
)
100+
# Mount the MCP HTTP/SSE app at 'MCP_MOUNT_PATH'
101+
transport = os.environ.get("MCP_TRANSPORT", app_config["mcp"]["transport"]).lower()
102+
mcp_app = mcp.http_app(transport=transport, middleware=middlewares)
103+
suffix_path = mcp.settings.streamable_http_path if transport == "streamable-http" else mcp.settings.sse_path
103104
app = FastAPI(lifespan=mcp_app.lifespan)
104-
app.mount("/sysdig-mcp-server", mcp_app)
105+
app.mount(MCP_MOUNT_PATH, mcp_app)
105106

106107
@app.get("/healthz", response_class=Response)
107108
async def health_check(request: Request) -> Response:
@@ -115,7 +116,9 @@ async def health_check(request: Request) -> Response:
115116
"""
116117
return JSONResponse({"status": "ok"})
117118

118-
log.info(f"Starting {mcp.name} at http://{app_config['app']['host']}:{app_config['app']['port']}/sysdig-mcp-server/mcp")
119+
log.info(
120+
f"Starting {mcp.name} at http://{app_config['app']['host']}:{app_config['app']['port']}{MCP_MOUNT_PATH}{suffix_path}"
121+
)
119122
# Use Uvicorn's Config and Server classes for more control
120123
config = uvicorn.Config(
121124
app,
@@ -270,7 +273,7 @@ def add_tools(mcp: FastMCP, allowed_tools: list, transport_type: Literal["stdio"
270273
),
271274
)
272275

273-
if transport_type == "stdio" and "sysdig-cli-scanner" in allowed_tools:
276+
if "sysdig-cli-scanner" in allowed_tools:
274277
# Register the tools for STDIO transport
275278
cli_scanner_tool = CLIScannerTool()
276279
log.info("Adding Sysdig CLI Scanner Tool...")

utils/query_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def create_standard_response(results: RESTResponseType, execution_time_ms: str,
2525
raise ApiException(
2626
status=results.status,
2727
reason=results.reason,
28+
data=results.data,
2829
)
2930
else:
3031
response = results.json() if results.data else {}

utils/sysdig/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_api_client(config: Configuration) -> ApiClient:
2020
return api_client_instance
2121

2222

23-
def initialize_api_client(config: Configuration) -> ApiClient:
23+
def initialize_api_client(config: Configuration = None) -> ApiClient:
2424
"""
2525
Initializes the Sysdig API client with the provided token and host.
2626
This function creates a new ApiClient instance and returns a dictionary of API instances

0 commit comments

Comments
 (0)