get_ip_location
Find the geographic location of any IP address to identify where internet traffic originates and enhance location-based services.
Instructions
Get the location of an IP address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ipAddress | No | The IP address to get the location of. |
Implementation Reference
- src/ipfind.ts:32-36 (handler)The core handler method in the APIRequest class that fetches the IP location from the IPFind API using the provided IP address and API key.async getIPLocation(ip: string): Promise<IPFindIPResponse> { return await this.makeRequest<IPFindIPResponse>( `/?auth=${this.apiKey}&ip=${ip}` ); }
- src/types.ts:2-19 (schema)Type definition for the response from the IPFind API, serving as the output schema for the tool.export type IPFindIPResponse = { ip_address: string; country: string | null; country_code: string | null; continent: string | null; continent_code: string | null; city: string | null; county: string | null; region: string | null; region_code: string | null; postal_code: string | null; timezone: string | null; owner: string | null; longitude: number; latitude: number; currency: string | null; languages: string[]; };
- src/index.ts:47-59 (registration)Tool registration in the listTools handler, including name, description, and input schema.{ name: "get_ip_location", description: "Get the location of an IP address", inputSchema: { type: "object", properties: { ipAddress: { type: "string", description: "The IP address to get the location of.", }, }, }, },
- src/index.ts:82-98 (registration)Dispatch logic in the callTool handler that invokes the getIPLocation method when the tool name matches.if (request.params.name === "get_ip_location") { const input = request.params.arguments as { ipAddress: string }; const output = await ipfind.apiRequest.getIPLocation(input.ipAddress); if (!output) { throw new Error("Failed to fetch IP location."); } return { content: [ { type: "text", text: JSON.stringify(output, null, 2), }, ], }; }
- src/ipfind.ts:11-30 (helper)Helper method used by getIPLocation to make the HTTP request to the IPFind API, handling headers, errors, and response parsing.async makeRequest<T = any>(path: string, options?: RequestInit): Promise<T> { options = Object.assign({}, options, { headers: Object.assign({}, options?.headers, { "user-agent": "IPFindMCPServer/0.1.0", }), }); const url = `https://api.ipfind.com${path}`; const res = await fetch(url, options); if (res.status >= 400) { throw await createIPFindError(res); } const contentType = res.headers.get("content-type"); const result = contentType?.includes("application/json") ? await res.json() : await res.text(); return result as T; }