get_public_ip
Retrieve the public IP address of the machine hosting the MCP server. Use this utility to quickly identify the server's external IP for network configuration or troubleshooting.
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:26-38 (registration)Registers the get_public_ip tool using server.tool, including description and inline handler function.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/mcp/public-ip.ts:8-23 (helper)Helper function that fetches the public IP address from api.ipify.org using HTTPS.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/index.ts:20-20 (registration)Invokes the registerPublicIpTool function to register the get_public_ip tool on the MCP server.registerPublicIpTool(server);
- src/mcp/public-ip.ts:29-37 (handler)Inline handler function for the get_public_ip tool that calls the helper and returns formatted text response.async () => { const publicIp = await getPublicIp(); return { content: [{ type: "text", text: publicIp }] }; }