PMDB Connector Plugin + Installer
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
# PMDB Connector Plugin
|
||||
|
||||
Profil-aware Anbindung an den PMDB MCP-Server als Hermes-Backend-Plugin
|
||||
(`kind: backend`). Liest das aktive Hermes-Profil, wählt den zugehörigen
|
||||
Bearer-Token aus der Profil-Config und registriert die `pmdb_*`-Tools im
|
||||
Toolset `pmdb`.
|
||||
|
||||
- Feature: `F454` (Plugin-Anbindung), `F621` (SSE-Stream), `F719` (Anlagen)
|
||||
- Repo: `Andreas/PMDB-Connector.git` auf Gitea (.47)
|
||||
|
||||
---
|
||||
|
||||
## Was das Plugin bietet
|
||||
|
||||
| Phase | Tools |
|
||||
|-------|-------|
|
||||
| Task-Lifecycle | `pmdb_get_tasks`, `pmdb_accept_task`, `pmdb_decline_task`, `pmdb_submit_task`, `pmdb_return_for_revision`, `pmdb_manager_decision` |
|
||||
| Query + Management | `pmdb_get_mask`, `pmdb_search`, `pmdb_get_baustein`, `pmdb_get_pipeline_status`, `pmdb_get_task_evidence` |
|
||||
| Manager-only | `pmdb_set_bit`, `pmdb_create_task`, `pmdb_get_submitted_tasks`, `pmdb_manager_dashboard`, `pmdb_submit_on_behalf` |
|
||||
| Task-Anlagen (F719) | `pmdb_get_anlagen`, `pmdb_download_anlage`, `pmdb_upload_ergebnis_anlage`, `pmdb_upload_anlage` |
|
||||
| Diagnose | `pmdb_stream_status` |
|
||||
|
||||
Manager-only-Tools sind doppelt abgesichert (Plugin-Guard *und* Server-
|
||||
Rollen-Check, F453).
|
||||
|
||||
---
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
- Hermes-Instanz mit aktivem Profil
|
||||
- `python3` mit `PyYAML` (das Plugin importiert `yaml` in `config.py`)
|
||||
- Ein PMDB-Bearer-Token für den Agenten (generiert auf `.49`)
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
./install.sh
|
||||
```
|
||||
|
||||
Interaktiv werden abgefragt:
|
||||
|
||||
1. **Agent-/Profil-Name** (Default: automatisch aus `HERMES_HOME` erkannt)
|
||||
2. **PMDB-Bearer-Token** (verdeckte Eingabe)
|
||||
3. **PMDB MCP `base_url`** (Default `https://pmdb.myowntools.org/mcp`)
|
||||
|
||||
Nicht-interaktiv (für Automatisierung/CI):
|
||||
|
||||
```bash
|
||||
./install.sh \
|
||||
--agent miguel \
|
||||
--token 'mcp_miguel_...' \
|
||||
--api-url 'http://192.168.180.49:8099' \
|
||||
--yes
|
||||
```
|
||||
|
||||
Alle Optionen:
|
||||
|
||||
```
|
||||
--agent <name> Agent-/Profil-Name
|
||||
--token <token> PMDB-Bearer-Token
|
||||
--api-url <url> PMDB MCP base_url (Default: https://pmdb.myowntools.org/mcp)
|
||||
--source <dir> Quellverzeichnis der Plugin-Dateien
|
||||
--skip-curl curl-Verbindungstest überspringen
|
||||
--yes, -y nicht-interaktiv
|
||||
--help, -h Hilfe
|
||||
```
|
||||
|
||||
### Was `install.sh` tut
|
||||
|
||||
1. Kopiert `__init__.py`, `client.py`, `config.py`, `plugin.yaml` (+ `tests/`)
|
||||
nach `~/.hermes/profiles/<agent>/plugins/pmdb_connector/`.
|
||||
2. Entfernt stale `__pycache__`/`.pyc` (P-001).
|
||||
3. Schreibt den Token in **zwei** Quellen:
|
||||
- `~/.hermes/mcp_tokens.json` → `agenten.<agent>.token` (kanonisch, F590)
|
||||
- `~/.hermes/profiles/<agent>/config.yaml` → `pmdb_connector.auth_keys.<agent>` (Fallback, F526)
|
||||
4. Legt vor jedem Schreibvorgang ein Backup an (`.bak-install`).
|
||||
5. Testet die Verbindung per `curl` gegen `GET <base_url>/mcp/api/tasks`.
|
||||
|
||||
---
|
||||
|
||||
## Token-Quellen (Auflösungsreihenfolge)
|
||||
|
||||
Die KANONISCHE Quelle ist `mcp_tokens.json` (F590, Single Source of Truth).
|
||||
`config.yaml`-`auth_keys` ist nur Fallback (Backward-Compat).
|
||||
|
||||
```
|
||||
resolve_token(profile):
|
||||
1. mcp_tokens.json agenten[<profile>].token <- kanonisch
|
||||
2. config.yaml pmdb_connector.auth_keys[<profile>]
|
||||
3. config.yaml pmdb_connector.auth_keys["default"]
|
||||
4. Basis-Config ~/.hermes/config.yaml
|
||||
5. Profil-Config ~/.hermes/profiles/<profile>/config.yaml
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Konfigurations-Referenz (`pmdb_connector`-Sektion)
|
||||
|
||||
```yaml
|
||||
pmdb_connector:
|
||||
base_url: "http://192.168.180.49:8099" # PMDB MCP base_url (OHNE /mcp!)
|
||||
auth_keys: # Fallback-Tokens (F526)
|
||||
default: "mcp_bernd_..."
|
||||
miguel: "mcp_miguel_..."
|
||||
rainer: "mcp_rainer_..."
|
||||
manager_profiles: [bernd, andreas] # Manager-only-Tools (F453)
|
||||
stream_enabled: false # SSE-Listener (F621, opt-in, Default aus)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ base_url-Falle (doppeltes `/mcp`)
|
||||
|
||||
Der Client hängt **selbst** `/mcp/api/...` an `base_url` an
|
||||
(`client.py` → `self.base_url + "/mcp/api/tasks"`). Deshalb darf `base_url`
|
||||
**kein** abschließendes `/mcp` enthalten:
|
||||
|
||||
| `base_url` | effektiver get_tasks-Aufruf | Ergebnis |
|
||||
|------------|-----------------------------|----------|
|
||||
| `https://pmdb.myowntools.org` | `.../mcp/api/tasks` | ✅ 200 |
|
||||
| `http://192.168.180.49:8099` (intern) | `.../mcp/api/tasks` | ✅ 200 |
|
||||
| `https://pmdb.myowntools.org/mcp` (Default) | `.../mcp/mcp/api/tasks` | ❌ 404 |
|
||||
|
||||
Zusätzlich blockt der Openresty-Proxy (`pmdb.myowntools.org`) Bearer-Tokens
|
||||
mit HTTP 401 (P-NEW-F563-PMDB-AUTH). **Empfehlung:** intern
|
||||
`http://192.168.180.49:8099` verwenden. `install.sh` warnt bei einem
|
||||
curl-404 explizit vor dieser Falle.
|
||||
|
||||
---
|
||||
|
||||
## Tests
|
||||
|
||||
Unit-Tests (stdlib-only, laufen überall, kein Netzwerk):
|
||||
|
||||
```bash
|
||||
cd tests
|
||||
python3 -m pytest -q
|
||||
```
|
||||
|
||||
Integration-Tests (gegen Live-PMDB auf `.49`) werden nur mit
|
||||
`PMDB_TEST_TOKEN` aktiviert:
|
||||
|
||||
```bash
|
||||
PMDB_TEST_TOKEN='mcp_...' PMDB_TEST_BASE='http://192.168.180.49:8099' \
|
||||
python3 -m pytest -q
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Datei-Layout
|
||||
|
||||
```
|
||||
pmdb_connector/
|
||||
├── install.sh # Installer (diese Anleitung)
|
||||
├── README.md
|
||||
├── __init__.py # Tool-Registrierung + Handler (F454, F621, F719)
|
||||
├── client.py # stdlib-only HTTP-Client (F454, F727)
|
||||
├── config.py # Profil-Config + Token-Auflösung (F454, F590)
|
||||
├── plugin.yaml # Plugin-Metadaten (kind: backend)
|
||||
└── tests/
|
||||
└── test_plugin.py # Unit- + Integration-Tests
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pitfalls-Referenz
|
||||
|
||||
- **P-001** stale `__pycache__` → `install.sh` räumt vor/nach Deploy auf.
|
||||
- **P-NEW-F563-PMDB-AUTH** Proxy blockt Bearer-Tokens (401) → intern `.49:8099`.
|
||||
- **P-191** Token nie in Logs/Responses (nur maskierter Prefix).
|
||||
- **F590** `mcp_tokens.json` ist kanonisch → verhindert Token-Drift.
|
||||
Reference in New Issue
Block a user