Skip to main content
Glama
iplocate

IPLocate

Official
by iplocate

Look up IP Address Location

lookup_ip_address_location

Find geographic location details for any IP address, including country, city, coordinates, and timezone. Use this tool to identify IP geolocation information for IPv4 or IPv6 addresses.

Instructions

Get geographic location information for an IP address including country, city, coordinates, timezone, and postal code. Can look up any IPv4 or IPv6 address, or your own IP if no address is provided.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ipNoIPv4 or IPv6 address to look up. If not provided, returns information about the caller's IP address.

Implementation Reference

  • The handler function that implements the core logic of the 'lookup_ip_address_location' tool. Validates IP, fetches data, filters to location fields, adds disclaimer, handles errors, and returns JSON-formatted response.
    async ({ ip }) => {
      if (ip && !isValidIP(ip)) {
        return {
          content: [{
            type: "text",
            text: `Error: "${ip}" is not a valid IPv4 or IPv6 address.`
          }],
          isError: true
        };
      }
    
      try {
        const data = await fetchIPData(ip);
        const locationData = {
          ip: data.ip,
          country: data.country,
          country_code: data.country_code,
          is_eu: data.is_eu,
          city: data.city,
          continent: data.continent,
          latitude: data.latitude,
          longitude: data.longitude,
          time_zone: data.time_zone,
          postal_code: data.postal_code,
          subdivision: data.subdivision,
          currency_code: data.currency_code,
          calling_code: data.calling_code,
          disclaimer: DISCLAIMER
        };
    
        return {
          content: [{
            type: "text",
            text: JSON.stringify(locationData, null, 2)
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    }
  • Zod-based input schema defining the optional 'ip' parameter for the tool.
    const IPAddressSchema = {
      ip: z.string().optional().describe("IPv4 or IPv6 address to look up. If not provided, returns information about the caller's IP address.")
    };
  • src/index.ts:136-190 (registration)
    Tool registration call using McpServer.registerTool, specifying name, title, description, input schema, and inline handler function.
    // Register tool: lookup_ip_address_location
    server.registerTool(
      "lookup_ip_address_location",
      {
        title: "Look up IP Address Location",
        description: "Get geographic location information for an IP address including country, city, coordinates, timezone, and postal code. Can look up any IPv4 or IPv6 address, or your own IP if no address is provided.",
        inputSchema: IPAddressSchema
      },
      async ({ ip }) => {
        if (ip && !isValidIP(ip)) {
          return {
            content: [{
              type: "text",
              text: `Error: "${ip}" is not a valid IPv4 or IPv6 address.`
            }],
            isError: true
          };
        }
    
        try {
          const data = await fetchIPData(ip);
          const locationData = {
            ip: data.ip,
            country: data.country,
            country_code: data.country_code,
            is_eu: data.is_eu,
            city: data.city,
            continent: data.continent,
            latitude: data.latitude,
            longitude: data.longitude,
            time_zone: data.time_zone,
            postal_code: data.postal_code,
            subdivision: data.subdivision,
            currency_code: data.currency_code,
            calling_code: data.calling_code,
            disclaimer: DISCLAIMER
          };
    
          return {
            content: [{
              type: "text",
              text: JSON.stringify(locationData, null, 2)
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • TypeScript interface defining the full structure of the IP geolocation API response data, imported and used to type the fetchIPData return value and extract location fields.
    export interface IPLocateResponse {
      ip: string;
      country?: string | null;
      country_code?: string | null;
      is_eu?: boolean;
      city?: string | null;
      continent?: string | null;
      latitude?: number | null;
      longitude?: number | null;
      time_zone?: string | null;
      postal_code?: string | null;
      subdivision?: string | null;
      currency_code?: string | null;
      calling_code?: string | null;
      network?: string | null;
      asn?: ASNInfo | null;
      privacy?: PrivacyInfo;
      company?: CompanyInfo | null;
      hosting?: HostingInfo | null;
      abuse?: AbuseInfo | null;
    }
  • Helper function that performs the actual HTTP fetch to the iplocate.io API, constructs URL with optional IP and API key, handles HTTP errors and JSON parsing, returns typed response data. Central to all IP lookup tools.
    async function fetchIPData(ip?: string): Promise<IPLocateResponse> {
      const baseUrl = "https://iplocate.io/api/lookup";
      const apiKey = process.env.IPLOCATE_API_KEY;
    
      let url = ip ? `${baseUrl}/${ip}` : `${baseUrl}/`;
    
      // Add API key if available
      if (apiKey) {
        url += `?apikey=${apiKey}`;
      }
    
      try {
        const response = await fetch(url, {
          headers: {
            'User-Agent': `mcp-server-iplocate/${VERSION}`
          }
        });
    
        if (!response.ok) {
          const errorText = await response.text();
          let errorMessage = `API request failed with status ${response.status}`;
    
          try {
            const errorJson = JSON.parse(errorText);
            if (errorJson.error) {
              errorMessage = errorJson.error;
            }
          } catch {
            // If not JSON, use the raw text
            if (errorText) {
              errorMessage = errorText;
            }
          }
    
          throw new Error(errorMessage);
        }
    
        const data = await response.json() as IPLocateResponse;
        return data;
      } catch (error) {
        if (error instanceof Error) {
          throw error;
        }
        throw new Error(`Failed to fetch IP data: ${String(error)}`);
      }
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits: it can handle both IPv4 and IPv6 addresses, and it defaults to returning the caller's IP if no address is provided. However, it doesn't mention potential rate limits, authentication needs, or error conditions, which are gaps for a tool with no annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence clearly states the purpose and key details, and the second sentence adds important behavioral context (address types and default). Every sentence earns its place with no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 optional parameter, no output schema, no annotations), the description is mostly complete. It covers purpose, usage, and key behavior. However, without annotations or output schema, it lacks details on return format (e.g., structure of geographic data) and error handling, which could be improved for full completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents the single parameter (ip). The description adds minimal value beyond the schema by reiterating that the parameter is for IPv4/IPv6 addresses and the default behavior, but doesn't provide additional syntax or format details. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get geographic location information') and resource ('for an IP address'), and distinguishes it from siblings by specifying the exact type of information returned (country, city, coordinates, timezone, postal code). It explicitly mentions what makes it different from other lookup tools that focus on abuse contacts, company details, network info, privacy, or general details.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool vs. alternatives: it specifies that this tool is for geographic location information, and by listing the sibling tools (e.g., lookup_ip_address_abuse_contacts), it implies alternatives for other types of IP data. It also clearly states when to use it ('if no address is provided' returns caller's IP info), though it doesn't explicitly say when not to use it, but the sibling context suffices.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/iplocate/mcp-server-iplocate'

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