MCP · Source: mqlite main · docs/mcp.md — source v0.4.3 with unreleased changes. Latest supported release: v0.4.3. These docs track main; use the linked release for published artifacts.

MCP server (mqlite-mcp)

mqlite-mcp is a Model Context Protocol server that exposes the mqlite broker as agent tools — so an AI agent (Claude, etc.) can observe broker health, create queues, send, receive, settle messages, and manage access keys without writing any HTTP. It is a thin, dependency-free forwarder: it speaks MCP (JSON-RPC 2.0 over stdio) and turns each tool call into one HTTP POST to the broker. Stdlib + the in-repo wire contract only — no MCP SDK, no CGO (the same ethos as the rest of mqlite).

Build & run

make build           # → bin/mqlite-mcp  (also: go build ./cmd/mqlite-mcp)

It's a stdio server: an MCP host launches it and talks over stdin/stdout. Configure it with the broker endpoint + token:

Env Default Meaning
MQLITE_ENDPOINT http://127.0.0.1:6754 the broker base URL
MQLITE_TOKEN — configured administrator, monitor credential, or managed broker access key; tool calls follow its permissions

Connect an agent host

Most MCP hosts take a JSON server entry. For example:

{
  "mcpServers": {
    "mqlite": {
      "command": "/path/to/bin/mqlite-mcp",
      "env": {
        "MQLITE_ENDPOINT": "https://your-mqlite.fly.dev",
        "MQLITE_TOKEN": "mqk_prod_xxx"
      }
    }
  }
}

The agent then sees the tools below and can drive the broker directly.

Tools

Minimal — selected core routes map 1:1 (kept small on purpose — over-specified tools make models misuse them):

Permissions follow the HTTP API: producers use send, consumers and subscription provisioners use listen, and broker-wide inventory, lifecycle and key management use manage. observe also accepts a configured monitor credential.

Tool Does
observe complete canonical observation; takes no arguments; requires monitor or manage
list_queues list queues/subscriptions
create_queue create/update a queue by name
delete_queue delete a plain queue; optional force explicitly discards retained work
subscribe create a topic subscription or update its filter (listen); optional ttl_ms sets a fixed lifetime
list_subscriptions page subscriptions by topic, with total/count and optional deleting entries (manage)
delete_subscription delete one exact topic/subscription pair (manage); optional force discards retained work
send send a message (queue, body, optional message_id/group_id)
receive peek-lock messages → returns seq_number + lock_token
complete acknowledge a message (queue, seq_number, lock_token)
abandon end this delivery attempt; retry now/later below the limit, otherwise dead-letter
reject dead-letter a message
renew extend the same live delivery lock without increasing delivery_count; cannot revive an expired lock
defer set a message aside for later retrieval by seq_number
receive_deferred retrieve deferred messages by their seq_numbers
peek browse without locking (optionally by state)
stats queue counters by state
redrive move dead letters back to active
purge permanently delete dead letters
create_key create a managed key (id, name, permissions, optional expires_at_ms); returns the token once
list_keys list public key metadata, including revoked/expired keys (after_id, limit, sort)
revoke_key revoke a managed key by public id; repeated revocation is safe

Settlement is by lock_token from receive — delivery is at-least-once, so an agent should treat handlers as idempotent. Full HTTP semantics: api-reference.md.

Queue deletion

delete_queue takes {"name":"orders"} for empty-only deletion or {"name":"orders","force":true} to authorize permanent discard of every message state. Do not infer force from a prior observation. Locked work may already have caused an external side effect that deletion cannot undo.

The result is {"deleted":true,"state":"deleted"} when physical removal finishes in the call, or {"deleted":false,"state":"deleting"} after durable retirement while bounded background cleanup continues. In the latter state, data-plane calls fail, list_queues keeps the row with state:"deleting", and the name cannot be reused. The original discard authorization is already durable and background cleanup needs no follow-up write. Serialize deletion and same-name recreation; use list_queues as the read-only status check and wait until it no longer contains the name before creating a replacement. Treat a transport failure, redirect, any HTTP 5xx response (including one generated by a gateway), or malformed success response as an unknown outcome. Keep the name reserved and reconcile through list_queues; never automatically replay delete_queue. Configure intermediaries not to retry lifecycle-delete routes.

Subscription lifecycle

delete_subscription takes topic, name, and optional force. Empty-only is the default. An accepted delete removes the subscription from fan-out immediately and returns the same deleted / deleting result as queue deletion. The exact topic/name pair is required even though subscription names are globally unique. Both deletion modes require manage; force changes the non-empty precondition, not the permission.

Use list_subscriptions for bounded inventory and reconciliation. Its optional arguments are topic, after, limit (default 100, maximum 1,000), and include_deleting; the result carries subscriptions, total, and next_after. A cursor is opaque and tied to the topic/deleting scope. Null, incomplete, out-of-order, out-of-scope, or inconsistent successful pages are rejected and cannot establish that a deleted name is absent. If a destructive call receives a redirect, transport failure, any HTTP 5xx, or malformed success response, do not replay it. Keep ownership of the one-use subscription name and query with include_deleting:true until the old mapping is absent.

The default capacity is 10,000 active plus deleting subscriptions. That value is a metadata safety ceiling. Publish work and stored copies still grow with the number of matching subscriptions, so an agent should not create a subscription per request at high rates; use a stable reply subscription and dispatch by correlation_id.

subscribe accepts an optional positive integer ttl_ms. On first creation, it sets a fixed lifetime measured from that creation time. Omit ttl_ms to create a permanent subscription or preserve an existing subscription's lifetime; the MCP tool rejects an explicit zero. Repeating the original positive TTL is idempotent; supplying a different positive TTL for the same subscription returns a conflict before changing its filter. Updates, retries, traffic, and receives never extend the deadline.

subscribe requires listen and is a broker-wide upsert: a caller can update the filter of any known existing (topic,name) pair. It does not grant inventory or deletion rights. A listen-only agent creating temporary subscriptions should always set ttl_ms; a manager performs any early retirement and reconciliation.

At the deadline, the broker makes the subscription unavailable and treats the TTL as advance authorization to discard its retained messages. Physical cleanup is bounded and asynchronous, so the name remains reserved until inventory with include_deleting:true no longer returns it. A later creation with the same name starts a new lifecycle; serialize deletion or expiry with same-name recreation. Each list item includes created_at_ms and expires_at_ms; zero expiry means the subscription is permanent. Prefer unique one-use names for genuinely temporary work. For high-rate request/reply traffic, prefer a stable reply subscription per service instance and route replies by correlation_id.

Read-only observation

The observe tool requires v0.3.2 or later of both mqlite-mcp and the broker. Configured monitor credentials also require a v0.3.2 or later broker.

Call observe with {} to get the same canonical JSON snapshot as the HTTP route, Go SDK and CLI: availability/freshness, queue gauges, process message effects, storage operations, maintenance, filters and HTTP measurements. The tool does not recompute counters. An unavailable queue collection remains explicit even when the HTTP request succeeds; inspect collection.state and runtime availability flags. Process counters reset when the broker restarts. See observability.md.

Use a credential configured in the broker's MQLITE_MONITOR_TOKENS as this process's MQLITE_TOKEN for a read-only monitoring agent. The tool inventory stays the same, but the broker permits only observe for this credential; other tool calls return permission_denied. Managed send/listen credentials cannot observe the whole broker, and monitor is not a managed-key permission.

Access key management

The three key tools require manage; both an environment administrator token and an active managed manage key may issue further administrator keys. send and listen keys receive permission_denied for these tools. The MCP server forwards MQLITE_TOKEN on every call, and broker authorization decides what it may do.

Before calling create_key, choose and retain a unique 32-character lowercase hexadecimal id. The id is public metadata, distinct from the secret token:

{
  "name": "create_key",
  "arguments": {
    "id": "e734810a9f634d75bd8a029c1f7e5062",
    "name": "order-producer",
    "permissions": ["send"]
  }
}

permissions accepts send, listen, their combination, or manage (which includes both). expires_at_ms is a future UTC epoch-millisecond timestamp; omit it or use zero for no expiry. The response has key metadata and a one-time token in the mqk_ + 64 lowercase hex format. Store the token securely; it will be visible in the successful MCP tool result and may be retained by your MCP host. List responses never contain secrets or token hashes.

Creation is not retried automatically. An error includes the retained valid public ID; after an uncertain result, use list_keys and revoke_key for that ID before issuing a replacement with a new ID. Reusing an ID returns key_conflict and cannot recover a secret. Pass next_after_id from list_keys back as after_id until the cursor is absent; the default limit is 100, maximum 1000. The optional sort is id_asc (default) or created_desc (newest-created first, then descending public ID for timestamp ties). Keep the same sort on every page. Creation-order cursors must identify an existing key, including revoked or expired keys. The default ID order also accepts absent predecessor IDs when reconciling a lost create response. Environment tokens are not listed or revocable through these tools. Key tools are unavailable when broker authentication is explicitly disabled.