get_public_ip
Retrieve the public IP address of the machine hosting the MCP server for network configuration and connectivity verification.
Instructions
Returns the public IP address of the machine running the MCP server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp/public-ip.ts:29-37 (handler)The asynchronous handler function for the 'get_public_ip' tool. It fetches the public IP using the helper function and returns it in MCP text content format.async () => { const publicIp = await getPublicIp(); return { content: [{ type: "text", text: publicIp }] }; }
- src/mcp/public-ip.ts:8-23 (helper)Core helper function that fetches the machine's public IP address via HTTPS request to api.ipify.org.export async function getPublicIp(): Promise<string> { return new Promise((resolve, reject) => { https.get('https://api.ipify.org', (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { resolve(data.trim()); }); }).on('error', (err) => { console.error("Error fetching public IP from api.ipify.org:", err); reject(new Error("Failed to fetch public IP address")); }); }); }
- src/mcp/public-ip.ts:25-39 (registration)Function that registers the 'get_public_ip' tool on the MCP server by calling server.tool with name, description, and handler.export function registerPublicIpTool(server: McpServer): void { server.tool( "get_public_ip", "Returns the public IP address of the machine running the MCP server.", async () => { const publicIp = await getPublicIp(); return { content: [{ type: "text", text: publicIp }] }; } ); }
- src/index.ts:20-20 (registration)Top-level call to registerPublicIpTool during server setup, which registers the get_public_ip tool.registerPublicIpTool(server);