Skip to main content
Glama
arjshiv

Local Utilities MCP Server

by arjshiv
public-ip.ts1.05 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import https from 'https'; /** * Fetches the public IP address using a public API * @returns Promise with the public IP address */ 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")); }); }); } 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 }] }; } ); }

Implementation Reference

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/arjshiv/localutils-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server