Skip to main content
Glama

get_location

Retrieve precise geographic location data based on IP address to deliver location-specific recommendations, services, and information tailored to the user's actual position.

Instructions

【建议调用】根据IP地址获取用户的真实地理位置信息。

⚠️ 重要:不要假设用户的位置,调用此工具获取准确的地理信息。

强制调用场景:

  • 用户询问位置相关问题("我在哪里"、"我的位置")

  • 需要提供本地化建议(推荐服务、资源、网站、学习平台)

  • 讨论地区特定话题(天气、时差、当地服务、可访问性)

  • 提供安装指令、下载链接时(不同地区可能有不同的镜像源)

  • 推荐内容时(语言、文化、法规差异)

返回信息:国家、地区、城市、经纬度、时区、ISP等完整地理位置信息。

⚠️ 在提供地区特定建议前,应主动调用此工具确认用户位置!

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ipNoIP地址(可选,不提供则自动获取用户当前公网IP)

Implementation Reference

  • The main handler function that executes the tool logic: fetches geolocation data from ip-api.com based on provided or auto-detected IP address.
    export async function getLocationInfo(ip?: string) {
      try {
        // 如果没有提供IP,获取当前公网IP
        const targetIp = ip || await publicIpv4();
        
        // 使用免费的 IP 地理位置 API
        const response = await fetch(`http://ip-api.com/json/${targetIp}?lang=zh-CN`);
        
        if (!response.ok) {
          throw new Error(`API请求失败: ${response.status}`);
        }
        
        const data = await response.json() as IpApiResponse;
        
        if (data.status === "fail") {
          throw new Error(data.message || "无法获取位置信息");
        }
        
        return {
          ip: targetIp,
          country: data.country,
          countryCode: data.countryCode,
          region: data.regionName,
          regionCode: data.region,
          city: data.city,
          zip: data.zip,
          latitude: data.lat,
          longitude: data.lon,
          timezone: data.timezone,
          isp: data.isp,
          org: data.org,
          as: data.as,
        };
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`获取位置信息失败: ${error.message}`);
        }
        throw error;
      }
    }
  • src/index.ts:60-85 (registration)
    Tool registration in the ListTools response, including name, description, and input schema.
          {
            name: "get_location",
            description: `【建议调用】根据IP地址获取用户的真实地理位置信息。
    
    ⚠️ 重要:不要假设用户的位置,调用此工具获取准确的地理信息。
    
    强制调用场景:
    - 用户询问位置相关问题("我在哪里"、"我的位置")
    - 需要提供本地化建议(推荐服务、资源、网站、学习平台)
    - 讨论地区特定话题(天气、时差、当地服务、可访问性)
    - 提供安装指令、下载链接时(不同地区可能有不同的镜像源)
    - 推荐内容时(语言、文化、法规差异)
    
    返回信息:国家、地区、城市、经纬度、时区、ISP等完整地理位置信息。
    
    ⚠️ 在提供地区特定建议前,应主动调用此工具确认用户位置!`,
            inputSchema: {
              type: "object",
              properties: {
                ip: {
                  type: "string",
                  description: "IP地址(可选,不提供则自动获取用户当前公网IP)",
                },
              },
            },
          },
  • src/index.ts:199-209 (registration)
    Tool invocation handler in the CallToolRequestSchema switch statement that calls the getLocationInfo function.
    case "get_location": {
      const result = await getLocationInfo(args?.ip as string);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • TypeScript interface defining the structure of the response from the IP geolocation API.
    interface IpApiResponse {
      status: string;
      message?: string;
      country: string;
      countryCode: string;
      regionName: string;
      region: string;
      city: string;
      zip: string;
      lat: number;
      lon: number;
      timezone: string;
      isp: string;
      org: string;
      as: string;
    }
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it returns comprehensive location data (country, region, city, coordinates, timezone, ISP), emphasizes accuracy over assumptions, and mandates proactive calls in specific scenarios. However, it lacks details on rate limits, error handling, or authentication needs, which would be helpful for a tool with no annotation coverage.

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

Conciseness4/5

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

The description is well-structured and front-loaded with the core purpose, followed by important warnings and detailed usage scenarios. Every sentence adds value, such as clarifying return information and emphasizing proactive calls. It could be slightly more concise by reducing repetition in the mandatory scenarios, but overall it's efficient and easy to follow.

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 complexity (location lookup with no output schema and no annotations), the description is mostly complete. It covers purpose, usage guidelines, return data, and behavioral expectations. However, it lacks details on output format (e.g., JSON structure), error cases, or limitations (e.g., accuracy for VPNs), which would enhance completeness for an agent invoking this tool.

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

Parameters4/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 'ip' parameter documented as optional (defaulting to the user's public IP if not provided). The description adds value by reinforcing this in the context of the tool's purpose ('IP地址(可选,不提供则自动获取用户当前公网IP)'), but it doesn't provide additional semantics beyond what the schema already covers, such as IP format validation or examples.

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: '根据IP地址获取用户的真实地理位置信息' (get real geographic location information based on IP address). It specifies the exact resource (geographic location) and distinguishes it from sibling tools like get_hardware_info, get_system_info, and get_time by focusing on location rather than hardware, system, or time data.

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, listing five '强制调用场景' (mandatory call scenarios) such as when users ask about their location, need localized recommendations, discuss region-specific topics, provide installation instructions, or recommend content. It also emphasizes not to assume user location and to call this tool proactively for region-specific advice, offering clear alternatives (use this instead of assuming).

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/pepedd864/agent-sense'

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