All articles
mcpclaude-codetutorialagents

Debug Failed Webhooks From Claude Code With KestrelMQ's MCP Server

Connect Claude Code or Cursor to KestrelMQ's built-in MCP server with one command, then send test events, inspect failed deliveries and replay them without leaving your editor. Includes real tool responses.

KestrelMQ Engineering5 min read

Debugging a failed webhook usually means five tabs: dashboard, logs, curl, your handler, back to the dashboard. KestrelMQ ships a Model Context Protocol (MCP) server inside its API gateway, so Claude Code can read the failed delivery, read your handler and replay the fix in the same session.

Connect in one command

Hosted (KestrelMQ Cloud):

terminal
claude mcp add --transport http kestrelmq https://api.kestrelmq.dev/mcp \
  --header "Authorization: Bearer $KESTRELMQ_API_KEY"

Self-hosted (Docker quickstart):

terminal
claude mcp add --transport http kestrelmq http://localhost:3000/mcp \
  --header "Authorization: Bearer $KESTRELMQ_API_KEY"

KESTRELMQ_API_KEY is a workspace API key (kmq_live_...). Prefer a project-scoped .mcp.json so the whole team gets the same setup; Claude Code expands ${KESTRELMQ_API_KEY} from your environment, so the key never lands in the repository:

.mcp.json
{
  "mcpServers": {
    "kestrelmq": {
      "type": "http",
      "url": "https://api.kestrelmq.dev/mcp",
      "headers": {
        "Authorization": "Bearer ${KESTRELMQ_API_KEY}"
      }
    }
  }
}

Cursor uses a different interpolation syntax. Put this in .cursor/mcp.json:

.cursor/mcp.json
{
  "mcpServers": {
    "kestrelmq": {
      "url": "https://api.kestrelmq.dev/mcp",
      "headers": {
        "Authorization": "Bearer ${env:KESTRELMQ_API_KEY}"
      }
    }
  }
}

Sanity-check with a JSON-RPC tools/list call (swap in http://localhost:3000 when self-hosting), then run /mcp in Claude Code; kestrelmq should show as connected:

terminal
curl -s -X POST https://api.kestrelmq.dev/mcp \
  -H "Authorization: Bearer ${KESTRELMQ_API_KEY}" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

The server is stateless Streamable HTTP, so it needs no session affinity behind a load balancer.

MCP calls count toward your rate limit

Every request to /mcp counts against the workspace rate limit, the same quota as POST /v1/events. Keep agent loops bounded. When the quota is exhausted you get 429 with a Retry-After header.

The six tools

ToolArgumentsWhat it does
send_eventevent, payload, recipient?, idempotencyKey?, deliverAt?Validates against the event schema, fans out by routing rules, returns eventId and deliveryIds
list_deliverieslimit?, cursor?, status?, eventName?, integrationId?Newest-first deliveries with keyset pagination
inspect_deliverydeliveryIdDelivery plus event, integration, routing rule and every attempt, secrets masked
replay_deliverydeliveryIdResets to PENDING and re-enqueues with a fresh retry budget; meant for FAILED deliveries
get_analytics_summarywindow? (24h, 7d, 30d)Totals, status counts, success rate, avg and p95 duration
toggle_inbound_sourcesourceId, action (pause, resume)Buffers inbound webhooks as PAUSED, or drains them

Two resources let the agent learn your contracts before it sends anything: kestrelmq://schemas (event names, validation mode, JSON Schemas) and kestrelmq://templates (placeholders and the routes that use them). Every tool uses a strict schema, so unknown arguments are rejected, and none accepts a workspaceId.

A real debugging session

Paste this prompt into Claude Code:

Read kestrelmq://schemas, then list my FAILED deliveries from the last day. Inspect the newest one, find the cause, check my handler in src/webhooks/orders.ts and propose a fix. Do not replay anything yet.

1. list_deliveries finds the failure.

tool call · list_deliveries
{ "name": "list_deliveries", "arguments": { "status": "FAILED", "limit": 5 } }

2. inspect_delivery shows why. The response carries the whole attempt timeline (abridged):

tool response · inspect_delivery
{
  "id": "9bafef5c-41d2-4e89-9a0b-3c14d78e02f1",
  "status": "FAILED",
  "attemptCount": 1,
  "maxAttempts": 5,
  "nextRetryAt": null,
  "event": { "eventName": "order.paid", "payload": { "orderId": "ord_9001", "amount": 149.99 } },
  "integration": { "name": "Order Fulfillment Webhook", "provider": "CUSTOM_WEBHOOK" },
  "attempts": [
    {
      "attemptNumber": 1,
      "responseStatus": 422,
      "responseBody": "{\"error\":\"currency is required\"}",
      "durationMs": 184
    }
  ]
}

A fatal 422 (any 4xx except 429 is not retried) plus your handler's code is enough for the agent to spot the missing currency field. It edits the handler or the event payload.

3. send_event tests the fix with an idempotency key, so an agent retry never fans out duplicates:

tool call · send_event
{
  "name": "send_event",
  "arguments": {
    "event": "order.paid",
    "payload": { "orderId": "ord_9001", "amount": 149.99, "currency": "USD" },
    "idempotencyKey": "mcp-test-ord_9001"
  }
}

4. replay_delivery closes the loop for the original failure. It gives the delivery a fresh retry budget and a new job:

tool response · replay_delivery
{
  "id": "9bafef5c-41d2-4e89-9a0b-3c14d78e02f1",
  "status": "PENDING",
  "attemptCount": 1,
  "maxAttempts": 5,
  "nextRetryAt": null,
  "replayed": true,
  "jobId": "9bafef5c-41d2-4e89-9a0b-3c14d78e02f1-replay-0b8d6c1e-7b53-4f0e-9d2a-5a1c3e7f9b42"
}

replay_delivery is intended for FAILED deliveries after the cause is fixed. Confirm recovery with get_analytics_summary (window: "24h") and watch successRate.

Security model

  • The workspace comes from the API key hash, never from tool arguments, and another workspace's IDs return not found.
  • Secrets and PII in delivery records are masked before they reach the model.
  • Tools only enqueue work. The worker, not the MCP server, performs every outbound call.
  • Use a separate key for agents so you can revoke it independently, and review replay_delivery and toggle_inbound_source calls before approving them on production.

Next step

Create a workspace API key, run the one-line claude mcp add, and paste the debugging prompt above. The full reference is in the MCP server docs; to see what happens after send_event, read how at-least-once delivery works. No instance yet? Follow the Docker quickstart.

FAQ

How does Claude Code authenticate to the KestrelMQ MCP server?

With a workspace API key (kmq_live_...) sent as an Authorization Bearer header or as X-API-Key. The workspace is derived from the key, never from tool arguments, so an agent cannot reach another tenant's data.

Which MCP tools does KestrelMQ expose?

Six tools with strict Zod schemas (send_event, list_deliveries, inspect_delivery, replay_delivery, get_analytics_summary and toggle_inbound_source) plus the resources kestrelmq://schemas and kestrelmq://templates.

Does it work with Cursor?

Yes. Add the server to .cursor/mcp.json with the header Authorization set to Bearer ${env:KESTRELMQ_API_KEY}. Cursor uses the ${env:NAME} interpolation syntax, which differs from Claude Code's ${NAME}.

Do MCP calls count toward my rate limit?

Yes. Every request to /mcp counts toward the workspace rate limit, the same quota that applies to POST /v1/events, so cap agent loops. Exceeding it returns 429 with a Retry-After header.

Is it safe to give an agent access to production webhooks?

Use a dedicated API key and prefer a staging workspace. Secrets are masked in tool output, and every call is scoped to the key's workspace. Treat replay_delivery and toggle_inbound_source as the actions worth reviewing before approving.

Run guaranteed webhook delivery on your own infrastructure

KestrelMQ is MIT-licensed and boots with a single Docker Compose file. Follow the quickstart or start in the hosted dashboard.