Content
# Node-RED MCP Server
A **MCP (Model Context Protocol)** server for managing remote Node-RED services, supporting operations such as adding, deleting, modifying, and querying Node-RED flows through natural language in MCP clients like Dify, Claude Desktop, and Cursor.
## ✨ Features
| Tool | Description |
| --- | --- |
| `list_flows` | List all flow (tab) summaries |
| `get_flow` | Get the complete configuration of a single flow |
| `get_all_flows_raw` | Get all flows' raw configurations (including rev) |
| `create_flow` | Create a new flow |
| `update_flow` | Update a flow (name, description, nodes, enable/disable) |
| `delete_flow` | Delete a flow |
| `enable_flow` / `disable_flow` | Enable / disable a flow |
| `deploy_flows` | Overall deployment (equivalent to the Deploy button in the editor) |
| `list_node_types` | List installed node modules and types |
| `get_runtime_settings` | View Node-RED runtime settings |
Built on top of the [Node-RED Admin API](https://nodered.org/docs/api/admin/methods/).
## 📦 Installation
```bash
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux / macOS
pip install -r requirements.txt
```
## ⚙️ Configuration
Copy `.env.example` to `.env` and fill in the actual values:
```bash
cp .env.example .env
```
```dotenv
NODE_RED_URL=http://your-node-red:1880
NODE_RED_TOKEN= # Recommended: use Bearer Token directly
NODE_RED_USERNAME= # Or use username and password (when adminAuth is enabled)
NODE_RED_PASSWORD=
```
### How to obtain the Node-RED Token?
If Node-RED has `adminAuth` enabled, you can obtain the token by:
```bash
curl -X POST http://your-node-red:1880/auth/token \
-d "client_id=node-red-admin" \
-d "grant_type=password" \
-d "scope=*" \
-d "username=admin" \
-d "password=xxx"
```
The returned `access_token` can be used as `NODE_RED_TOKEN`.
This project also supports directly configuring the username and password, and automatically exchanging tokens at startup.
## 🚀 Quick Verification
First, confirm that you can connect to Node-RED:
```bash
python flow_get.py
```
Normally, it should output a list of flows.
## ▶️ Running the MCP Server
### 1. stdio Mode (local, for Cursor / Claude Desktop)
```bash
python server.py
```
Add the following to `~/.cursor/mcp.json` in Cursor:
```json
{
"mcpServers": {
"node-red": {
"command": "python",
"args": ["C:/02Code/Node-RED-MCP-Server/server.py"],
"env": {
"NODE_RED_URL": "http://your-node-red:1880",
"NODE_RED_TOKEN": "xxx"
}
}
}
}
```
### 2. SSE Mode (for Dify)
```bash
python server.py --transport sse --host 0.0.0.0 --port 8765
```
In Dify, go to Tools → MCP → Add MCP Service:
- Server URL: `http://your-host:8765/sse`
- Transport Type: `SSE`
### 3. Streamable HTTP Mode
```bash
python server.py --transport http --host 0.0.0.0 --port 8765
```
Enter the URL: `http://your-host:8765/mcp`.
## 🧩 Usage Examples (calling through large language models with natural language)
- "List all flows on Node-RED"
- "Disable the flow named 'Temperature Alarm'"
- "Create a new flow named 'MQTT Collection' with the description 'xxx'"
- "Rename the flow with id `abc123` to 'Data Cleaning'"
- "Delete the flow with id `abc123`"
## 📁 Project Structure
```
.
├── server.py # MCP Server main entry
├── node_red_client.py # Node-RED Admin API client wrapper
├── flow_get.py # Connection test script
├── requirements.txt
├── .env.example
└── README.md
```
## ⚠️ Notes
- **Overall deployment will overwrite existing configurations**, so it's recommended to backup using `get_all_flows_raw` first.
- The `nodes` passed in `update_flow` will **replace** all nodes under the tab, not merge.
- Node-RED v3+ uses flows API v2 by default, and the client has automatically carried the corresponding request header.
- It's recommended to configure a reverse proxy + HTTPS + authentication for the MCP Server to avoid exposing the Node-RED management interface.