Skip to main content
Glama

Health Check

ping
Read-onlyIdempotent

Verify Claude CLI installation and authentication. Reports version, capabilities, and configuration details for local health check without cost.

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 core handler function that executes the ping tool logic: finds the Claude binary, runs '--version', detects authentication method, and returns a PingResult with version, auth, models, and capabilities.
    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 inline async handler passed to registerTool that calls executePing(), formats the result into text output, and handles errors.
    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 }),
        };
      }
    },
  • PingResult interface defining the shape of the tool's output including cliFound, version, authMethod, models, server version, queue stats, and capabilities.
    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:316-323 (registration)
    Registration of the 'ping' tool with server.registerTool(), including title, description (from descriptions.ts), inputSchema (empty object), and annotations (from annotations.ts).
    server.registerTool(
      "ping",
      {
        title: "Health Check",
        description: pingDescription,
        inputSchema: {},
        annotations: pingAnnotations,
      },
  • Helper function detectAuth() that checks for ANTHROPIC_API_KEY env var or reads ~/.claude/.credentials.json to determine the authentication 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 };
    }
Behavior5/5

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

The description provides behavioral context beyond the annotations by specifying that it is a local-only check with no cost. This adds detail about side effects and performance, which complements the readOnlyHint and idempotentHint already present.

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 extremely concise with two sentences that convey all necessary information without any redundancy. It is front-loaded with the main purpose.

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?

Given the tool's simplicity (no parameters, no output schema, and comprehensive annotations), the description provides all needed context: what the tool checks, that it is local and cost-free, and what information it reports.

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?

There are no parameters, and the schema coverage is 100% by default. The description does not need to elaborate on parameters, and the baseline for zero parameters is 4.

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 clearly states that this tool performs a health check, verifying Claude CLI installation and authentication, and reports versions, capabilities, and configuration. This distinguishes it from sibling tools like query and search, which are for 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?

The description indicates that the tool is a local check with no cost, implying it is safe and appropriate to use anytime. However, it does not explicitly state when not to use it or mention alternatives, but the simplicity of the tool makes this omission minor.

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