get_ip_region
Retrieve the geographic region or state associated with an IP address to determine location-based information for network analysis or geolocation purposes.
Instructions
Get just the region/state for an IP address.
Args: ip: IP address to lookup. If None, returns current region.
Returns: Region or state name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | No |
Implementation Reference
- src/mcp_ipinfo/server.py:414-432 (handler)The handler function implementing the 'get_ip_region' tool logic. Decorated with @mcp.tool() for automatic registration in the FastMCP server. Delegates to IPInfoClient methods for API calls.@mcp.tool() async def get_ip_region(ctx: Context[Any, Any, Any], ip: str | None = None) -> str: """Get just the region/state for an IP address. Args: ip: IP address to lookup. If None, returns current region. Returns: Region or state name. """ client = get_client(ctx) try: if ip: return await client.get_region_by_ip(ip) else: return await client.get_current_region() except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise
- src/mcp_ipinfo/api_client.py:348-356 (helper)Supporting helper methods in the IPInfoClient class that handle the actual HTTP requests to the IPInfo API for retrieving region information.async def get_current_region(self) -> str: """Get current region.""" data = await self._request("GET", "/region") return str(data.get("result", "")) async def get_region_by_ip(self, ip: str) -> str: """Get region for an IP.""" data = await self._request("GET", f"/{ip}/region") return str(data.get("result", ""))