Skip to main content
Glama

get_ip_country

Retrieve the two-letter country code for any IP address using IP geolocation. Specify an IP to get its country or omit to identify your current location.

Instructions

Get just the country code for an IP address.

Args: ip: IP address to lookup. If None, returns current country.

Returns: Two-letter country code (ISO-3166).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ipNo

Implementation Reference

  • The main handler function for the 'get_ip_country' tool. It is registered via the @mcp.tool() decorator. The function retrieves the country code for a given IP address (or the current IP if none provided) using the IPInfoClient, handling API errors appropriately.
    @mcp.tool() async def get_ip_country(ctx: Context[Any, Any, Any], ip: str | None = None) -> str: """Get just the country code for an IP address. Args: ip: IP address to lookup. If None, returns current country. Returns: Two-letter country code (ISO-3166). """ client = get_client(ctx) try: if ip: return await client.get_country_by_ip(ip) else: return await client.get_current_country() except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise

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/NimbleBrainInc/mcp-ipinfo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server