maps_ip_location
Locate the geographic position of any IP address to determine its physical location for location-based services and geographic analysis.
Instructions
IP 定位根据用户输入的 IP 地址,定位 IP 的所在位置
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes | IP地址 |
Implementation Reference
- build/index.js:338-370 (handler)The handler function that executes the maps_ip_location tool logic. It fetches the IP location from Amap API using the provided IP, handles errors, and returns formatted JSON response.async function handleIPLocation(ip) { const url = new URL("https://restapi.amap.com/v3/ip"); url.searchParams.append("ip", ip); url.searchParams.append("key", AMAP_MAPS_API_KEY); url.searchParams.append("source", "ts_mcp"); const response = await fetch(url.toString()); const data = await response.json(); if (data.status !== "1") { return { content: [{ type: "text", text: `IP Location failed: ${data.info || data.infocode}`, }], isError: true, }; } return { content: [{ type: "text", text: JSON.stringify( { province: data.province, city: data.city, adcode: data.adcode, rectangle: data.rectangle, }, null, 2, ), }], isError: false, }; }
- build/index.js:51-64 (schema)The input schema definition for the maps_ip_location tool, defining the expected 'ip' parameter.const IP_LOCATION_TOOL = { name: "maps_ip_location", description: "IP 定位根据用户输入的 IP 地址,定位 IP 的所在位置", inputSchema: { type: "object", properties: { ip: { type: "string", description: "IP地址", }, }, required: ["ip"], }, };
- build/index.js:862-865 (registration)The switch case in the CallToolRequestHandler that registers and dispatches to the handleIPLocation function for the tool.case "maps_ip_location": { const { ip } = request.params.arguments; return await handleIPLocation(ip); }
- build/index.js:247-250 (registration)The tools array registration where IP_LOCATION_TOOL is included for list tools request.const MAPS_TOOLS = [ REGEOCODE_TOOL, GEO_TOOL, IP_LOCATION_TOOL,
- build/streamable-http.js:933-936 (handler)Duplicate handler dispatch case in the streamable HTTP server version.case "maps_ip_location": { const { ip } = request.params.arguments; return await handleIPLocation(ip); }