# Responds to ping requests

- **Pattern:** `ab-001839` (`mcp-server.transport-protocol.ping-support`)
- **Severity:** low
- **Lifecycle:** active
- **Last modified:** 2026-04-18
- **Canonical URL:** https://auditbuffet.com/patterns/ab-001839
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-001839)

## Why it matters

MCP clients send `ping` requests to verify a server is alive before timing out a connection or showing an error to the user. A server that returns `-32601 Method not found` on ping tells the client it is disconnected, triggering reconnection logic or user-visible errors even when the server is running fine. A server that returns a non-standard value (e.g., the string `"pong"` instead of an empty object `{}`) breaks clients that validate response shape. Ping is cheap to implement correctly and expensive to get wrong.

## Severity rationale

Low because a broken ping handler causes spurious connection errors and reconnection overhead but does not expose data or corrupt tool results.

## Remediation

The MCP SDK handles ping automatically — do not override it. For custom implementations, add a case for `ping` that returns an empty result object.

```ts
// src/transport/handler.ts — ping handler
if (message.method === 'ping') {
  return {
    jsonrpc: '2.0',
    id: message.id,
    result: {}  // empty object, not null, not 'pong'
  }
}
```

Verify the ping handler is working by sending `{ "jsonrpc": "2.0", "method": "ping", "id": 1 }` directly to your server and confirming the response is `{ "jsonrpc": "2.0", "id": 1, "result": {} }`.

## Detection

- **ID:** `ping-support`
- **Severity:** `low`
- **What to look for:** Enumerate whether the server handles ping requests and responds with a valid JSON-RPC response. Count ping handler implementations. The MCP spec defines a `ping` method that clients use to check if the server is alive. Check that the server handles `ping` requests and returns an empty result `{}`. For SDK-based servers, this is built in — verify it's not accidentally disabled or overridden. For custom implementations, check for a `ping` case in the message handler.
- **Pass criteria:** The server responds to `ping` requests with an empty result object `{}`. SDK-based servers get this automatically. At least 1 ping handler must respond within 100ms.
- **Fail criteria:** Custom server does not handle `ping` (returns method-not-found), or SDK server has ping handling accidentally overridden.
- **Skip (N/A) when:** All checks skip when no MCP server is detected.

- **Cross-reference:** For timeout handling, see `timeout-handling`.
- **Detail on fail:** `"Custom message handler has no case for 'ping' method — returns -32601 method not found. Clients will consider the server unresponsive"` or `"Ping handler returns 'pong' string instead of empty object {} — non-standard response"`
- **Remediation:** Ping is simple but important for client health checks:

  ```ts
  // Ping is handled automatically by the MCP SDK in src/index.ts
  // Verify with: { "jsonrpc": "2.0", "method": "ping", "id": 1 }
  ```

  ```ts
  // Custom implementation
  if (message.method === 'ping') {
    return { jsonrpc: '2.0', id: message.id, result: {} }
  }

  // SDK-based servers handle this automatically — just don't override it
  ```

---

## External references

- external mcp-spec-ping — https://modelcontextprotocol.io/docs/concepts/utilities#ping

Taxons: inference-contract, error-resilience

HTML version: https://auditbuffet.com/patterns/ab-001839
