Skip to main content
Glama
dstreefkerk

ms-sentinel-mcp-server

by dstreefkerk

sentinel_analytics_rules_count_by_tactic

Count Microsoft Sentinel analytics rules by MITRE ATT&CK tactic to assess security coverage and identify gaps in threat detection.

Instructions

Count Sentinel analytics rules by tactic.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • The MCPToolBase subclass that implements the core logic of the tool. The `run` method fetches all Sentinel analytics rules, extracts MITRE tactics from each rule's tags, groups and counts rules by tactic (lowercased), and returns a structured dictionary with counts and rule lists per tactic.
    class SentinelAnalyticsRulesCountByTacticTool(MCPToolBase):
        """
        Count Sentinel analytics rules by tactic.
        Extracts tactics from each rule and returns a mapping of tactic to count and
        rule summaries.
        """
    
        name = "sentinel_analytics_rules_count_by_tactic"
        description = "Count Sentinel analytics rules by tactic."
    
        async def run(self, ctx: Context, **kwargs) -> Dict:
            """
            Count analytics rules by tactic.
            Returns a dict: {tactic: {count: int, rules: [{id, display_name}]}}
            """
            logger = self.logger
            workspace, resource_group, subscription_id = self.get_azure_context(ctx)
            if not (workspace and resource_group and subscription_id):
                logger.error("Missing Azure Sentinel context for analytics rule listing.")
                return {"error": "Missing Azure Sentinel context."}
            client = self.get_securityinsight_client(subscription_id)
            tactic_map = {}
            try:
                rules = client.alert_rules.list(
                    resource_group_name=resource_group,
                    workspace_name=workspace,
                )
                for rule in rules:
                    rule_dict = rule.as_dict() if hasattr(rule, "as_dict") else dict(rule)
                    # pylint: disable=unused-variable
                    tags, tactics, _ = extract_tags_tactics_techniques_from_dict(rule_dict)
                    display_name = (
                        rule_dict.get("display_name")
                        or rule_dict.get("displayName")
                        or rule_dict.get("name")
                    )
                    for tactic in tactics or ["Unknown"]:
                        tkey = tactic.lower() or "unknown"
                        if tkey not in tactic_map:
                            tactic_map[tkey] = {"count": 0, "rules": []}
                        tactic_map[tkey]["count"] += 1
                        tactic_map[tkey]["rules"].append(
                            {
                                "id": rule_dict.get("id"),
                                "display_name": display_name,
                            }
                        )
                return {
                    "valid": True,
                    "error": None,
                    "results": tactic_map,
                    "errors": [],
                }
            except Exception as e:
                logger.error("Error in %s: %s", self.__class__.__name__, str(e))
                return {
                    "valid": False,
                    "error": str(e),
                    "results": None,
                    "errors": [str(e)],
                }
  • The call to register this tool class with the MCP server instance.
    SentinelAnalyticsRulesCountByTacticTool.register(mcp)
  • Helper utility function to parse tags, tactics, and techniques from Sentinel analytics rule or template dictionaries. Called within the handler to extract tactics for grouping.
    def extract_tags_tactics_techniques_from_dict(obj):
        """
          Extract tags, tactics, and techniques from an analytics rule/template dict.
    
        Args:
            obj (dict): Analytics rule or template dictionary.
    
        Returns:
            tuple: (tags, tactics, techniques)
                tags (list[dict]): All tags as {name, value} pairs.
                tactics (list[str]): List of tactics (from tags or legacy fields).
                techniques (list[str]): List of techniques (from tags or legacy fields).
    
        Extraction precedence:
            - Tactics/techniques: Prefer tags with name 'tactics'/'techniques'
              (case-insensitive, split on comma). Fallback to legacy fields.
            - Tags: All tags as {name, value} pairs (robust to SDK object, dict, or string).
        """
        tags = []
        tactics = []
        techniques = []
        raw_tags = obj.get("tags")
        if raw_tags:
            for tag in raw_tags:
                tag_name = None
                tag_value = None
                if isinstance(tag, dict):
                    tag_name = tag.get("name") or tag.get("Name")
                    tag_value = tag.get("value") or tag.get("Value")
                elif hasattr(tag, "name") and hasattr(tag, "value"):
                    tag_name = getattr(tag, "name", None)
                    tag_value = getattr(tag, "value", None)
                elif isinstance(tag, str):
                    tag_name = tag
                    tag_value = None
                else:
                    try:
                        tag_name = str(tag)
                    except Exception:
                        continue
                if tag_name is not None:
                    tags.append({"name": tag_name, "value": tag_value})
        for tag in tags:
            if tag["name"] and isinstance(tag["name"], str):
                if tag["name"].lower() == "tactics" and tag["value"]:
                    tactics += [t.strip() for t in tag["value"].split(",") if t.strip()]
                elif tag["name"].lower() == "techniques" and tag["value"]:
                    techniques += [t.strip() for t in tag["value"].split(",") if t.strip()]
        legacy_tactics = obj.get("tactics")
        if legacy_tactics:
            tactics += [
                t.strip() for t in legacy_tactics if isinstance(t, str) and t.strip()
            ]
        legacy_techniques = obj.get("techniques")
        if legacy_techniques:
            techniques += [
                t.strip() for t in legacy_techniques if isinstance(t, str) and t.strip()
            ]
        tactics = list(dict.fromkeys([t for t in tactics if t]))
        techniques = list(dict.fromkeys([t for t in techniques if t]))
        return tags, tactics, techniques
Behavior1/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It only states what the tool does at a high level, with no information about permissions, rate limits, output format, error handling, or whether it's a read-only operation. This is inadequate for a tool with unknown behavioral traits.

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 states the core purpose without unnecessary words. It's appropriately sized for a simple counting operation and front-loads the essential information.

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

Completeness1/5

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

Given no annotations, 0% schema description coverage, no output schema, and one undocumented parameter, the description is completely inadequate. It doesn't compensate for the missing structured information, leaving users guessing about how to use the tool and what to expect from it.

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 one parameter 'kwargs' with 0% description coverage, and the tool description provides no information about parameters. The description doesn't explain what 'kwargs' should contain, how to specify tactics, or any filtering options. This leaves the parameter completely undocumented.

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

Purpose3/5

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

The description 'Count Sentinel analytics rules by tactic' clearly states the action (count) and resource (Sentinel analytics rules), but it's somewhat vague about what 'by tactic' means operationally. It distinguishes from siblings like 'sentinel_analytics_rule_list' (which lists rules) and 'sentinel_analytics_rules_count_by_technique' (which counts by technique instead of tactic), but lacks specificity on the counting mechanism.

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, context for counting by tactic, or compare it to similar tools like 'sentinel_analytics_rules_count_by_technique' or 'sentinel_analytics_rule_templates_count_by_tactic'. Users must infer usage from the name alone.

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