Skip to content

Commit e5b2814

Browse files
authored
Merge pull request #12 from stife/codex/erstelle-mcp-server-fur-lima-city-vps
Add Lima-City MCP server for n8n and ChatGPT
2 parents a568669 + 1ee1180 commit e5b2814

File tree

9 files changed

+2218
-0
lines changed

9 files changed

+2218
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ Version 0.224.1
2222
## Facebook Page Management
2323

2424
A simple web interface to manage the Facebook page **"Techno auf den Augen"** is included in the [`facebook-manager`](./facebook-manager) directory. It relies on Express and the built-in Node.js `fetch` API to list and create posts and display basic page insights. Further documentation is available in the [Facebook manager wiki](./facebook-manager/WIKI.md).
25+
26+
## Lima-City MCP Server
27+
28+
The [`mcp-server`](./mcp-server) directory contains a dedicated Node.js service that exposes a Model Context Protocol (MCP) bridge for n8n and ChatGPT. It is designed to run on the Lima-City cloud VPS under `https://mcp.die-paten.biz` and provides:
29+
30+
- A combined `/mcp/tasks` endpoint to orchestrate ChatGPT prompts and n8n workflows.
31+
- Stand-alone `/chatgpt/complete` and `/n8n/execute` endpoints for direct integrations.
32+
- Health checks and configuration via environment variables (see [`mcp-server/.env.example`](./mcp-server/.env.example)).
33+
34+
Follow the [MCP server README](./mcp-server/README.md) for deployment instructions, reverse proxy examples, and integration tips.

mcp-server/.env.example

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Server configuration
2+
PORT=8080
3+
HOST=0.0.0.0
4+
JSON_BODY_LIMIT=1mb
5+
6+
# n8n integration
7+
# Base URL of your n8n instance (e.g. https://automation.example.com)
8+
N8N_API_BASE_URL=
9+
# Optional personal access token for the n8n REST API
10+
N8N_API_KEY=
11+
# Base webhook URL (e.g. https://automation.example.com/webhook)
12+
N8N_WEBHOOK_BASE_URL=
13+
# Optional basic auth credentials when your n8n instance is protected
14+
N8N_BASIC_AUTH_USER=
15+
N8N_BASIC_AUTH_PASSWORD=
16+
# Optional path template for running workflows via API
17+
N8N_RUN_ENDPOINT_TEMPLATE=/rest/workflows/:id/run
18+
# Optional timeout (ms) for n8n HTTP calls
19+
N8N_TIMEOUT=
20+
21+
# ChatGPT / OpenAI configuration
22+
OPENAI_API_KEY=
23+
# Override the default OpenAI API URL when using compatible services
24+
OPENAI_API_BASE_URL=https://api.openai.com/v1
25+
OPENAI_DEFAULT_MODEL=gpt-4o-mini
26+
OPENAI_DEFAULT_TEMPERATURE=0.7
27+
# Optional timeout (ms) for OpenAI HTTP calls
28+
OPENAI_TIMEOUT=

mcp-server/README.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Lima-City MCP Server
2+
3+
Ein schlanker Node.js-Server, der das **Model Context Protocol (MCP)** für Automatisierungen auf deiner Lima-City Cloud VPS umsetzt. Er fungiert als Brücke zwischen deiner n8n-Instanz und ChatGPT (OpenAI-kompatible APIs) und wurde auf den Betrieb unter der Domain **`https://mcp.die-paten.biz`** ausgelegt.
4+
5+
## Funktionsumfang
6+
7+
- 🌐 Einheitliches HTTP-Interface (`/mcp/tasks`) zur Orchestrierung von ChatGPT-Anfragen und n8n-Workflows.
8+
- 🤖 Direkte Weiterleitungen an beliebige n8n-Webhooks oder Workflow-Ausführungen via REST-API.
9+
- 🧠 ChatGPT/ OpenAI-Anbindung inkl. Modell- und Temperatursteuerung.
10+
- 📊 Gesundheitschecks für beide Integrationen über `/health`.
11+
- 🔒 Unterstützung für Basic-Auth geschützte n8n-Instanzen und API-Keys.
12+
- 🪪 Bereit für den Einsatz hinter einem Reverse Proxy (z. B. Nginx) auf Lima-City VPS.
13+
14+
## Installation
15+
16+
```bash
17+
cd mcp-server
18+
npm install
19+
cp .env.example .env
20+
```
21+
22+
Bearbeite anschließend die `.env` Datei mit deinen Zugangsdaten (siehe [Konfiguration](#konfiguration)).
23+
24+
### Systemdienst auf Lima-City VPS
25+
26+
1. **Systemd Service anlegen** (`/etc/systemd/system/mcp-server.service`):
27+
```ini
28+
[Unit]
29+
Description=Lima-City MCP Server
30+
After=network.target
31+
32+
[Service]
33+
Type=simple
34+
WorkingDirectory=/var/www/mcp-server
35+
ExecStart=/usr/bin/node src/index.js
36+
Restart=on-failure
37+
Environment=NODE_ENV=production
38+
EnvironmentFile=/var/www/mcp-server/.env
39+
40+
[Install]
41+
WantedBy=multi-user.target
42+
```
43+
2. Projekt nach `/var/www/mcp-server` deployen (z. B. per git pull).
44+
3. `sudo systemctl daemon-reload`
45+
4. `sudo systemctl enable --now mcp-server`
46+
47+
### Reverse Proxy (Beispiel Nginx)
48+
49+
```nginx
50+
server {
51+
server_name mcp.die-paten.biz;
52+
53+
listen 80;
54+
listen [::]:80;
55+
return 301 https://$host$request_uri;
56+
}
57+
58+
server {
59+
server_name mcp.die-paten.biz;
60+
61+
listen 443 ssl http2;
62+
listen [::]:443 ssl http2;
63+
ssl_certificate /etc/letsencrypt/live/mcp.die-paten.biz/fullchain.pem;
64+
ssl_certificate_key /etc/letsencrypt/live/mcp.die-paten.biz/privkey.pem;
65+
66+
location / {
67+
proxy_pass http://127.0.0.1:8080;
68+
proxy_http_version 1.1;
69+
proxy_set_header Upgrade $http_upgrade;
70+
proxy_set_header Connection "upgrade";
71+
proxy_set_header Host $host;
72+
proxy_set_header X-Real-IP $remote_addr;
73+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
74+
proxy_set_header X-Forwarded-Proto $scheme;
75+
}
76+
}
77+
```
78+
79+
## Konfiguration
80+
81+
Alle relevanten Umgebungsvariablen findest du in der Datei [`.env.example`](./.env.example).
82+
83+
| Variable | Beschreibung |
84+
| --- | --- |
85+
| `PORT` / `HOST` | Port/Host, auf dem der MCP-Server lauscht (Standard: 8080 / 0.0.0.0). |
86+
| `JSON_BODY_LIMIT` | Max. Größe eingehender JSON Payloads (z. B. `1mb`). |
87+
| `N8N_API_BASE_URL` | Basis-URL deiner n8n-Instanz (ohne `/webhook`). |
88+
| `N8N_API_KEY` | Optionaler API-Key für n8n (z. B. Personal Access Token). |
89+
| `N8N_WEBHOOK_BASE_URL` | Basis-URL für Webhook-Aufrufe (z. B. `https://automation.example.com/webhook`). |
90+
| `N8N_BASIC_AUTH_USER` / `N8N_BASIC_AUTH_PASSWORD` | Optional: Basic Auth Zugangsdaten, wenn n8n geschützt ist. |
91+
| `N8N_RUN_ENDPOINT_TEMPLATE` | Pfad-Template zum Ausführen eines Workflows via API (`/rest/workflows/:id/run`). |
92+
| `OPENAI_API_KEY` | API-Key für ChatGPT/OpenAI-kompatible Anbieter. |
93+
| `OPENAI_API_BASE_URL` | Alternative API-URL, falls du einen kompatiblen Anbieter nutzt. |
94+
| `OPENAI_DEFAULT_MODEL` | Standardmodell (z. B. `gpt-4o-mini`). |
95+
| `OPENAI_DEFAULT_TEMPERATURE` | Optionale Standardtemperatur (Float). |
96+
97+
> **Hinweis:** Für Lima-City Firewalls Ports öffnen (`iptables`/`ufw`) und sicherstellen, dass `8080/tcp` intern erreichbar ist. Der externe Zugriff erfolgt ausschließlich über den Reverse Proxy.
98+
99+
## Endpunkte
100+
101+
### `GET /`
102+
Liefert eine kurze Statusmeldung des Servers.
103+
104+
### `GET /health`
105+
Gibt die aktuellen Gesundheitsinformationen der n8n- und ChatGPT-Anbindungen zurück.
106+
107+
### `POST /chatgpt/complete`
108+
Erzeugt eine ChatGPT-Antwort. Beispielpayload:
109+
110+
```json
111+
{
112+
"prompt": "Erstelle eine Zusammenfassung der letzten Supportanfrage.",
113+
"context": [
114+
{ "role": "system", "content": "Du bist ein Support-Agent." },
115+
{ "role": "user", "content": "Kunde meldet Fehler 42 bei der Registrierung." }
116+
],
117+
"model": "gpt-4o-mini",
118+
"temperature": 0.2
119+
}
120+
```
121+
122+
### `POST /n8n/execute`
123+
Löst einen Workflow aus. Beispiel (Webhook):
124+
125+
```json
126+
{
127+
"webhookSlug": "support-intake",
128+
"payload": {
129+
"ticketId": "4711",
130+
"message": "Der Kunde benötigt Hilfe." }
131+
}
132+
```
133+
134+
### `POST /mcp/tasks`
135+
Kombinierter Endpunkt, um ChatGPT und n8n hintereinander aufzurufen.
136+
137+
```json
138+
{
139+
"prompt": "Fasse das Meeting in Stichpunkten zusammen.",
140+
"context": [
141+
"Meetingnotizen vom 12.05."
142+
],
143+
"chat": {
144+
"model": "gpt-4o-mini"
145+
},
146+
"workflow": {
147+
"webhookSlug": "send-meeting-summary",
148+
"payload": {
149+
"recipient": "team@die-paten.biz"
150+
}
151+
}
152+
}
153+
```
154+
155+
Der MCP-Server ergänzt automatisch das ChatGPT-Ergebnis und leitet es (sofern `mergeResults` nicht auf `false` gesetzt ist) an n8n weiter.
156+
157+
## Nutzung mit ChatGPT / OpenAI
158+
159+
- Richte in ChatGPT (Custom GPT oder API) einen **Webhook** auf `https://mcp.die-paten.biz/mcp/tasks` ein.
160+
- Übermittle in der Payload den gewünschten Prompt sowie optional ein Ziel in n8n.
161+
- Die Antwort enthält sowohl die ChatGPT-Ausgabe als auch die Antwort deines n8n-Workflows.
162+
163+
## Nutzung mit n8n
164+
165+
- Verwende den HTTP Request Node, um ChatGPT über `/chatgpt/complete` aufzurufen.
166+
- Nutze Webhook-Trigger in n8n, um `/mcp/tasks` als zentrale Schnittstelle anzusprechen.
167+
- Der Endpunkt ist ideal, um nachgelagerte Automationen in n8n zu starten und gleichzeitig ChatGPT in die Verarbeitung einzubeziehen.
168+
169+
## Entwicklung
170+
171+
```bash
172+
npm run dev
173+
```
174+
175+
Standardmäßig wird auf `http://localhost:8080` gelauscht. Mit `LOG_LEVEL=debug` erhältst du detaillierte Logs.
176+
177+
## Fehlerbehebung
178+
179+
- Prüfe `/health`, falls Antworten ausbleiben.
180+
- Aktiviere `LOG_LEVEL=debug`, um Anfrage- und Antwortdaten zu prüfen (sensitiven Inhalt zuvor maskieren!).
181+
- Bei n8n-Workflows ohne API-Key sollte `N8N_WEBHOOK_BASE_URL` gesetzt sein – andernfalls verwende einen vollständigen `webhookUrl` im Request.
182+
183+
Viel Erfolg beim Betrieb auf **mcp.die-paten.biz**! ✨

0 commit comments

Comments
 (0)