Metadata-Version: 2.4
Name: dlq-recovery-mcp
Version: 0.2.0
Summary: Read-only MCP inspection of failed jobs and dead-letter queues
License-Expression: MIT
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mcp<3,>=2.3
Requires-Dist: pydantic<3,>=2
Requires-Dist: redis<9,>=5
Requires-Dist: langchain-core<2,>=1.8.5
Requires-Dist: python-dotenv<2,>=1
Requires-Dist: httpx<1,>=0.28
Provides-Extra: sqs
Requires-Dist: boto3<2,>=1.40; extra == "sqs"
Provides-Extra: kafka
Requires-Dist: confluent-kafka<3,>=2.12; extra == "kafka"
Dynamic: license-file

# DLQ Recovery Inspector

<!-- mcp-name: io.github.nsunny2772/dlq-recovery-mcp -->

Inspect failed jobs and dead-letter queues from an MCP client. The server lists retained BullMQ and Sidekiq failures, reports RabbitMQ and Amazon SQS dead-letter queue counts, and reads Kafka Connect dead-letter record metadata. It runs locally and exposes read-only tools.

## Quickstart from PyPI

1. Install `uv` and confirm that Redis is reachable from the machine running your MCP client.
2. Add the entry below to your client's MCP configuration. Use your Redis URL and BullMQ queue name.
3. Reload the client and ask it to show the latest failed jobs.

On first use, the client runs `uvx` to download the published package from PyPI and start the server over stdio. Stdio is the default in the current source. The [package page](https://pypi.org/project/dlq-recovery-mcp/) lists published versions.

### BullMQ client configuration

```json
{
  "mcpServers": {
    "bullmq": {
      "command": "uvx",
      "args": ["dlq-recovery-mcp", "--transport", "stdio"],
      "env": {
        "DLQ_PROVIDER": "bullmq",
        "DLQ_REDIS_URL": "redis://127.0.0.1:6379/0",
        "DLQ_BULLMQ_QUEUE": "payments"
      }
    }
  }
}
```

### Upgrading from 0.1.x

Set `DLQ_PROVIDER=bullmq` in existing BullMQ configurations before using
0.2.0. Stdio is the default in 0.2.0. If you start an HTTP server separately,
include `--transport streamable-http` in its launch command.

## Run from source

Clone the repository to develop the server or try the queue adapters in the current checkout.

```bash
git clone https://github.com/nsunny2772/dlq-recovery-mcp.git
cd dlq-recovery-mcp
cp -n .env.example .env
uv sync --locked
```

Set `DLQ_PROVIDER` and the connection variables for your provider before startup.

For an MCP client that starts the server over stdio, set its command to `uv` and its arguments to `["--directory", "/absolute/path/to/dlq-recovery-mcp", "run", "--locked", "dlq-recovery-mcp", "--transport", "stdio"]`. Use the absolute path to your clone.

## Run a local Streamable HTTP server

```bash
uv run --locked dlq-recovery-mcp --transport streamable-http
```

Point your MCP client or MCP Inspector at `http://127.0.0.1:8080/mcp` using Streamable HTTP. You can also run `uvx dlq-recovery-mcp --transport streamable-http` with the Redis and queue settings supplied through your environment.

## List failed jobs

Try asking your MCP client: “Show me the latest failed jobs and summarize their failure reasons.”

Call `list_failed_jobs` with `{}` to start with up to 20 failures, newest first. Set `limit` to 1–100 to change the page size. Pass the response's `next_offset` as `offset` for the next page, and stop when it is null. Continue if the page is empty and `next_offset` is present. A job can disappear between reading the failed index and loading its metadata. Queue changes between calls can shift offset-based pages.

If the queue uses a custom prefix, set `DLQ_BULLMQ_PREFIX`. The default is `bull`.

The tool reads the configured BullMQ queue's Redis failed index and job metadata. It returns the job ID, name, failure reason, attempts made, and Unix timestamps in milliseconds. Payloads and stack traces are excluded. Only failures still retained in the configured queue's failed state are visible.

## Redis read behavior

The server shares one async Redis client with a pool of up to 16 connections and closes it at shutdown. Configure the Redis URL and queue before startup. Each failed-job listing has a five-second deadline, with up to two retries for transient connection errors or timeouts. Retries use short randomized backoff. Redis access failures return a tool error. Successful reads may return an empty page.

## Redis credentials and queue access

For authenticated Redis, set these variables on the MCP server.

| Variable | Value |
| --- | --- |
| `DLQ_REDIS_URL` | Redis address and database, for example `redis://127.0.0.1:6379/0` |
| `DLQ_REDIS_USERNAME` | Redis ACL username. Omit for password-only authentication. |
| `DLQ_REDIS_PASSWORD` | Redis password in its original form. |

Supply the password through your environment or secret manager. Redis URL credentials in the form `redis://USERNAME:PERCENT_ENCODED_PASSWORD@HOST:PORT/0` also work. Choose one credential format per server. For local Redis without authentication, omit the credential variables. Use your MCP client's local environment or secret settings when supplying credentials.

On Redis 7 or newer, a Redis administrator can create a new read-only account for the `payments` queue under the default `bull` prefix. For example, pass these arguments to an authenticated administrative `redis-cli` invocation. Supply the password rule from your secret manager.

```bash
redis-cli ACL SETUSER dlq-inspector on "$DLQ_REDIS_ACL_PASSWORD_RULE" \
  '%R~bull:payments:*' +zrevrange +hmget
```

The password rule begins with `>` followed by the account password. Match the read pattern to the configured queue and prefix. Add `+select` if the client must select a nondefault Redis database.

## Run the tests

```bash
uv run --locked --extra sqs --extra kafka python -m unittest discover -s tests -v
```

Set `DLQ_TEST_REDIS_URL` to a dedicated test Redis instance to include the
live BullMQ and Sidekiq pagination tests. The suite uses isolated keys and
removes them after each test. Kafka tests use the client library's broker
simulator. RabbitMQ and SQS tests use an HTTP fixture and SDK stub.

## Build the package

Run `uv build` from the repository root to produce a wheel and source distribution in `dist/`.

## Other queue backends

Set `DLQ_PROVIDER` in the server environment to select one backend per process.
Use `bullmq` for the BullMQ setup above. Names are case-insensitive.
`bullm` is an alias for `bullmq`, and `kafka` is an alias for `kafka-connect`. Start with
`dlq-recovery-mcp --transport stdio` or use the existing HTTP transport.

| Backend | Configuration | MCP tool |
| --- | --- | --- |
| `sidekiq` | `DLQ_REDIS_URL`, `DLQ_SIDEKIQ_QUEUE`, optional `DLQ_SIDEKIQ_DEAD_KEY` (defaults to `dead`) | `list_failed_jobs` |
| `rabbitmq` | `DLQ_RABBITMQ_API_URL` (management base URL), `DLQ_RABBITMQ_QUEUE` (DLQ name), `DLQ_RABBITMQ_USERNAME`, `DLQ_RABBITMQ_PASSWORD`, optional `DLQ_RABBITMQ_VHOST` (defaults to `/`) | `get_dlq_stats` |
| `sqs` | `DLQ_SQS_QUEUE_URL`, AWS region and credentials through the standard AWS SDK configuration | `get_dlq_stats` |
| `kafka-connect` | `DLQ_KAFKA_BOOTSTRAP_SERVERS`, `DLQ_KAFKA_TOPIC` (DLQ topic), optional `DLQ_KAFKA_CONFIG` (JSON object for client settings such as TLS and SASL) | `list_dlq_records` |

### MCP client configuration for RabbitMQ, SQS, and Kafka Connect

Use the entries below to run the adapters from your local checkout. Copy the
entries you need into your client's `mcpServers` object. Replace the checkout
path, endpoint, and queue or topic name. Each entry starts its own MCP process.
The `--extra` flags install the optional SQS and Kafka dependencies.

```json
{
  "mcpServers": {
    "rabbitmq-dlq": {
      "command": "uv",
      "args": ["--directory", "/absolute/path/to/dlq-recovery-mcp", "run", "--locked", "dlq-recovery-mcp", "--transport", "stdio"],
      "env": {
        "DLQ_PROVIDER": "rabbitmq",
        "DLQ_RABBITMQ_API_URL": "http://127.0.0.1:15672",
        "DLQ_RABBITMQ_VHOST": "/",
        "DLQ_RABBITMQ_QUEUE": "payments-dlq",
        "DLQ_RABBITMQ_USERNAME": "dlq-reader",
        "DLQ_RABBITMQ_PASSWORD": "REPLACE_WITH_LOCAL_SECRET"
      }
    },
    "sqs-dlq": {
      "command": "uv",
      "args": ["--directory", "/absolute/path/to/dlq-recovery-mcp", "run", "--locked", "--extra", "sqs", "dlq-recovery-mcp", "--transport", "stdio"],
      "env": {
        "DLQ_PROVIDER": "sqs",
        "DLQ_SQS_QUEUE_URL": "https://sqs.ap-south-1.amazonaws.com/123456789012/payments-dlq",
        "AWS_DEFAULT_REGION": "ap-south-1",
        "AWS_PROFILE": "dlq-reader"
      }
    },
    "kafka-connect-dlq": {
      "command": "uv",
      "args": ["--directory", "/absolute/path/to/dlq-recovery-mcp", "run", "--locked", "--extra", "kafka", "dlq-recovery-mcp", "--transport", "stdio"],
      "env": {
        "DLQ_PROVIDER": "kafka-connect",
        "DLQ_KAFKA_BOOTSTRAP_SERVERS": "127.0.0.1:9092",
        "DLQ_KAFKA_TOPIC": "payments-dlq"
      }
    }
  }
}
```

Use your MCP client's local secret settings for the RabbitMQ password. For SQS,
use an existing local AWS profile with access to the queue, or omit
`AWS_PROFILE` to use the SDK's default credential chain. The Kafka example
targets a local plaintext listener. For a secured cluster, supply
`DLQ_KAFKA_CONFIG` as a JSON string with your cluster's TLS and SASL settings.

- **Sidekiq** reads the global Dead set newest first and filters each page to the configured queue. Continue using `next_offset` even when a page is empty. `failed_at_ms` is the Dead-set insertion time, and `failed_reason` contains the exception class when available.
- **RabbitMQ and SQS** return queue counts without receiving, acknowledging, or requeuing messages. Enable the RabbitMQ management plugin and queue statistics. The SQS principal needs `sqs:GetQueueAttributes`. SQS counts are approximate.
- **Kafka Connect** takes a partition, an optional Kafka offset, and a limit. Omit the offset to start at the earliest retained record. Resume using `next_offset`, which can equal the requested offset when a poll times out. A null offset ends the scan. The tool returns metadata and supported error context headers when available. It excludes keys and payloads from the response and leaves consumer offsets uncommitted.
