Skip to main content
Glama
dstreefkerk

ms-sentinel-mcp-server

by dstreefkerk

sentinel_query_validate

Validate KQL query syntax locally to ensure proper structure before execution in Microsoft Sentinel.

Instructions

Validate KQL Query Syntax locally

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • The main handler function (run method) that implements the tool logic: extracts 'query' parameter, calls validate_kql helper, handles errors, and returns validation results.
    async def run(self, ctx: Context, **kwargs):
        """
        Validate a KQL query and return the result.
    
        Args:
            ctx (Context): The context of the MCP server.
            **kwargs: Additional keyword arguments.
    
        Returns:
            dict: A dictionary containing the validation result.
        """
        # Extract query using the centralized parameter extraction from MCPToolBase
        query = self._extract_param(kwargs, "query")
        logger = self.logger
        if not query:
            logger.error("Missing required parameter: query")
            return {
                "error": "Missing required parameter: query",
                "valid": False,
                "errors": ["Missing required parameter: query"],
            }
        try:
            is_valid, errors = validate_kql(query)
            if is_valid:
                return {
                    "result": (
                        "Query validation passed. "
                        "The KQL syntax appears to be correct."
                    ),
                    "valid": True,
                    "errors": [],
                }
            error_message = "KQL validation failed:\n" + "\n".join(errors)
            # Warn via context if available
            if hasattr(ctx, "warning") and callable(getattr(ctx, "warning", None)):
                await ctx.warning(error_message)
            # Special handling for initialization error
            if any("KQL validation unavailable" in err for err in errors):
                return {"error": error_message, "valid": False, "errors": errors}
            return {"error": error_message, "valid": False, "errors": errors}
        except Exception as e:
            logger.error("Error validating KQL query: %s", e, exc_info=True)
            return {
                "error": (
                    "An error occurred while validating the query. "
                    "Try validating code by executing a KQL query against the "
                    "workspace instead: %s" % str(e)
                ),
                "valid": False,
                "errors": [str(e)],
            }
  • Registers the sentinel_query_validate tool (KQLValidateTool) with the FastMCP server instance.
    def register_tools(mcp: FastMCP):
        """
        Register KQL tools with the MCP server.
    
        Args:
            mcp (FastMCP): The MCP server instance to register tools with.
        """
        KQLValidateTool.register(mcp)
  • Core helper function that performs KQL syntax validation using the KQLValidator singleton, which uses Kusto.Language.dll via pythonnet for offline syntax checking.
    def validate_kql(query: str) -> Tuple[bool, List[str]]:
        """
        Validate a KQL query.
    
        Args:
            query: The KQL query to validate.
    
        Returns:
            Tuple[bool, List[str]]: (is_valid, list_of_error_messages)
        """
        validator = get_validator()
        if not validator.initialized:
            return False, [
                "KQL validation unavailable: Could not initialize validator.",
                "For syntax validation, please use the query tool to validate against your workspace.",
            ]
        return validator.validate_query(query)
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'locally' which implies no network call or resource consumption, but doesn't disclose what validation entails (syntax checking, semantic validation, performance estimation), what errors might be returned, or whether this affects any system state. For a validation tool with zero annotation coverage, this is insufficient behavioral disclosure.

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 extremely concise at just 5 words. It's front-loaded with the core purpose and wastes no words. Every word earns its place by conveying essential information about what the tool does and its scope.

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 tool's apparent simplicity (single parameter, no output schema), the description is incomplete. It doesn't explain what constitutes valid KQL syntax, what the validation output looks like, or how this differs from executing queries. With no annotations and minimal parameter documentation, the description should provide more context about the tool's behavior and results.

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

Parameters2/5

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

The description provides no information about the single parameter 'kwargs'. With 0% schema description coverage and no parameter details in the description, the agent has no guidance on what to pass. The description doesn't compensate for the schema's lack of documentation, leaving the parameter's purpose and format completely unspecified.

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 tool's purpose: 'Validate KQL Query Syntax locally'. It specifies the verb (validate), resource (KQL Query Syntax), and scope (locally). However, it doesn't differentiate from sibling tools like 'sentinel_logs_search' which might also involve KQL queries but for different purposes.

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. It doesn't mention prerequisites, when validation is needed, or what happens after validation. With many sibling tools for Sentinel operations, this lack of context leaves the agent guessing about appropriate usage scenarios.

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