Conversation
Add a new tool node for ip2geo.dev IP geolocation API. - Credential: ip2GeoApi (API key) - Tool node: Ip2Geo (converts IP to geolocation data) - Returns city, country, coordinates, timezone, ASN, currency - Uses DynamicStructuredTool pattern - SVG icon included
There was a problem hiding this comment.
Code Review
This pull request introduces a new Ip2Geo tool and its associated credentials, allowing users to perform geolocation lookups for IP addresses via the ip2geo.dev API. The review feedback identifies several necessary improvements: replacing the global fetch API with axios to ensure security and consistency within the sandbox environment, explicitly calling setVariables on the DynamicStructuredTool instance to correctly authenticate API requests, and utilizing the user-provided IP address as a default value in the tool's schema.
| const code = ` | ||
| const url = 'https://api.ip2geo.dev/convert?ip=' + encodeURIComponent($ip_address); | ||
|
|
||
| const response = await fetch(url, { | ||
| headers: { | ||
| 'X-Api-Key': $vars.apiKey, | ||
| }, | ||
| }); | ||
|
|
||
| const data = await response.json(); | ||
|
|
||
| if (!data.success) { | ||
| return { error: data.message || 'Request failed' }; | ||
| } | ||
|
|
||
| return data.data; | ||
| ` |
There was a problem hiding this comment.
The sandbox code uses the global fetch API, which may not be available or consistently implemented across all execution environments (e.g., NodeVM vs E2B). Additionally, using axios is preferred in this repository as it is wrapped with security checks (like deny-list filtering) in the sandbox environment. Using axios also provides better error handling for non-2xx responses.
const code = "const axios = require('axios');\nconst url = 'https://api.ip2geo.dev/convert?ip=' + encodeURIComponent($ip_address);\ntry {\n const response = await axios.get(url, { headers: { 'X-Api-Key': $vars.apiKey } });\n return response.data.success ? response.data.data : { error: response.data.message || 'Request failed' };\n} catch (error) {\n return { error: error.response?.data?.message || error.message || 'Request failed' };\n}"References
- Use a default (fallback) implementation unless the specific implementation has meaningfully different behavior or provides better error messages.
| const dynamicStructuredTool = new DynamicStructuredTool(obj) | ||
|
|
||
| return dynamicStructuredTool |
There was a problem hiding this comment.
The variables property passed to the DynamicStructuredTool constructor is not automatically assigned to the instance (as seen in the core.ts implementation). You must explicitly call setVariables to ensure that $vars.apiKey is available within the sandbox code. Without this, the tool will fail to authenticate with the API.
const dynamicStructuredTool = new DynamicStructuredTool(obj)
dynamicStructuredTool.setVariables(obj.variables)
return dynamicStructuredToolReferences
- Maintain consistency with existing code patterns, even if they are not considered best practice.
| description: | ||
| 'Look up geolocation data for an IP address. Returns city, country, coordinates, timezone, ASN, and currency. Input should be an IPv4 or IPv6 address.', | ||
| schema: z.object({ | ||
| ip_address: z.string().describe('The IPv4 or IPv6 address to look up') |
There was a problem hiding this comment.
The ipAddress input from the node UI (captured in defaultIp on line 66) is currently unused. To allow users to provide a default IP address or hardcode one while still allowing the LLM to override it, you can use the .default() method in the Zod schema. This aligns with the input description 'Leave empty to let the LLM provide it.'
| ip_address: z.string().describe('The IPv4 or IPv6 address to look up') | |
| ip_address: z.string().default(defaultIp || '').describe('The IPv4 or IPv6 address to look up') |
Summary
Adds a new tool node for ip2geo — an IP geolocation API. Allows AI agents to look up geolocation data from IP addresses.
What it does
Files
packages/components/credentials/Ip2GeoApi.credential.ts— API key credentialpackages/components/nodes/tools/Ip2Geo/Ip2Geo.ts— tool node using DynamicStructuredToolpackages/components/nodes/tools/Ip2Geo/ip2geo.svg— iconTest plan
success: false