RA

RabbitMQ MCP Server: Publish and Consume Messages

Publish and consume messages with the RabbitMQ MCP server to streamline reliable messaging, routing, and processing across services.

Quick Install
npx -y @kenliao94/mcp-server-rabbitmq

Overview

The RabbitMQ MCP Server is a lightweight Model Context Protocol (MCP) server implementation that uses RabbitMQ as its transport layer. It provides a simple way to publish and consume structured model-context messages across services, leveraging AMQP for durable routing, acknowledgements, and retries. By combining the MCP semantics with RabbitMQ’s reliable messaging primitives, you can decouple producers and consumers while preserving delivery guarantees.

This server is useful when you need a dependable message bus for ML model inputs/outputs, feature updates, event streaming, or any cross-service coordination that benefits from structured context messages. It is designed for developers who want to plug RabbitMQ into an MCP-driven architecture without building the AMQP plumbing from scratch.

Features

  • Publish and consume MCP-style messages over RabbitMQ (AMQP)
  • Exchange/queue-based routing and topic-style routing keys
  • Durable queues and persistent messages for reliable delivery
  • Acknowledgement and retry-friendly consumer behavior
  • Configuration via environment variables or Docker Compose
  • Lightweight, easy to run locally or in containers
  • Useful for model-driven pipelines, background jobs, and event routing

Installation / Configuration

You can run the server locally by cloning the repository and using Docker / Docker Compose, or by building the project and running it directly (Node.js runtime assumed). The examples below show common deployment patterns.

Clone the repo

git clone https://github.com/kenliao94/mcp-server-rabbitmq.git
cd mcp-server-rabbitmq

Docker Compose example (runs RabbitMQ + MCP server)

# docker-compose.yml
version: "3.8"
services:
  rabbitmq:
    image: rabbitmq:3-management
    ports:
      - "5672:5672"
      - "15672:15672"
    environment:
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest

  mcp-server:
    build: .
    depends_on:
      - rabbitmq
    environment:
      RABBITMQ_URI: amqp://guest:guest@rabbitmq:5672
      MCP_EXCHANGE: mcp.exchange
      PORT: 3000
    ports:
      - "3000:3000"

Run with Docker Compose:

docker-compose up --build

Environment variables (typical)

RABBITMQ_URI    # AMQP URI, e.g. amqp://user:pass@host:5672
MCP_EXCHANGE    # Exchange name used for MCP messages (default: mcp)
MCP_QUEUE       # Default queue name for consumers (optional)
PORT            # HTTP/management port if the server exposes one (optional)
LOG_LEVEL       # Logging verbosity (info, debug, warn)

If you prefer to run the server directly (Node.js):

# Install dependencies and start
npm install
npm start
# or
node src/index.js

Available Resources

  • Source code and issues: https://github.com/kenliao94/mcp-server-rabbitmq
  • RabbitMQ management UI (if using docker-compose): http://localhost:15672 (default guest/guest)
  • AMQP libraries:
    • Node: amqplib (https://github.com/squaremo/amqp.node)
    • Python: pika (https://pika.readthedocs.io)
  • Useful commands:
    • docker logs
    • rabbitmqctl list_queues (inside container)
    • Use Cases

      1. Microservices event bus

        • Producers publish model context events (feature updates, inference requests) to the MCP exchange with topic routing keys like “model.X.request” or “model.Y.update”. Multiple services can subscribe to only the topics they care about.
      2. Background job / task queue

        • Use durable queues with persistent messages for long-running model re-training tasks. Consumers acknowledge messages after successful processing; unacknowledged messages can be retried or moved to dead-letter queues.
      3. Model inference pipeline

        • Frontend service publishes inference requests with context (input features, metadata). A pool of worker services consumes requests, runs models, and publishes responses or follow-up events to the exchange for downstream processing.
      4. Fan-out notifications

        • Broadcast contextual updates to several downstream services by binding multiple queues to the same exchange with different routing keys.

      Quick Example: Publish & Consume (Node.js)

      Publisher (amqplib)

      const amqp = require('amqplib');
      
      async function publish(uri, exchange, routingKey, message) {
        const conn = await amqp.connect(uri);
        const ch = await conn.createChannel();
        await ch.assertExchange(exchange, 'topic', { durable: true });
        ch.publish(exchange, routingKey, Buffer.from(JSON.stringify(message)), { persistent: true });
        await ch.close();
        await conn.close();
      }
      
      publish('amqp://guest:guest@localhost:5672', 'mcp.exchange', 'model.myModel.request', { id: 1, input: [0.1, 0.2] });
      

      Consumer (amqplib)

      const amqp = require('amqplib');
      
      async function consume(uri, exchange, queue, bindingKey, handler) {
        const conn = await amqp.connect(uri);
        const ch = await conn.createChannel();
        await ch.assertExchange(exchange, 'topic', { durable: true });
        await ch.assertQueue(queue, { durable: true });
        await ch.bindQueue(queue, exchange, bindingKey);
        ch.consume(queue, async msg => {
          const data = JSON.parse(msg.content.toString());
          try {
            await handler(data);
            ch.ack(msg);
          } catch (err) {
            ch.nack(msg, false, true); // requeue on failure
          }
        });
      }
      
      consume('amqp://guest:guest@localhost:5672', 'mcp.exchange', 'worker.queue', 'model.#', async (data) => {
        //