maps_ip_location
Find geographic locations from IP addresses using AMap Maps API. Input an IP to get detailed positioning data for Chinese locations.
Instructions
IP 定位根据用户输入的 IP 地址,定位 IP 的所在位置
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes | IP地址 |
Implementation Reference
- build/index.js:338-370 (handler)Handler function that performs IP geolocation by querying the Amap API with the provided IP address and returns the province, city, adcode, and rectangle.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)Tool schema definition including name, description, and input schema requiring an 'ip' string 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)Dispatch case in the CallToolRequestSchema handler that extracts 'ip' argument and calls handleIPLocation.case "maps_ip_location": { const { ip } = request.params.arguments; return await handleIPLocation(ip); }
- build/index.js:247-260 (registration)MAPS_TOOLS array registration including IP_LOCATION_TOOL, returned by ListToolsRequestSchema handler.const MAPS_TOOLS = [ REGEOCODE_TOOL, GEO_TOOL, IP_LOCATION_TOOL, WEATHER_TOOL, SEARCH_DETAIL_TOOL, BICYCLING_TOOL, WALKING_TOOL, DRIVING_TOOl, TRANSIT_INTEGRATED_TOOL, DISTANCE_TOOL, TEXT_SEARCH_TOOL, AROUND_SEARCH_TOOL, ];