get_ip_postal
Retrieve postal or ZIP code information from any IP address to determine geographic location for location-based services, verification, or analytics.
Instructions
Get just the postal code for an IP address.
Args: ip: IP address to lookup. If None, returns current postal code.
Returns: Postal or ZIP code.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | No |
Implementation Reference
- src/mcp_ipinfo/server.py:456-475 (handler)The main handler function for the 'get_ip_postal' MCP tool. Decorated with @mcp.tool() which handles registration. It fetches the postal code for the specified IP (or current IP) using the IPInfoClient and manages errors via the MCP context.@mcp.tool() async def get_ip_postal(ctx: Context[Any, Any, Any], ip: str | None = None) -> str: """Get just the postal code for an IP address. Args: ip: IP address to lookup. If None, returns current postal code. Returns: Postal or ZIP code. """ client = get_client(ctx) try: if ip: return await client.get_postal_by_ip(ip) else: return await client.get_current_postal() except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise