Skip to content

Add ip2geo IP geolocation tool#6258

Open
bfzli wants to merge 1 commit intoFlowiseAI:mainfrom
bfzli:add-ip2geo-tool
Open

Add ip2geo IP geolocation tool#6258
bfzli wants to merge 1 commit intoFlowiseAI:mainfrom
bfzli:add-ip2geo-tool

Conversation

@bfzli
Copy link
Copy Markdown

@bfzli bfzli commented Apr 21, 2026

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

  • Input: IPv4 or IPv6 address
  • Output: city, country, coordinates, timezone, ASN, currency, continent, flag

Files

  • New: packages/components/credentials/Ip2GeoApi.credential.ts — API key credential
  • New: packages/components/nodes/tools/Ip2Geo/Ip2Geo.ts — tool node using DynamicStructuredTool
  • New: packages/components/nodes/tools/Ip2Geo/ip2geo.svg — icon

Test plan

  • Live API: returns correct data (Los Angeles, US, 34.0544, -118.244)
  • Bad API key: returns success: false
  • All files valid
  • Follows CurrentDateTime/DynamicStructuredTool pattern

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
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +6 to +22
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;
`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
  1. Use a default (fallback) implementation unless the specific implementation has meaningfully different behavior or provides better error messages.

Comment on lines +85 to +87
const dynamicStructuredTool = new DynamicStructuredTool(obj)

return dynamicStructuredTool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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 dynamicStructuredTool
References
  1. 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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.'

Suggested change
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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant