Skip to main content
Glama

Health Check

ping
Read-onlyIdempotent

Verifies Claude CLI installation and authentication, reporting versions, capabilities, and configuration. Local-only health check.

Instructions

Health check: verifies Claude CLI is installed and authenticated, reports versions, capabilities, and configuration. No cost (local check only).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function executePing() that performs the health check by detecting the Claude CLI binary, checking authentication, reading config, and returning a PingResult with server/cli state.
    export async function executePing(): Promise<PingResult> {
      const binary = findClaudeBinary();
      const maxConcurrent = getMaxConcurrent();
      const activeCount = getActiveCount();
      const queueDepth = getQueueDepth();
    
      let cliFound = false;
      let version: string | null = null;
    
      try {
        version = execFileSync(binary, ["--version"], {
          encoding: "utf8",
          timeout: 10_000,
        }).trim();
        cliFound = true;
      } catch (e) {
        const err = e as NodeJS.ErrnoException;
        if (err.code === "ENOENT") {
          return {
            cliFound: false,
            version: null,
            authMethod: "none",
            subscriptionType: null,
            defaultModel: getDefaultModel("query"),
            fallbackModel: getFallbackModel() ?? null,
            serverVersion: PKG_VERSION,
            nodeVersion: process.version,
            maxConcurrent,
            activeCount,
            queueDepth,
            capabilities: {
              bareMode: false,
              jsonOutput: false,
              jsonSchema: false,
              sessionResume: false,
            },
          };
        }
        // Non-ENOENT errors (EACCES, timeout, broken binary) mean the CLI exists
        // but is not usable. Report cliFound: false with a diagnostic message.
        return {
          cliFound: false,
          version: `error: ${err.message ?? String(e)}`,
          authMethod: "none",
          subscriptionType: null,
          defaultModel: getDefaultModel("query"),
          fallbackModel: getFallbackModel() ?? null,
          serverVersion: PKG_VERSION,
          nodeVersion: process.version,
          maxConcurrent,
          activeCount,
          queueDepth,
          capabilities: {
            bareMode: false,
            jsonOutput: false,
            jsonSchema: false,
            sessionResume: false,
          },
        };
      }
    
      const auth = detectAuth();
      return {
        cliFound,
        version,
        authMethod: auth.method,
        subscriptionType: auth.subscriptionType,
        defaultModel: getDefaultModel("query"),
        fallbackModel: getFallbackModel() ?? null,
        serverVersion: PKG_VERSION,
        nodeVersion: process.version,
        maxConcurrent,
        activeCount,
        queueDepth,
        capabilities: {
          bareMode: true,
          jsonOutput: true,
          jsonSchema: true,
          sessionResume: true,
        },
      };
    }
  • The PingResult interface defining the full shape of the ping tool's output (cliFound, version, authMethod, capabilities, etc.).
    export interface PingResult {
      cliFound: boolean;
      version: string | null;
      authMethod: "api-key" | "subscription" | "none";
      subscriptionType: string | null;
      defaultModel: string | null;
      fallbackModel: string | null;
      serverVersion: string;
      nodeVersion: string;
      maxConcurrent: number;
      activeCount: number;
      queueDepth: number;
      capabilities: {
        bareMode: boolean;
        jsonOutput: boolean;
        jsonSchema: boolean;
        sessionResume: boolean;
      };
    }
  • src/index.ts:314-356 (registration)
    Registration of the 'ping' tool on the MCP server via server.registerTool, including inputSchema (empty), annotations, and the async callback that calls executePing() and formats the response.
    // --- ping tool ---
    
    server.registerTool(
      "ping",
      {
        title: "Health Check",
        description: pingDescription,
        inputSchema: {},
        annotations: pingAnnotations,
      },
      async () => {
        const start = Date.now();
        try {
          const result = await executePing();
          const lines = [
            `cliFound: ${result.cliFound}`,
            `version: ${result.version ?? "unknown"}`,
            `authMethod: ${result.authMethod}`,
            ...(result.subscriptionType ? [`subscriptionType: ${result.subscriptionType}`] : []),
            `defaultModel: ${result.defaultModel ?? "none"}`,
            `fallbackModel: ${result.fallbackModel ?? "none"}`,
            `serverVersion: ${result.serverVersion}`,
            `nodeVersion: ${result.nodeVersion}`,
            `maxConcurrent: ${result.maxConcurrent}`,
            `activeCount: ${result.activeCount}`,
            `queueDepth: ${result.queueDepth}`,
            `capabilities: bareMode=${result.capabilities.bareMode}, jsonOutput=${result.capabilities.jsonOutput}, jsonSchema=${result.capabilities.jsonSchema}, sessionResume=${result.capabilities.sessionResume}`,
          ];
    
          return {
            content: [{ type: "text" as const, text: lines.join("\n") }],
            _meta: buildMeta({ durationMs: Date.now() - start }),
          };
        } catch (e) {
          console.error("[ping]", e);
          return {
            content: [{ type: "text" as const, text: `Error: ${getErrorMessage(e)}` }],
            isError: true,
            _meta: buildMeta({ durationMs: Date.now() - start }),
          };
        }
      },
    );
  • Helper function detectAuth() that checks for ANTHROPIC_API_KEY env var or reads credentials file to determine auth method.
    function detectAuth(): { method: PingResult["authMethod"]; subscriptionType: string | null } {
      const env = buildSubprocessEnv();
      if (env["ANTHROPIC_API_KEY"]) {
        return { method: "api-key", subscriptionType: null };
      }
    
      const configDir = process.env["CLAUDE_CONFIG_DIR"]
        ?? join(process.env["HOME"] ?? "", ".claude");
      try {
        const raw = readFileSync(join(configDir, ".credentials.json"), "utf8");
        const creds = JSON.parse(raw) as CredentialsFile;
        const oauth = creds.claudeAiOauth;
        if (oauth?.expiresAt && oauth.expiresAt > Date.now()) {
          return { method: "subscription", subscriptionType: oauth.subscriptionType ?? null };
        }
      } catch {
        // No credentials file or unreadable
      }
    
      return { method: "none", subscriptionType: null };
    }
  • ToolName type definition includes 'ping', and the DEFAULT_MODELS map assigns 'haiku' as the default model for ping.
    export type ToolName = "query" | "structured" | "search" | "ping";
    
    const DEFAULT_MODELS: Record<ToolName, string> = {
      query: "sonnet",
      structured: "sonnet",
      search: "sonnet",
      ping: "haiku",
    };
Behavior4/5

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

Annotations already indicate read-only and idempotent. Description adds that it's local only and costless, providing extra behavioral context beyond annotations without contradiction.

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?

Two concise sentences that front-load the purpose and include all necessary details without waste.

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

Completeness5/5

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

For a tool with no parameters, rich annotations, and no output schema, the description fully covers purpose, scope, and cost, making it complete for agent use.

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

Parameters4/5

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

No parameters exist, so schema coverage is 100%. Baseline for zero parameters is 4, and no additional parameter info needed.

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?

Description clearly states the tool performs a health check for Claude CLI, verifying installation, authentication, and reporting versions, capabilities, configuration. It is specific and distinguishes itself from sibling tools that handle data retrieval.

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?

Explicitly notes 'No cost (local check only)', implying when to use (verify setup) and when not (no remote calls). While it doesn't explicitly compare to siblings, the purpose is distinct enough.

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/hampsterx/claude-mcp-bridge'

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