get_ip_location
Retrieve latitude and longitude coordinates for any IP address to determine its geographic location. When no IP is specified, returns the coordinates of your current location.
Instructions
Get just the coordinates for an IP address.
Args: ip: IP address to lookup. If None, returns current location.
Returns: Latitude,longitude coordinates.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | No |
Implementation Reference
- src/mcp_ipinfo/server.py:435-453 (handler)The MCP tool handler and registration for 'get_ip_location'. This async function executes the tool logic by calling the IPInfoClient to retrieve latitude/longitude coordinates for the specified IP or current IP.@mcp.tool() async def get_ip_location(ctx: Context[Any, Any, Any], ip: str | None = None) -> str: """Get just the coordinates for an IP address. Args: ip: IP address to lookup. If None, returns current location. Returns: Latitude,longitude coordinates. """ client = get_client(ctx) try: if ip: return await client.get_location_by_ip(ip) else: return await client.get_current_location() except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise
- src/mcp_ipinfo/api_client.py:373-376 (helper)Core helper method in IPInfoClient that makes the HTTP request to IPInfo API endpoint /{ip}/loc to fetch the location coordinates string.async def get_location_by_ip(self, ip: str) -> str: """Get location coordinates for an IP.""" data = await self._request("GET", f"/{ip}/loc") return str(data.get("result", ""))