# n8n AI Assistant (MCP Proxy & Chrome Extension)

An advanced Chrome Extension and Node.js Proxy that brings "God Mode" AI orchestration directly into your n8n workspace. It allows you to chat with an AI assistant (ChatGPT, Gemini, etc.) that can read, create, modify, and execute n8n workflows via a zero-dependency local proxy using the Model Context Protocol (MCP).

## 🚀 Features

- **Context-First UX**: The AI assistant only activates when you are viewing an active n8n workflow, automatically injecting the current workflow's context into the chat.
- **MCP Proxy Server**: A lightweight, zero-dependency Node.js proxy server that bridges communication between the Chrome Extension and the n8n REST API via SSE + JSON-RPC.
- **12 n8n Tool Integrations**: The proxy exposes 12 powerful n8n management tools, including listing, getting, creating, updating, activating, and executing workflows.
- **System Prompt Injection**: Automatically injects a production-grade system prompt (inspired by `n8n-mcp`) into every AI chat session, teaching the AI how to safely and effectively manipulate n8n workflows.
- **Unified Dev Environment**: Run both the Vite-based Chrome extension frontend and the Node.js MCP proxy backend simultaneously with a single command.
- **Dynamic Configuration**: Configure your n8n API URL and Key directly from the extension's Settings UI.

## 🛠️ Tech Stack

- **Extension Frontend**: Vue 3, Vite, Tailwind CSS, TypeScript
- **MCP Proxy Backend**: Node.js (Zero-dependency, native `http` module)
- **Protocol**: SSE (Server-Sent Events) for real-time notifications, JSON-RPC 2.0 for tool execution.

## ⚙️ Installation & Setup

### Prerequisites
- Node.js (v18+)
- An active n8n instance
- An n8n API Key (Generated from your n8n account settings)

### 1. Clone & Install
```bash
git clone git@gitlab.hdtex.group:anhvh/n8n_ai_assistant.git
cd n8n_ai_assistant
npm install
```

### 2. Configure Environment
Copy the example environment file for the proxy server:
```bash
cp .env.example .env
```
*(You can also configure the n8n API URL and Key directly within the extension's UI later).*

### 3. Run Development Environment
Start both the Vite extension server and the MCP proxy server simultaneously:
```bash
npm run dev
```

### 4. Load the Extension in Chrome
1. Open Chrome and navigate to `chrome://extensions/`.
2. Enable **Developer mode** (toggle in the top right).
3. Click **Load unpacked** and select the `dist/` directory inside this project.

### 5. Configure the Extension
1. Pin the "Anything Copilot" extension to your browser toolbar.
2. Click the extension icon to open the popup.
3. Click the **Settings (⚙️)** icon in the top right corner.
4. Enter your Proxy URL (e.g., `http://localhost:3006`), n8n API URL, and n8n API Key.
5. Click **Save Settings**.

## 🧠 How It Works

1. **User Action**: You open an n8n workflow in your browser and click the extension icon to launch the AI Assistant sidebar.
2. **Context Injection**: The extension detects the active n8n workflow ID, fetches its structure, and prepends a hidden "System Prompt" (loaded from the MCP Proxy) to teach the AI how to use n8n tools.
3. **AI Reasoning**: You ask the AI to "Add a Telegram node to send a message when the webhook is triggered."
4. **Tool Execution**: The AI decides to call the `n8n_get_workflow` and `n8n_update_workflow` tools.
5. **Proxy Bridging**: The extension sends an RPC call to the local MCP Proxy Server (`http://localhost:3006`).
6. **n8n Interaction**: The Proxy Server securely forwards the request to the real n8n API using the configured API Key and returns the result to the AI.
7. **Result**: The workflow is updated directly on your screen!

## 📜 Available MCP Tools

| Category | Tools |
|----------|-------|
| Workflow Management | `n8n_list_workflows`, `n8n_get_workflow`, `n8n_create_workflow`, `n8n_update_workflow`, `n8n_delete_workflow`, `n8n_activate_workflow`, `n8n_deactivate_workflow` |
| Execution | `n8n_execute_workflow`, `n8n_list_executions`, `n8n_get_execution` |
| Credentials | `n8n_list_credentials` |
| System | `n8n_health_check` |

## 🏗️ Building for Production

To compile and minify the extension for production release:
```bash
npm run build
```

## 📄 License
Internal use only.
