Skip to main content
Glama

ping

Test network connectivity to a host by sending ICMP echo requests and receiving response data.

Instructions

Pings a host and returns the result

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesThe hostname or URL to ping (e.g., 'google.com' or 'https://google.com')

Implementation Reference

  • The handler function that executes the ping logic: extracts hostname from URL if provided, runs platform-specific ping command using execAsync (promisified child_process.exec), parses output, and returns success or error messages.
    execute: async (args) => { try { // Extract hostname from URL if needed let hostname = args.host; // If it's a full URL, extract the hostname if (hostname.startsWith("http://") || hostname.startsWith("https://")) { const url = new URL(hostname); hostname = url.hostname; } // Execute ping command (platform-specific) const isWindows = process.platform === "win32"; const pingCommand = isWindows ? `ping -n 4 ${hostname}` : `ping -c 4 ${hostname}`; const { stderr, stdout } = await execAsync(pingCommand); if (stderr) { return `Failed to ping ${hostname}:\n${stderr}`; } return `Ping results for ${hostname}:\n\n${stdout}`; } catch (error) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return `Failed to ping ${args.host}:\n${errorMessage}`; }
  • Zod schema defining the single input parameter 'host' as a string, with a description allowing hostname or full URL.
    parameters: z.object({ host: z .string() .describe( "The hostname or URL to ping (e.g., 'google.com' or 'https://google.com')", ), }),
  • Registration of the 'ping' tool using FastMCP's server.addTool method, including name, description, annotations (title 'Ping'), execute handler, and parameters schema.
    server.addTool({ annotations: { openWorldHint: false, readOnlyHint: true, title: "Ping", }, description: "Pings a host and returns the result", execute: async (args) => { try { // Extract hostname from URL if needed let hostname = args.host; // If it's a full URL, extract the hostname if (hostname.startsWith("http://") || hostname.startsWith("https://")) { const url = new URL(hostname); hostname = url.hostname; } // Execute ping command (platform-specific) const isWindows = process.platform === "win32"; const pingCommand = isWindows ? `ping -n 4 ${hostname}` : `ping -c 4 ${hostname}`; const { stderr, stdout } = await execAsync(pingCommand); if (stderr) { return `Failed to ping ${hostname}:\n${stderr}`; } return `Ping results for ${hostname}:\n\n${stdout}`; } catch (error) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return `Failed to ping ${args.host}:\n${errorMessage}`; } }, name: "ping", parameters: z.object({ host: z .string() .describe( "The hostname or URL to ping (e.g., 'google.com' or 'https://google.com')", ), }), });

Other Tools

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/punkpeye/mcp-ping'

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