Skip to main content
Glama
ip2location

IP2Location IP Geolocation MCP Server

Official

get_geolocation

Retrieve detailed geolocation data for any IP address, including country, region, city, network info, proxy status, and more, using IP2Location.io API integration.

Instructions

Fetch geolocation for the given IP address.

It helps users to retrieve detailed information such as country, region, city, latitude, longitude, ZIP code, time zone, ASN, and proxy information for any IPv4 or IPv6 address

Args: ip: The IP address to analyze (IPv4 or IPv6).

Returns: A JSON string result includes:

Location & Geography: Country, region, district, city, ZIP code, latitude & longitude, time zone. Network & Connectivity ASN (Autonomous System Number), ISP (Internet Service Provider), domain, net speed, IDD code, area code, address type, usage type. Mobile Information MNC (Mobile Network Code), MCC (Mobile Country Code), Mobile Brand. Currency & Language currency code, currency name, currency symbol, language code, language name. Proxy & Security proxy type, last seen, threat level/type, proxy provider, fraud score. Others IAB category, weather, elevation, population and more. Note that some information may only available in paid plan. Learn more on this in https://www.ip2location.io/pricing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ipYes

Implementation Reference

  • The main handler function for the 'get_geolocation' tool. It constructs API parameters, fetches data from IP2Location.io using the helper function, and returns the result or an error message.
    async def get_geolocation(ip: str) -> Dict[str, Any] | str: """ Fetch geolocation for the given IP address. It helps users to retrieve detailed information such as country, region, city, latitude, longitude, ZIP code, time zone, ASN, and proxy information for any IPv4 or IPv6 address Args: ip: The IP address to analyze (IPv4 or IPv6). Returns: A JSON string result includes: Location & Geography: Country, region, district, city, ZIP code, latitude & longitude, time zone. Network & Connectivity ASN (Autonomous System Number), ISP (Internet Service Provider), domain, net speed, IDD code, area code, address type, usage type. Mobile Information MNC (Mobile Network Code), MCC (Mobile Country Code), Mobile Brand. Currency & Language currency code, currency name, currency symbol, language code, language name. Proxy & Security proxy type, last seen, threat level/type, proxy provider, fraud score. Others IAB category, weather, elevation, population and more. Note that some information may only available in paid plan. Learn more on this in https://www.ip2location.io/pricing. """ params = {"ip": ip} api_key = get_api_key() if api_key: params["key"] = api_key # IP2Location.io API key parameter geolocation_result = await make_request(IPLIO_API_BASE, params) if not geolocation_result: return f"Unable to fetch geolocation for IP {ip}." return geolocation_result
  • Docstring defining the input schema (ip: str) and detailed output description for the tool.
    """ Fetch geolocation for the given IP address. It helps users to retrieve detailed information such as country, region, city, latitude, longitude, ZIP code, time zone, ASN, and proxy information for any IPv4 or IPv6 address Args: ip: The IP address to analyze (IPv4 or IPv6). Returns: A JSON string result includes: Location & Geography: Country, region, district, city, ZIP code, latitude & longitude, time zone. Network & Connectivity ASN (Autonomous System Number), ISP (Internet Service Provider), domain, net speed, IDD code, area code, address type, usage type. Mobile Information MNC (Mobile Network Code), MCC (Mobile Country Code), Mobile Brand. Currency & Language currency code, currency name, currency symbol, language code, language name. Proxy & Security proxy type, last seen, threat level/type, proxy provider, fraud score. Others IAB category, weather, elevation, population and more. Note that some information may only available in paid plan. Learn more on this in https://www.ip2location.io/pricing. """
  • src/server.py:32-32 (registration)
    Registration of the 'get_geolocation' tool using the FastMCP @tool decorator.
    async def get_geolocation(ip: str) -> Dict[str, Any] | str:
  • Helper function to make HTTP requests to the IP2Location.io API.
    async def make_request(url: str, params: dict[str, str]) -> dict[str, Any] | None: """Make a request to the IP2Location.io API with proper error handling.""" headers = { "User-Agent": USER_AGENT, "Accept": "application/json" } async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, params=params, timeout=30.0) response.raise_for_status() return response.json() except Exception: return None
  • Helper function to retrieve the IP2Location.io API key from environment variable.
    def get_api_key() -> str | None: """Retrieve the API key from MCP server config.""" return os.getenv("IP2LOCATION_API_KEY")

Other Tools

Related 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/ip2location/mcp-ip2location-io'

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