Skip to main content
Glama

geolocate

Retrieve geolocation details for an IP address or domain by inputting the query into the tool. Simplify location-based insights for seamless integration.

Instructions

Get geolocation information for an IP address or domain

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesIP address or domain to lookup

Implementation Reference

  • The main handler function for the 'geolocate' tool. It checks the cache first, enforces rate limiting, fetches geolocation data from ip-api.com if necessary, caches successful results, and returns a JSON-formatted response.
    handler: async ({ query }: { query: string }) => {
      // Check cache first
      const cached = geoCache.get(query);
      if (cached) {
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              data: cached,
              source: 'cache'
            }, null, 2)
          }]
        };
      }
    
      // Check rate limit
      if (!rateLimiter.canMakeRequest()) {
        const timeToReset = rateLimiter.getTimeToReset();
        throw new Error(`Rate limit exceeded. Please try again in ${Math.ceil(timeToReset / 1000)} seconds.`);
      }
    
      try {
        const { data, rateLimit } = await fetchGeoData(query);
        
        // Update rate limiter based on response headers
        rateLimiter.incrementRequests();
        
        // Cache successful responses
        if (data.status === 'success') {
          geoCache.set(query, data);
        }
    
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              data,
              rateLimit,
              source: 'api'
            }, null, 2)
          }]
        };
      } catch (error) {
        throw new Error(`Geolocation failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Tool metadata including name, description, and input schema definition for 'geolocate', specifying a required 'query' string parameter.
    geolocate: {
      name: 'geolocate',
      description: 'Get geolocation information for an IP address or domain',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'IP address or domain to lookup'
          }
        },
        required: ['query']
      },
  • src/index.ts:27-33 (registration)
    Registration of the 'geolocate' tool by spreading geoTools into the central allTools registry used for listing and dispatching tool calls.
    const allTools: ToolKit = {
      ...encodingTools,
      ...geoTools,
      ...generatorTools,
      ...dateTimeTools,
      ...securityTools
    };
  • Helper function that constructs the API request to ip-api.com, fetches geolocation data, and extracts rate limit information from headers.
    async function fetchGeoData(query: string): Promise<{ data: GeoLocation; rateLimit: RateLimitInfo }> {
      const fields = [
        'status',
        'message',
        'country',
        'countryCode',
        'region',
        'regionName',
        'city',
        'zip',
        'lat',
        'lon',
        'timezone',
        'offset',
        'isp',
        'org',
        'as',
        'query'
      ].join(',');
    
      const url = `http://ip-api.com/json/${encodeURIComponent(query)}?fields=${fields}`;
      
      const response = await fetch(url);
      const data = await response.json() as GeoLocation;
      
      const remaining = Number(response.headers.get('X-Rl') ?? '0');
      const ttl = Number(response.headers.get('X-Ttl') ?? '0');
    
      return {
        data,
        rateLimit: { remaining, ttl }
      };
    }
  • Initialization of the geolocation-specific cache (5 minutes TTL) and rate limiter (45 req/min) used by the handler.
    const geoCache = new Cache<GeoLocation>(5 * 60 * 1000); // 5 minute cache
    const rateLimiter = new RateLimiter(45, 60000); // 45 requests per minute
Behavior2/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 of behavioral disclosure. It states the tool retrieves information but doesn't cover aspects like rate limits, authentication needs, error handling, or data freshness. For a lookup tool with zero annotation coverage, this leaves significant gaps in understanding its operational behavior.

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 a single, efficient sentence: 'Get geolocation information for an IP address or domain.' It's front-loaded with the core purpose, has zero waste, and is appropriately sized for a simple lookup tool.

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

Completeness3/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 (one parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on behavior, usage context, or output format. For a geolocation tool, more information on what data is returned (e.g., coordinates, city) would enhance completeness, but it's not essential given the simplicity.

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?

The input schema has 100% description coverage, with the 'query' parameter documented as 'IP address or domain to lookup.' The description adds no additional meaning beyond this, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/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: 'Get geolocation information for an IP address or domain.' It specifies the action ('Get'), resource ('geolocation information'), and target ('IP address or domain'). However, it doesn't explicitly differentiate from sibling tools like 'listTimezones' or 'convertTimezone' that might involve location data, though those serve different purposes.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, exclusions (e.g., invalid inputs), or compare it to siblings like 'listTimezones' for broader location-related tasks. Usage is implied by the purpose but lacks explicit context.

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

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/MissionSquad/mcp-helper-tools'

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