Skip to main content
Glama
dstreefkerk

ms-sentinel-mcp-server

by dstreefkerk

sentinel_ip_geodata_get

Retrieve geolocation information for any IP address to identify geographic origins and enhance security analysis.

Instructions

Get geolocation data for an IP address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • The async run method implements the tool's core logic: extracts 'ip' parameter, initializes Azure SecurityInsights client, calls ip_geodata.get via run_in_thread, processes response to dict, handles errors.
    async def run(self, ctx: Context, **kwargs):
        """
        Get geolocation data for an IP address.
    
        Args:
            ctx (Context): The MCP tool context.
            **kwargs: IP address as 'ip' parameter.
    
        Returns:
            dict: Results as described in the class docstring.
        """
    
        # Extract parameters
        # Extract ip parameter using the centralized parameter extraction from MCPToolBase
        ip = self._extract_param(kwargs, "ip")
    
        if not ip:
            return {"error": "ip parameter is required", "valid": False}
    
        # Get Azure context
        workspace_name, resource_group, subscription_id = self.get_azure_context(ctx)
    
        # Get security insights client
        client = None
        try:
            client = self.get_securityinsight_client(subscription_id)
        except Exception as e:
            self.logger.error("Error initializing Azure SecurityInsights client: %s", e)
            return {
                "error": (
                    f"Azure SecurityInsights client initialization failed: {str(e)}"
                ),
                "valid": False,
            }
    
        if client is None:
            return {
                "error": "Azure SecurityInsights client is not initialized",
                "valid": False,
            }
    
        # Validate Azure context
        valid = self.validate_azure_context(
            client is not None,
            workspace_name,
            resource_group,
            subscription_id,
            self.logger,
        )
        if not valid:
            return {
                "error": "Missing required Azure context or SDK components",
                "valid": False,
            }
    
        try:
            # Get geolocation data for the IP address
            # Based on SDK testing, ip_geodata.get() doesn't accept workspace_name
            geodata = await run_in_thread(
                client.ip_geodata.get,
                resource_group_name=resource_group,
                ip_address=ip,
            )
    
            # Process geodata result
            # Return the full geodata object
            geodata_dict = {}
            if hasattr(geodata, "as_dict"):
                geodata_dict = geodata.as_dict()
            else:
                # If as_dict() is not available, try to convert to dict directly
                geodata_dict = dict(geodata) if geodata else {}
    
            # Ensure we have at least the IP in the response
            if not geodata_dict or not geodata_dict.get("ip"):
                geodata_dict["ip"] = ip
    
            return {
                "geodata": geodata_dict,
                "valid": True,
            }
        except Exception as e:
            self.logger.error("Error retrieving IP geodata for %s: %s", ip, e)
            return {
                "error": f"Error retrieving IP geodata for {ip}: {str(e)}",
                "valid": False,
            }
  • Tool name and description defining the schema and expected input ('ip' parameter) and output format as described in class docstring.
    name = "sentinel_ip_geodata_get"
    description = "Get geolocation data for an IP address"
  • Registers the SentinelIPGeodataGetTool with the MCP instance in the register_tools function.
    SentinelIPGeodataGetTool.register(mcp)
  • Full class definition of the MCPToolBase subclass implementing the sentinel_ip_geodata_get tool, including docstring for schema.
    class SentinelIPGeodataGetTool(MCPToolBase):
        """
        Tool to get geolocation data for an IP address.
    
        Returns:
            dict: {
                'geodata': dict,   # Geolocation data as returned by the API
                'valid': bool,     # True if successful
                'error': str (optional)
            }
        """
    
        name = "sentinel_ip_geodata_get"
        description = "Get geolocation data for an IP address"
    
        async def run(self, ctx: Context, **kwargs):
            """
            Get geolocation data for an IP address.
    
            Args:
                ctx (Context): The MCP tool context.
                **kwargs: IP address as 'ip' parameter.
    
            Returns:
                dict: Results as described in the class docstring.
            """
    
            # Extract parameters
            # Extract ip parameter using the centralized parameter extraction from MCPToolBase
            ip = self._extract_param(kwargs, "ip")
    
            if not ip:
                return {"error": "ip parameter is required", "valid": False}
    
            # Get Azure context
            workspace_name, resource_group, subscription_id = self.get_azure_context(ctx)
    
            # Get security insights client
            client = None
            try:
                client = self.get_securityinsight_client(subscription_id)
            except Exception as e:
                self.logger.error("Error initializing Azure SecurityInsights client: %s", e)
                return {
                    "error": (
                        f"Azure SecurityInsights client initialization failed: {str(e)}"
                    ),
                    "valid": False,
                }
    
            if client is None:
                return {
                    "error": "Azure SecurityInsights client is not initialized",
                    "valid": False,
                }
    
            # Validate Azure context
            valid = self.validate_azure_context(
                client is not None,
                workspace_name,
                resource_group,
                subscription_id,
                self.logger,
            )
            if not valid:
                return {
                    "error": "Missing required Azure context or SDK components",
                    "valid": False,
                }
    
            try:
                # Get geolocation data for the IP address
                # Based on SDK testing, ip_geodata.get() doesn't accept workspace_name
                geodata = await run_in_thread(
                    client.ip_geodata.get,
                    resource_group_name=resource_group,
                    ip_address=ip,
                )
    
                # Process geodata result
                # Return the full geodata object
                geodata_dict = {}
                if hasattr(geodata, "as_dict"):
                    geodata_dict = geodata.as_dict()
                else:
                    # If as_dict() is not available, try to convert to dict directly
                    geodata_dict = dict(geodata) if geodata else {}
    
                # Ensure we have at least the IP in the response
                if not geodata_dict or not geodata_dict.get("ip"):
                    geodata_dict["ip"] = ip
    
                return {
                    "geodata": geodata_dict,
                    "valid": True,
                }
            except Exception as e:
                self.logger.error("Error retrieving IP geodata for %s: %s", ip, e)
                return {
                    "error": f"Error retrieving IP geodata for {ip}: {str(e)}",
                    "valid": False,
                }
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 mentions 'Get' which implies a read operation, but doesn't specify whether this requires authentication, rate limits, what format the geolocation data returns, or any error conditions. This leaves significant gaps for a tool with no annotation coverage.

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 functionality without unnecessary words. It's appropriately sized and front-loaded with the essential information.

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?

For a tool with no annotations, no output schema, and undocumented parameters, the description is insufficient. It covers the basic purpose but lacks crucial details about behavior, parameter usage, and return values that would help an agent use it 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 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 this parameter expects or how to format it. This is inadequate for a tool with one required parameter.

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 ('Get') and resource ('geolocation data for an IP address'), making the purpose immediately understandable. It doesn't explicitly distinguish from siblings, but since none of the sibling tools appear to handle IP geolocation, this is sufficient for clarity.

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, prerequisites, or constraints. It simply states what the tool does without context about appropriate scenarios or limitations.

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