Skip to main content
Glama

ping

Read-only

Check host reachability by sending a network probe to a specified hostname or URL and returning the response result.

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 execute handler for the 'ping' tool. Extracts hostname from URL if needed, then runs platform-specific ping command (ping -n 4 on Windows, ping -c 4 on Unix) 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}`;
      }
    },
  • Zod schema defining the input parameter: a required 'host' string that accepts hostnames or URLs.
    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 with the FastMCP server, including its annotations (openWorldHint: false, readOnlyHint: true), description, name, parameters schema, and execute handler.
    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')",
          ),
      }),
    });
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations declare readOnlyHint=true, which the description does not contradict. However, the description adds no further behavioral insights (e.g., timeout, protocol used). The minimalism is acceptable given the simplicity and annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that front-loads the action and result. Every word is necessary, and there is no extraneous information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple (1 param, no output schema, no siblings). The description covers the core purpose and input sufficiently. A minor improvement could mention the return format, but it remains complete for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema provides a detailed description for the 'host' parameter (100% coverage). The tool description adds no additional meaning beyond the schema, so baseline score of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Pings a host and returns the result' is a specific verb and resource combination that clearly states the tool's action and outcome. With no sibling tools, differentiation is unnecessary.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

While no explicit when-to-use or alternatives are provided, the description implicitly indicates it is a network diagnostic tool. For a simple tool with a single parameter and no siblings, this is adequate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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