Skip to main content
Glama
dstreefkerk

ms-sentinel-mcp-server

by dstreefkerk

log_analytics_saved_search_get

Retrieve a specific saved search from a Log Analytics workspace to access predefined queries and analysis configurations for security monitoring.

Instructions

Get a specific saved search from a Log Analytics workspace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • The async run method that implements the core logic for retrieving a specific Log Analytics saved search by ID using the Azure LogAnalyticsManagementClient.
    async def run(self, ctx: Context, **kwargs):
        """
        Retrieve a specific saved search by ID from the specified Log Analytics workspace.
    
        Args:
            ctx (Context): The FastMCP context containing authentication and request information.
            **kwargs: Keyword arguments containing 'saved_search_id'.
    
        Returns:
            dict: Dictionary containing the saved search details and validity flag, or
            error information.
        """
        # Extract saved_search_id parameter using the
        # centralized parameter extraction from MCPToolBase
        saved_search_id = self._extract_param(kwargs, "saved_search_id")
    
        if not saved_search_id:
            return {"error": "saved_search_id parameter is required"}
    
        # 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" % str(e)
            }
    
        if client is None:
            return {"error": "Azure LogAnalytics client is not initialized"}
    
        try:
            # Get the specific saved search
            search = await run_in_thread(
                client.saved_searches.get,
                resource_group_name=resource_group,
                workspace_name=workspace_name,
                saved_search_id=saved_search_id,
            )
    
            # Log the search object to understand its structure
            self.logger.debug("Saved search object: %s", search)
    
            # Create a detailed info dictionary with all available attributes
            search_details = {
                "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,
            }
    
            # Based on the log output, the properties are directly accessible
            # as attributes of the search object, not nested under properties
            properties_to_check = [
                "category",
                "display_name",
                "query",
                "function_alias",
                "function_parameters",
                "version",
                "tags",
                "etag",
                "time_created",
                "time_modified",
            ]
    
            # Check for each property and add it if it exists
            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_details[key] = value
    
            # Check for additional_properties if they exist
            if (
                hasattr(search, "additional_properties")
                and search.additional_properties
            ):
                for key, value in search.additional_properties.items():
                    if value is not None and key not in search_details:
                        search_details[key] = value
    
            return {"savedSearch": search_details, "valid": True}
        except Exception as e:
            self.logger.error(
                "Error retrieving saved search with ID %s: %s", saved_search_id, e
            )
            return {
                "error": "Error retrieving saved search ID %s: %s"
                % (saved_search_id, str(e))
            }
  • Tool class definition including name, description, and docstring which define the tool's schema and parameters (saved_search_id).
    class LogAnalyticsSavedSearchGetTool(MCPToolBase):
        """
        Tool to retrieve a specific saved search from a Log Analytics workspace.
        """
    
        name = "log_analytics_saved_search_get"
        description = "Get a specific saved search from a Log Analytics workspace"
  • The register_tools function that calls register on LogAnalyticsSavedSearchGetTool to register it with the FastMCP server.
    def register_tools(mcp: FastMCP):
        """
        Register Log Analytics saved search tools with the MCP server.
    
        Args:
            mcp (FastMCP): The FastMCP server instance to register tools with.
        """
        LogAnalyticsSavedSearchesListTool.register(mcp)
        LogAnalyticsSavedSearchGetTool.register(mcp)
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 states it's a read operation ('Get'), but doesn't mention authentication requirements, error handling, rate limits, or what happens if the saved search doesn't exist. This leaves significant gaps for an agent to understand the tool's behavior.

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, clear sentence with no wasted words. It's front-loaded with the core purpose and efficiently communicates the essential action without unnecessary elaboration.

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 no annotations, 0% schema coverage, and no output schema, the description is incomplete. It covers the basic purpose but fails to address parameter usage, behavioral context, or output expectations, which are critical for a tool with undocumented inputs.

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 input schema has 1 parameter with 0% description coverage, and the tool description provides no information about parameters. It doesn't explain what 'kwargs' should contain (e.g., saved search name, ID, or workspace details), leaving the parameter completely undocumented.

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 action ('Get') and resource ('a specific saved search from a Log Analytics workspace'), making the purpose immediately understandable. It doesn't explicitly differentiate from its sibling 'log_analytics_saved_searches_list', but the distinction is implied through 'specific' versus 'list' naming.

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 like 'log_analytics_saved_searches_list' or other get/list siblings. It lacks context about prerequisites, such as needing a saved search name or ID, or when this is appropriate over listing all searches.

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