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; }

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