Skip to main content
Glama
dstreefkerk

ms-sentinel-mcp-server

by dstreefkerk

log_analytics_saved_searches_list

Retrieve all saved search queries from a Log Analytics workspace to monitor and analyze security data efficiently.

Instructions

List all saved searches in a Log Analytics workspace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • The async run method that executes the tool logic: validates context, initializes Log Analytics client, lists saved searches, processes them into a structured list, and returns the result.
    async def run(self, ctx: Context, **kwargs):
        """
        List all saved searches in the specified Log Analytics workspace.
    
        Args:
            ctx (Context): The FastMCP context containing authentication and request information.
            **kwargs: Additional keyword arguments (unused).
    
        Returns:
            dict: Dictionary containing the list of saved searches, count, and validity flag.
        """
        # Get Azure context
        workspace_name, resource_group, subscription_id = self.get_azure_context(ctx)
    
        # Validate Azure context
        sdk_available = True
        try:
            # Just check if the module is available
            import importlib.util  # pylint: disable=import-outside-toplevel
    
            sdk_available = (
                importlib.util.find_spec("azure.mgmt.loganalytics") is not None
            )
        except ImportError:
            sdk_available = False
    
        if not self.validate_azure_context(
            sdk_available, workspace_name, resource_group, subscription_id, self.logger
        ):
            return {"error": "Missing Azure SDK or workspace details."}
    
        # Get Log Analytics client
        client = None
        try:
            client = self.get_loganalytics_client(subscription_id)
        except Exception as e:
            self.logger.error("Error initializing Azure LogAnalytics client: %s", e)
            return {"error": "Azure LogAnalytics client initialization failed: %s" % e}
    
        if client is None:
            return {"error": "Azure LogAnalytics client is not initialized"}
    
        try:
            # List all saved searches in the workspace
            saved_searches_result = await run_in_thread(
                client.saved_searches.list_by_workspace,
                resource_group_name=resource_group,
                workspace_name=workspace_name,
            )
    
            # Log the result to understand its structure
            self.logger.info(
                "Saved searches result type: %s", type(saved_searches_result)
            )
    
            result = []
            # Check if the result has a 'value' attribute which is the actual list
            if hasattr(saved_searches_result, "value"):
                saved_searches = saved_searches_result.value
            else:
                # If not, try to access it as a dictionary
                saved_searches = getattr(saved_searches_result, "saved_searches", [])
    
            self.logger.info(
                "Processing %s saved searches",
                len(saved_searches) if saved_searches else 0,
            )
    
            for search in saved_searches:
                # Create a basic info dictionary with guaranteed attributes
                search_info = {
                    "id": search.id if hasattr(search, "id") else None,
                    "name": search.name if hasattr(search, "name") else None,
                    "type": search.type if hasattr(search, "type") else None,
                }
    
                # Try to access properties directly from the search object first
                try:
                    # Check for direct properties on the search object
                    properties_to_check = [
                        "category",
                        "display_name",
                        "query",
                        "function_alias",
                        "function_parameters",
                        "version",
                        "tags",
                        "etag",
                        "time_created",
                        "time_modified",
                    ]
    
                    for prop_name in properties_to_check:
                        if hasattr(search, prop_name):
                            value = getattr(search, prop_name)
                            if value is not None:
                                # Convert snake_case to camelCase for consistency in the output
                                key = "".join(
                                    [
                                        x.capitalize() if i > 0 else x
                                        for i, x in enumerate(prop_name.split("_"))
                                    ]
                                )
                                search_info[key] = value
    
                    # If we couldn't find any direct properties, try the nested properties approach
                    if len(search_info) <= 3 and hasattr(search, "properties"):
                        props = search.properties
                        if hasattr(props, "category"):
                            search_info["category"] = props.category
                        if hasattr(props, "display_name"):
                            search_info["displayName"] = props.display_name
                        if hasattr(props, "query"):
                            search_info["query"] = props.query
                        if hasattr(props, "function_alias"):
                            search_info["functionAlias"] = props.function_alias
                        if hasattr(props, "version"):
                            search_info["version"] = props.version
                        if hasattr(props, "tags"):
                            search_info["tags"] = props.tags
                        if hasattr(props, "etag"):
                            search_info["etag"] = props.etag
                except Exception as prop_error:
                    # Log the property access error but continue with basic details
                    self.logger.error(
                        "Error accessing saved search properties: %s", prop_error
                    )
    
                result.append(search_info)
    
            return {"savedSearches": result, "count": len(result), "valid": True}
        except Exception as e:
            self.logger.error("Error retrieving saved searches: %s", e)
            return {"error": "Error retrieving saved searches: %s" % str(e)}
  • Registers the tool with the MCP server instance.
    LogAnalyticsSavedSearchesListTool.register(mcp)
  • Tool metadata: name and description used for schema/registration.
    name = "log_analytics_saved_searches_list"
    description = "List all saved searches in a Log Analytics workspace"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It implies a read-only list operation but doesn't specify details like authentication requirements, rate limits, pagination, or return format. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a list operation with 1 parameter, no annotations, and no output schema, the description is incomplete. It lacks parameter details, behavioral context, and usage guidelines, making it insufficient for an agent to fully understand how to invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter information beyond what the input schema provides. With 0% schema description coverage and 1 required parameter ('kwargs'), the description fails to explain what 'kwargs' represents or how to use it, leaving the parameter undocumented and unclear.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('all saved searches in a Log Analytics workspace'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from its sibling 'log_analytics_saved_search_get', which appears to retrieve a single saved search, so it misses full sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of prerequisites, context, or comparisons to sibling tools like 'log_analytics_saved_search_get' or other list tools in the server, leaving the agent without usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dstreefkerk/ms-sentinel-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server