1111from datetime import datetime
1212from typing import Optional , Annotated , Any , Dict
1313from pydantic import Field
14- from fastmcp import Context
1514from sysdig_client import ApiException
1615from fastmcp .prompts .prompt import PromptMessage , TextContent
1716from fastmcp .exceptions import ToolError
@@ -38,21 +37,21 @@ class EventsFeedTools:
3837 This class provides methods to retrieve event information and list runtime events.
3938 """
4039
41- def init_client (self , config_tags : set [ str ], old_api : bool = False ) -> SecureEventsApi | OldSysdigApi :
40+ def init_client (self , old_api : bool = False ) -> SecureEventsApi | OldSysdigApi :
4241 """
4342 Initializes the SecureEventsApi client from the request state.
4443 If the request does not have the API client initialized, it will create a new instance
4544 using the Sysdig Secure token and host from the environment variables.
4645 Args:
47- config_tags (set[str] ): The tags associated with the MCP server configuration, used to determine the transport mode .
46+ old_api (bool ): If True, initializes the OldSysdigApi client instead of SecureEventsApi .
4847 Returns:
4948 SecureEventsApi | OldSysdigApi: An instance of the SecureEventsApi or OldSysdigApi client.
5049 Raises:
5150 ValueError: If the SYSDIG_SECURE_TOKEN environment variable is not set.
5251 """
5352 secure_events_api : SecureEventsApi = None
5453 old_sysdig_api : OldSysdigApi = None
55- if " streamable-http" in config_tags :
54+ if app_config . get ( "mcp" , {}). get ( "transport" , "" ) == " streamable-http" :
5655 # Try to get the HTTP request
5756 log .debug ("Attempting to get the HTTP request to initialize the Sysdig API client." )
5857 request : Request = get_http_request ()
@@ -77,7 +76,7 @@ def init_client(self, config_tags: set[str], old_api: bool = False) -> SecureEve
7776 return old_sysdig_api
7877 return secure_events_api
7978
80- def tool_get_event_info (self , event_id : str , ctx : Context ) -> dict :
79+ def tool_get_event_info (self , event_id : str ) -> dict :
8180 """
8281 Retrieves detailed information for a specific security event.
8382
@@ -88,7 +87,7 @@ def tool_get_event_info(self, event_id: str, ctx: Context) -> dict:
8887 Event: The Event object containing detailed information about the specified event.
8988 """
9089 # Init of the sysdig client
91- secure_events_api = self .init_client (config_tags = ctx . fastmcp . tags )
90+ secure_events_api = self .init_client ()
9291 try :
9392 # Get the HTTP request
9493 start_time = time .time ()
@@ -106,7 +105,6 @@ def tool_get_event_info(self, event_id: str, ctx: Context) -> dict:
106105
107106 def tool_list_runtime_events (
108107 self ,
109- ctx : Context ,
110108 cursor : Optional [str ] = None ,
111109 scope_hours : int = 1 ,
112110 limit : int = 50 ,
@@ -148,15 +146,15 @@ def tool_list_runtime_events(
148146 cursor (Optional[str]): Cursor for pagination.
149147 scope_hours (int): Number of hours back from now to include events. Defaults to 1.
150148 severity_level (Optional[str]): One of "info", "low", "medium", "high". If provided, filters by that severity.
151- If None, includes all severities.
149+ If None, includes all severities.
152150 cluster_name (Optional[str]): Name of the Kubernetes cluster to filter events. If None, includes all clusters.
153151 limit (int): Maximum number of events to return. Defaults to 50.
154152 filter_expr (Optional[str]): An optional filter expression to further narrow down events.
155153
156154 Returns:
157- List[Event] : A list of Event objects matching the criteria .
155+ dict : A dictionary containing the results of the runtime events query, including pagination information .
158156 """
159- secure_events_api = self .init_client (config_tags = ctx . fastmcp . tags )
157+ secure_events_api = self .init_client ()
160158 start_time = time .time ()
161159 # Compute time window
162160 now_ns = time .time_ns ()
@@ -188,13 +186,12 @@ def tool_list_runtime_events(
188186
189187 # A tool to retrieve all the process-tree information for a specific event.Add commentMore actions
190188
191- def tool_get_event_process_tree (self , ctx : Context , event_id : str ) -> Dict [ str , Any ] :
189+ def tool_get_event_process_tree (self , event_id : str ) -> dict :
192190 """
193191 Retrieves the process tree for a specific security event.
194192 Not every event has a process tree, so this may return an empty tree.
195193
196194 Args:
197- ctx (Context): The context object containing request-specific information.
198195 event_id (str): The unique identifier of the security event.
199196
200197 Returns:
@@ -203,7 +200,7 @@ def tool_get_event_process_tree(self, ctx: Context, event_id: str) -> Dict[str,
203200 try :
204201 start_time = time .time ()
205202 # Get process tree branches
206- old_api_client = self .init_client (config_tags = ctx . fastmcp . tags , old_api = True )
203+ old_api_client = self .init_client (old_api = True )
207204 branches = old_api_client .request_process_tree_branches (event_id )
208205 # Get process tree
209206 tree = old_api_client .request_process_tree_trees (event_id )
0 commit comments