Docs / MCP Server

MCP Server

Connect Claude Code, Cursor, and autonomous ops agents to KestrelMQ over stateless Streamable HTTP (/mcp) with 6 strict Zod-validated tools and 2 workspace resources.

Updated 2026-11-28~5 min readMCP · Streamable HTTP

KestrelMQ mounts an official Model Context Protocol (MCP) server (@nestjs/mcp + @modelcontextprotocol/server v2) directly inside the HTTP API Gateway at /mcp (outside the /v1 prefix) over stateless Streamable HTTP. POST /mcp processes JSON-RPC calls, while stateful GET / DELETE stream requests return 405 Method Not Allowed.

API Key Guard & Multi-Tenant Isolation

Every request to /mcp passes ApiKeyGuard (Authorization: Bearer kmq_live_... or X-API-Key) and the workspace RateLimitGuard. workspaceId is derived strictly from the authenticated API key hash — never from tool arguments.

Connecting via .mcp.json

Add kestrelmq to .mcp.json (Claude Code) or .cursor/mcp.json (Cursor):

.mcp.json
{
  "mcpServers": {
    "kestrelmq": {
      "type": "http",
      "url": "http://localhost:3000/mcp",
      "headers": {
        "Authorization": "Bearer ${KESTRELMQ_API_KEY}"
      }
    }
  }
}

Verify connectivity from a shell with a JSON-RPC tools/list request:

terminal
curl -s -X POST http://localhost:3000/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"}'

Available Tools (6 · z.strictObject)

All 6 tools validate inputs with z.strictObject — unknown properties are rejected with a validation error:

Tool NameExact Input Schema (z.strictObject)Purpose
send_event{ event, payload, recipient?, idempotencyKey?, deliverAt? }Validate payload against event_schemas and enqueue outbound deliveries (deliverAt ISO-8601 with offset for SCHEDULED delay).
list_deliveries{ limit?, cursor?, status?, eventName?, integrationId? }Keyset-paginated workspace deliveries (limit 1–100, default 20; status in DeliveryStatus; integrationId UUID).
inspect_delivery{ deliveryId } (UUID)Fetch delivery with parent event, integration, routingRule, and attempts (all secrets masked via maskSensitiveData).
replay_delivery{ deliveryId } (UUID)Reset a FAILED delivery to PENDING (nextRetryAt: null) and enqueue a new BullMQ job with a fresh retry budget.
get_analytics_summary{ window?: "24h" | "7d" | "30d" }Workspace metrics (totalEvents, totalDeliveries, deliveriesByStatus, successRate, avgDurationMs, p95DurationMs), cached 60s.
toggle_inbound_source{ sourceId, action: "pause" | "resume" }Pause an inbound source (PAUSED buffering) or resume it ({ action, source, resumedDeliveriesCount }) draining at maxRatePerSec.

Example Agent Calls: Dispatch & Inspect

tool · send_event
{
  "name": "send_event",
  "arguments": {
    "event": "order.paid",
    "payload": {
      "orderId": "ord_9001",
      "amount": 149.99,
      "currency": "USD"
    },
    "recipient": {
      "email": "ava@acme.io"
    },
    "idempotencyKey": "mcp-test-ord_9001"
  }
}
tool · inspect_delivery
{
  "name": "inspect_delivery",
  "arguments": {
    "deliveryId": "9bafef5c-41d2-4e89-9a0b-3c14d78e02f1"
  }
}

Pausing & Resuming an Inbound Gateway (toggle_inbound_source)

tool · toggle_inbound_source
{
  "name": "toggle_inbound_source",
  "arguments": {
    "sourceId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "action": "resume"
  }
}

Available Resources (2)

AI agents should read kestrelmq://schemas and kestrelmq://templates before calling send_event so payload properties and template placeholders match workspace contracts:

Resource URIReturn TypeFields
kestrelmq://schemasMcpEventSchemaEntry[]eventName, validationMode ("DISABLED" | "WARN" | "STRICT"), variables (sorted dot-paths), jsonSchema.
kestrelmq://templatesMcpTemplateEntry[]id (UUID), name, subjectTemplate, variables (Handlebars placeholders), routes ({ ruleId, eventName, integrationId, channel, isActive }[]).
resource · kestrelmq://schemas
[
  {
    "eventName": "order.paid",
    "validationMode": "STRICT",
    "variables": [
      "amount",
      "currency",
      "customer.email",
      "orderId"
    ],
    "jsonSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "required": ["orderId", "amount", "currency"],
      "properties": {
        "orderId": { "type": "string" },
        "amount": { "type": "number" },
        "currency": { "type": "string" }
      }
    }
  }
]
resource · kestrelmq://templates
[
  {
    "id": "8f14e45f-ceea-467a-9a38-7b2c1d9e04f1",
    "name": "Order Receipt Email",
    "subjectTemplate": "Order {{orderId}} confirmed",
    "variables": ["amount", "currency", "orderId"],
    "routes": [
      {
        "ruleId": "1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed",
        "eventName": "order.*",
        "integrationId": "6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b",
        "channel": "EMAIL",
        "isActive": true
      }
    ]
  }
]