Get the FREE Ultimate OpenClaw Setup Guide →

nats

MCP server for NATS messaging system using NATS CLI - enabling AI agents to interact with NATS messaging

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio bmorphism-nats-mcp-server node /path/to/nats-mcp-server/build/index.js \
  --env NATS_URL="nats://localhost:4222"

How to use

This MCP server exposes a set of tools to interact with a NATS broker via the MCP framework. It wraps the NATS CLI capabilities behind MCP tools, allowing you to publish messages (with headers, templates, and optional reply subjects), subscribe to subjects with configurable timeouts and counts, and perform request-reply exchanges with optional headers. The server is configured via the NATS URL, which defaults to nats://localhost:4222, and the MCP commands (publish, subscribe, request) can be invoked through the MCP interface. Example usage includes publishing templated messages, attaching headers for routing or metadata, and performing batch operations with controlled timing and counts. The integration relies on the NATS CLI for low-level interactions while exposing a higher-level API for MCP workflows.

How to install

Prerequisites:

  • Node.js >= 14.0.0
  • npm (comes with Node.js)
  • NATS CLI installed and available on PATH

Option 1: Install from npm

  1. Ensure NATS CLI is installed and accessible:
    • macOS (Homebrew): brew tap nats-io/nats-tools && brew install nats
    • Linux: install via snap or apt as described in the README
    • Windows: install via Chocolatey or Scoop as described in the README
  2. Install the MCP server package: npm install @modelcontextprotocol/nats-mcp-server
  3. Build if needed (the repository may provide a build step): npm run build

Option 2: Clone and build from source

  1. git clone https://github.com/bmorphism/nats-mcp-server.git
  2. cd nats-mcp-server
  3. npm install
  4. npm run build

Run the server using Node, pointing to the built index.js: node /path/to/nats-mcp-server/build/index.js

Additional notes

Tips and notes:

  • The MCP server relies on the NATS_URL environment variable to connect to your NATS broker. Set NATS_URL to your broker URL if it differs from the default (nats://localhost:4222).
  • Ensure NATS CLI is installed and functional, since the MCP server uses it under the hood to perform publish/subscribe/request operations.
  • If you encounter connection or CLI invocation errors, verify that the NATS broker is reachable from the host running the MCP server and that NATS_URL is correctly configured.
  • When adding to MCP configurations in editors like Claude, use the provided example structure and point the args to your built index.js, ensuring NATS_URL is set in env.
  • For template-enabled publishing, you can leverage functions like Count, TimeStamp, Unix, Random, etc., as described in the Template Functions section of the README.
  • If you need to run multiple MCP servers, repeat the mcpServers block with distinct server names and NATS_URL values as needed.
Sponsor this space

Reach thousands of developers