knowmind 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -132
- package/package.json +59 -59
- package/src/client.js +115 -115
- package/src/mcp-stdio.js +82 -351
package/README.md
CHANGED
|
@@ -1,132 +1,150 @@
|
|
|
1
|
-
# knowmind
|
|
2
|
-
|
|
3
|
-
**Das Agentengehirn aus Deutschland.** Langzeitgedächtnis und Wissensgraph für Ihre KI —
|
|
4
|
-
CLI + MCP-Server.
|
|
5
|
-
|
|
6
|
-
<!-- mcp-name: io.github.Schubeler-Consulting/knowmind -->
|
|
7
|
-
|
|
8
|
-
[](https://www.npmjs.com/package/knowmind) · Apache-2.0 · [knowmind.de](https://knowmind.de)
|
|
9
|
-
|
|
10
|
-
## Installation
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
npm install -g knowmind
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Oder ohne Installation direkt als MCP-Server: `npx -y knowmind mcp`
|
|
17
|
-
|
|
18
|
-
## Setup
|
|
19
|
-
|
|
20
|
-
1. Token auf knowmind.de anlegen: Dashboard → API-Tokens
|
|
21
|
-
2. Lokal speichern:
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
knowmind login --token kmt_xxxxxxxx
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Alternativ über ENV:
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
export KNOWMIND_TOKEN=kmt_xxxxxxxx
|
|
31
|
-
export KNOWMIND_API_URL=https://knowmind.de
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Befehle
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
knowmind search "Wo läuft die OKR-App?"
|
|
38
|
-
knowmind upload notizen.md --title "Meeting Notizen 2026-05-12"
|
|
39
|
-
knowmind stats
|
|
40
|
-
knowmind health
|
|
41
|
-
knowmind config
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## MCP-Server einrichten
|
|
45
|
-
|
|
46
|
-
knowmind ist ein MCP-Server (`npx -y knowmind mcp`, stdio). Token aus dem knowmind.de-Dashboard
|
|
47
|
-
(→ API-Tokens) als `KNOWMIND_TOKEN`; optional `KNOWMIND_API_URL` (Standard `https://knowmind.de`).
|
|
48
|
-
|
|
49
|
-
**Claude Code**
|
|
50
|
-
```
|
|
51
|
-
claude mcp add knowmind --env KNOWMIND_TOKEN=kmt_xxx --env KNOWMIND_API_URL=https://knowmind.de -- npx -y knowmind mcp
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Claude Desktop / Cursor / Windsurf / Cline / Continue / Goose / Zed** (`claude_desktop_config.json`, `~/.cursor/mcp.json`, …)
|
|
55
|
-
```json
|
|
56
|
-
{
|
|
57
|
-
"mcpServers": {
|
|
58
|
-
"knowmind": {
|
|
59
|
-
"command": "npx",
|
|
60
|
-
"args": ["-y", "knowmind", "mcp"],
|
|
61
|
-
"env": { "KNOWMIND_TOKEN": "kmt_xxx", "KNOWMIND_API_URL": "https://knowmind.de" }
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
> Windows-Hinweis: falls `npx` nicht direkt startet, `"command": "cmd"`, `"args": ["/c", "npx", "-y", "knowmind", "mcp"]`.
|
|
67
|
-
|
|
68
|
-
**VS Code / GitHub Copilot** (`.vscode/mcp.json` — Top-Level `servers` + `inputs`)
|
|
69
|
-
```json
|
|
70
|
-
{
|
|
71
|
-
"inputs": [{ "id": "knowmind_token", "type": "promptString", "description": "Knowmind API token", "password": true }],
|
|
72
|
-
"servers": {
|
|
73
|
-
"knowmind": {
|
|
74
|
-
"command": "npx",
|
|
75
|
-
"args": ["-y", "knowmind", "mcp"],
|
|
76
|
-
"env": { "KNOWMIND_TOKEN": "${input:knowmind_token}", "KNOWMIND_API_URL": "https://knowmind.de" }
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
**Codex CLI** (`~/.codex/config.toml`)
|
|
83
|
-
```toml
|
|
84
|
-
[mcp_servers.knowmind]
|
|
85
|
-
command = "npx"
|
|
86
|
-
args = ["-y", "knowmind", "mcp"]
|
|
87
|
-
env = { KNOWMIND_TOKEN = "kmt_xxx", KNOWMIND_API_URL = "https://knowmind.de" }
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
**Gemini CLI** (`~/.gemini/settings.json`) — gleiche `mcpServers`-Struktur wie Claude Desktop.
|
|
91
|
-
|
|
92
|
-
**Remote (ohne lokale Installation)** — für Clients mit HTTP-MCP-Support direkt der gehostete Endpoint:
|
|
93
|
-
```json
|
|
94
|
-
{ "type": "http", "url": "https://knowmind.de/api/mcp/v1", "headers": { "Authorization": "Bearer kmt_xxx" } }
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Token kann statt per `env` auch lokal via `knowmind login --token kmt_xxx` (→ `~/.knowmind/config.json`) hinterlegt werden.
|
|
98
|
-
|
|
99
|
-
## Tools (im MCP-Modus)
|
|
100
|
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
- `knowmind.
|
|
104
|
-
|
|
105
|
-
- `
|
|
106
|
-
- `
|
|
107
|
-
- `
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
# knowmind
|
|
2
|
+
|
|
3
|
+
**Das Agentengehirn aus Deutschland.** Langzeitgedächtnis und Wissensgraph für Ihre KI —
|
|
4
|
+
CLI + MCP-Server. Inhalte und Server in Deutschland (Hetzner-Rechenzentrum).
|
|
5
|
+
|
|
6
|
+
<!-- mcp-name: io.github.Schubeler-Consulting/knowmind -->
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/knowmind) · Apache-2.0 · [knowmind.de](https://knowmind.de)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
npm install -g knowmind
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Oder ohne Installation direkt als MCP-Server: `npx -y knowmind mcp`
|
|
17
|
+
|
|
18
|
+
## Setup
|
|
19
|
+
|
|
20
|
+
1. Token auf knowmind.de anlegen: Dashboard → API-Tokens
|
|
21
|
+
2. Lokal speichern:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
knowmind login --token kmt_xxxxxxxx
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Alternativ über ENV:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
export KNOWMIND_TOKEN=kmt_xxxxxxxx
|
|
31
|
+
export KNOWMIND_API_URL=https://knowmind.de
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Befehle
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
knowmind search "Wo läuft die OKR-App?"
|
|
38
|
+
knowmind upload notizen.md --title "Meeting Notizen 2026-05-12"
|
|
39
|
+
knowmind stats
|
|
40
|
+
knowmind health
|
|
41
|
+
knowmind config
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## MCP-Server einrichten
|
|
45
|
+
|
|
46
|
+
knowmind ist ein MCP-Server (`npx -y knowmind mcp`, stdio). Token aus dem knowmind.de-Dashboard
|
|
47
|
+
(→ API-Tokens) als `KNOWMIND_TOKEN`; optional `KNOWMIND_API_URL` (Standard `https://knowmind.de`).
|
|
48
|
+
|
|
49
|
+
**Claude Code**
|
|
50
|
+
```
|
|
51
|
+
claude mcp add knowmind --env KNOWMIND_TOKEN=kmt_xxx --env KNOWMIND_API_URL=https://knowmind.de -- npx -y knowmind mcp
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Claude Desktop / Cursor / Windsurf / Cline / Continue / Goose / Zed** (`claude_desktop_config.json`, `~/.cursor/mcp.json`, …)
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"mcpServers": {
|
|
58
|
+
"knowmind": {
|
|
59
|
+
"command": "npx",
|
|
60
|
+
"args": ["-y", "knowmind", "mcp"],
|
|
61
|
+
"env": { "KNOWMIND_TOKEN": "kmt_xxx", "KNOWMIND_API_URL": "https://knowmind.de" }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
> Windows-Hinweis: falls `npx` nicht direkt startet, `"command": "cmd"`, `"args": ["/c", "npx", "-y", "knowmind", "mcp"]`.
|
|
67
|
+
|
|
68
|
+
**VS Code / GitHub Copilot** (`.vscode/mcp.json` — Top-Level `servers` + `inputs`)
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"inputs": [{ "id": "knowmind_token", "type": "promptString", "description": "Knowmind API token", "password": true }],
|
|
72
|
+
"servers": {
|
|
73
|
+
"knowmind": {
|
|
74
|
+
"command": "npx",
|
|
75
|
+
"args": ["-y", "knowmind", "mcp"],
|
|
76
|
+
"env": { "KNOWMIND_TOKEN": "${input:knowmind_token}", "KNOWMIND_API_URL": "https://knowmind.de" }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Codex CLI** (`~/.codex/config.toml`)
|
|
83
|
+
```toml
|
|
84
|
+
[mcp_servers.knowmind]
|
|
85
|
+
command = "npx"
|
|
86
|
+
args = ["-y", "knowmind", "mcp"]
|
|
87
|
+
env = { KNOWMIND_TOKEN = "kmt_xxx", KNOWMIND_API_URL = "https://knowmind.de" }
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Gemini CLI** (`~/.gemini/settings.json`) — gleiche `mcpServers`-Struktur wie Claude Desktop.
|
|
91
|
+
|
|
92
|
+
**Remote (ohne lokale Installation)** — für Clients mit HTTP-MCP-Support direkt der gehostete Endpoint:
|
|
93
|
+
```json
|
|
94
|
+
{ "type": "http", "url": "https://knowmind.de/api/mcp/v1", "headers": { "Authorization": "Bearer kmt_xxx" } }
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Token kann statt per `env` auch lokal via `knowmind login --token kmt_xxx` (→ `~/.knowmind/config.json`) hinterlegt werden.
|
|
98
|
+
|
|
99
|
+
## Tools (im MCP-Modus)
|
|
100
|
+
|
|
101
|
+
Der MCP-Modus ist seit 0.1.18 ein reiner Proxy auf die Plattform: Tool-Namen,
|
|
102
|
+
Schemas und Safety-Annotations kommen direkt vom Server und sind damit immer
|
|
103
|
+
identisch mit dem Remote-Connector (`https://knowmind.de/api/mcp/v1`).
|
|
104
|
+
|
|
105
|
+
- `knowmind_recall` — Hybride Suche im Wissensspeicher des Mandanten
|
|
106
|
+
- `knowmind_recall_at_time` — Recall mit Zeitfilter (bi-temporal)
|
|
107
|
+
- `knowmind_store_memory` — Neue Erinnerung anlegen (Titel + Inhalt)
|
|
108
|
+
- `knowmind_upload_document` — Längeren Text als Dokument ingestieren
|
|
109
|
+
- `knowmind_update_fact` — Fakt bi-temporal aktualisieren (Historie bleibt)
|
|
110
|
+
- `knowmind_link` — Typisierte Beziehung anlegen (Inverse wird automatisch gesetzt)
|
|
111
|
+
- `knowmind_unlink` — Beziehung wieder entfernen (samt Inverse)
|
|
112
|
+
- `knowmind_list_relations` — Beziehungen einer Erinnerung auflisten
|
|
113
|
+
- `knowmind_stats` — Statistik über gespeicherte Erinnerungen und Beziehungen
|
|
114
|
+
- `knowmind_health` — Verfügbarkeits-Status der Plattform
|
|
115
|
+
|
|
116
|
+
Inverse-Beziehungen (z. B. `IS_EMPLOYEE_OF` zu `HAS_EMPLOYEE`) werden
|
|
117
|
+
serverseitig automatisch mit angelegt. Hinweis: `knowmind upload` als
|
|
118
|
+
CLI-Befehl läuft über die REST-Schnittstelle (`/api/documents`), nicht über MCP.
|
|
119
|
+
|
|
120
|
+
## Daten in Deutschland
|
|
121
|
+
|
|
122
|
+
knowmind ist das Agentengehirn aus Deutschland: Ihre Inhalte (Memories, Account- und Metadaten) werden
|
|
123
|
+
ausschließlich auf Servern in Deutschland (Hetzner-Rechenzentrum) gespeichert und verlassen Deutschland nicht.
|
|
124
|
+
Auftragsverarbeitung (AVV) nach Art. 28 DSGVO verfügbar: https://knowmind.de/legal/avv
|
|
125
|
+
|
|
126
|
+
**Hinweis (Bring-your-own-Key):** Wenn Sie eigene Schlüssel externer KI-Anbieter hinterlegen, werden Ihre
|
|
127
|
+
Anfragen direkt an den von Ihnen gewählten Anbieter übermittelt. Sitzt dieser außerhalb der EU, kann dabei
|
|
128
|
+
ein Drittlandtransfer stattfinden, für den Sie als Verantwortlicher zuständig sind.
|
|
129
|
+
|
|
130
|
+
## Haftung & Nutzung (Disclaimer)
|
|
131
|
+
|
|
132
|
+
- **Software:** Dieses Paket steht unter der **Apache-Lizenz 2.0** und wird „AS IS" ohne jegliche
|
|
133
|
+
Gewährleistung bereitgestellt; die Haftung ist im Rahmen der Lizenz (Abschnitte 7 und 8)
|
|
134
|
+
ausgeschlossen bzw. beschränkt. Siehe `LICENSE`.
|
|
135
|
+
- **Eigenes Konto, eigener Token:** knowmind bündelt keine Zugangsdaten. Sie nutzen Ihren eigenen
|
|
136
|
+
knowmind.de-Account und API-Token. Anlegen: https://knowmind.de/dashboard/api-tokens
|
|
137
|
+
- **Eigene Kosten/Verbrauch:** Jede Nutzung (API-Anfragen, Token-/Kontingentverbrauch, ggf.
|
|
138
|
+
modellbezogene Kosten) erfolgt über Ihren eigenen Account und auf Ihre Verantwortung. Verbrauch
|
|
139
|
+
und Kosten sind im knowmind.de-Dashboard transparent einsehbar.
|
|
140
|
+
- **Service-Bedingungen:** Für die Nutzung der gehosteten Plattform gelten die AGB und die
|
|
141
|
+
Datenschutzerklärung von knowmind.de:
|
|
142
|
+
[AGB](https://knowmind.de/legal/agb) · [Datenschutz](https://knowmind.de/legal/datenschutz) ·
|
|
143
|
+
[AVV](https://knowmind.de/legal/avv) · [Impressum](https://knowmind.de/legal/impressum)
|
|
144
|
+
- **Kein Einsatz in sicherheitskritischen Bereichen:** knowmind ist ein Gedächtnis-/Recall-Dienst und
|
|
145
|
+
**nicht** für den Betrieb von selbstfahrenden Fahrzeugen, kritischer Infrastruktur, medizinischen oder
|
|
146
|
+
lebenserhaltenden Systemen oder sonstigen Anwendungen bestimmt, bei denen ein Fehler oder Ausfall zu Tod,
|
|
147
|
+
Personen-, Umwelt- oder schweren Sachschäden führen kann. Ein Einsatz in solchen Umgebungen erfolgt auf
|
|
148
|
+
alleiniges Risiko des Nutzers.
|
|
149
|
+
|
|
150
|
+
Anbieter: Schübeler Consulting — Johann Jörgen Schübeler. Kontakt: info@schuebeler-consulting.de
|
package/package.json
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "knowmind",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"mcpName": "io.github.Schubeler-Consulting/knowmind",
|
|
5
|
-
"description": "Knowmind — das Agentengehirn aus Deutschland: CLI + MCP-Server (Langzeitgedächtnis & Wissensgraph für Ihre KI, Server in Deutschland).",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"license": "Apache-2.0",
|
|
8
|
-
"homepage": "https://knowmind.de",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/Schubeler-Consulting/knowmind.git"
|
|
12
|
-
},
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://knowmind.de/support",
|
|
15
|
-
"email": "info@schuebeler-consulting.de"
|
|
16
|
-
},
|
|
17
|
-
"author": {
|
|
18
|
-
"name": "Knowmind",
|
|
19
|
-
"email": "info@schuebeler-consulting.de",
|
|
20
|
-
"url": "https://knowmind.de"
|
|
21
|
-
},
|
|
22
|
-
"engines": {
|
|
23
|
-
"node": ">=20"
|
|
24
|
-
},
|
|
25
|
-
"bin": {
|
|
26
|
-
"knowmind": "bin/knowmind.js"
|
|
27
|
-
},
|
|
28
|
-
"files": [
|
|
29
|
-
"bin",
|
|
30
|
-
"src",
|
|
31
|
-
"README.md",
|
|
32
|
-
"LICENSE"
|
|
33
|
-
],
|
|
34
|
-
"scripts": {
|
|
35
|
-
"test": "node --test src/*.test.js"
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"@huggingface/transformers": "^3.5.0"
|
|
39
|
-
},
|
|
40
|
-
"overrides": {
|
|
41
|
-
"global-agent": "^4.1.3"
|
|
42
|
-
},
|
|
43
|
-
"keywords": [
|
|
44
|
-
"knowmind",
|
|
45
|
-
"mcp",
|
|
46
|
-
"model-context-protocol",
|
|
47
|
-
"knowledge-graph",
|
|
48
|
-
"recall",
|
|
49
|
-
"memory",
|
|
50
|
-
"rag",
|
|
51
|
-
"claude",
|
|
52
|
-
"openai",
|
|
53
|
-
"anthropic",
|
|
54
|
-
"ai"
|
|
55
|
-
],
|
|
56
|
-
"publishConfig": {
|
|
57
|
-
"access": "public"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "knowmind",
|
|
3
|
+
"version": "0.1.18",
|
|
4
|
+
"mcpName": "io.github.Schubeler-Consulting/knowmind",
|
|
5
|
+
"description": "Knowmind — das Agentengehirn aus Deutschland: CLI + MCP-Server (Langzeitgedächtnis & Wissensgraph für Ihre KI, Server in Deutschland).",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"homepage": "https://knowmind.de",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Schubeler-Consulting/knowmind.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://knowmind.de/support",
|
|
15
|
+
"email": "info@schuebeler-consulting.de"
|
|
16
|
+
},
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Knowmind",
|
|
19
|
+
"email": "info@schuebeler-consulting.de",
|
|
20
|
+
"url": "https://knowmind.de"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"knowmind": "bin/knowmind.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"bin",
|
|
30
|
+
"src",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "node --test src/*.test.js"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@huggingface/transformers": "^3.5.0"
|
|
39
|
+
},
|
|
40
|
+
"overrides": {
|
|
41
|
+
"global-agent": "^4.1.3"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"knowmind",
|
|
45
|
+
"mcp",
|
|
46
|
+
"model-context-protocol",
|
|
47
|
+
"knowledge-graph",
|
|
48
|
+
"recall",
|
|
49
|
+
"memory",
|
|
50
|
+
"rag",
|
|
51
|
+
"claude",
|
|
52
|
+
"openai",
|
|
53
|
+
"anthropic",
|
|
54
|
+
"ai"
|
|
55
|
+
],
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/client.js
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Knowmind-API-Client.
|
|
3
|
-
*
|
|
4
|
-
* Spricht ausschließlich gegen den MCP-Endpoint /api/mcp/v1 (JSON-RPC),
|
|
5
|
-
* weil dieser bereits Bearer-Auth + Tools für recall/stats/health bietet.
|
|
6
|
-
* Document-Upload geht zusätzlich gegen die REST-API /api/documents.
|
|
7
|
-
*/
|
|
8
|
-
import { loadConfig } from "./config.js";
|
|
9
|
-
|
|
10
|
-
let rpcId = 1;
|
|
11
|
-
|
|
12
|
-
async function rpc(method, params, options = {}) {
|
|
13
|
-
const { apiUrl, token } = loadConfig();
|
|
14
|
-
if (!token) throw new Error("Kein Token konfiguriert — bitte `knowmind login` ausführen.");
|
|
15
|
-
const r = await fetch(`${apiUrl}/api/mcp/v1`, {
|
|
16
|
-
method: "POST",
|
|
17
|
-
headers: {
|
|
18
|
-
"content-type": "application/json",
|
|
19
|
-
authorization: `Bearer ${token}`,
|
|
20
|
-
...(options.headers ?? {}),
|
|
21
|
-
},
|
|
22
|
-
body: JSON.stringify({ jsonrpc: "2.0", id: rpcId++, method, params }),
|
|
23
|
-
signal: options.signal,
|
|
24
|
-
});
|
|
25
|
-
const data = await r.json();
|
|
26
|
-
if (data.error) throw new Error(`${data.error.code}: ${data.error.message}`);
|
|
27
|
-
return data.result;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function recall(query, { k = 5, hops = 2 } = {}) {
|
|
31
|
-
const res = await rpc("tools/call", {
|
|
32
|
-
name: "knowmind.recall",
|
|
33
|
-
arguments: { query, k, hops },
|
|
34
|
-
});
|
|
35
|
-
// MCP-Antwort: { content: [{ type: "text", text: "<JSON>" }] }
|
|
36
|
-
const text = res.content?.[0]?.text;
|
|
37
|
-
if (!text) return null;
|
|
38
|
-
return JSON.parse(text);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function stats() {
|
|
42
|
-
const res = await rpc("tools/call", { name: "knowmind.stats", arguments: {} });
|
|
43
|
-
return JSON.parse(res.content?.[0]?.text ?? "{}");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function health() {
|
|
47
|
-
const res = await rpc("tools/call", { name: "knowmind.health", arguments: {} });
|
|
48
|
-
return JSON.parse(res.content?.[0]?.text ?? "{}");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Lädt ein Dokument hoch. Default-Pfad: Client rechnet die Embeddings
|
|
53
|
-
* lokal und schickt sie mit — der Server speichert nur noch, ohne eigene
|
|
54
|
-
* Berechnung. Skaliert deutlich besser.
|
|
55
|
-
*
|
|
56
|
-
* Wird KNOWMIND_EMBED_MODE=server gesetzt, geht der alte Pfad: Server
|
|
57
|
-
* rechnet selbst. Sinnvoll als Fallback, wenn der Client kein Modell
|
|
58
|
-
* laden kann (z. B. RAM-knapp).
|
|
59
|
-
*/
|
|
60
|
-
export async function uploadDocument(title, content) {
|
|
61
|
-
const { apiUrl, token } = loadConfig();
|
|
62
|
-
if (!token) throw new Error("Kein Token konfiguriert.");
|
|
63
|
-
|
|
64
|
-
const mode = (process.env.KNOWMIND_EMBED_MODE || "client").toLowerCase();
|
|
65
|
-
let body;
|
|
66
|
-
if (mode === "client") {
|
|
67
|
-
try {
|
|
68
|
-
const { prepareChunks, embedBatch, MODEL } = await import("./local-embedding.js");
|
|
69
|
-
// prepareChunks zerlegt Text in Standard-Chunks UND extrahiert
|
|
70
|
-
// Preference-/Fact-/Update-Statements als Zusatz-Chunks mit type-Tag.
|
|
71
|
-
// Recall-Server boostet die getaggten Chunks für passende Queries.
|
|
72
|
-
const prepared = await prepareChunks(content);
|
|
73
|
-
const vectors = await embedBatch(prepared.map((c) => c.content), "passage");
|
|
74
|
-
body = {
|
|
75
|
-
title,
|
|
76
|
-
content,
|
|
77
|
-
chunks: prepared.map((c, i) => ({
|
|
78
|
-
content: c.content,
|
|
79
|
-
embedding: vectors[i],
|
|
80
|
-
...(c.metadata ? { metadata: c.metadata } : {}),
|
|
81
|
-
})),
|
|
82
|
-
embeddingModel: MODEL,
|
|
83
|
-
};
|
|
84
|
-
} catch (err) {
|
|
85
|
-
process.stderr.write(
|
|
86
|
-
`[knowmind] lokales Embedding fehlgeschlagen, fallback auf Server: ${err.message}\n`,
|
|
87
|
-
);
|
|
88
|
-
body = { title, content };
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
body = { title, content };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const r = await fetch(`${apiUrl}/api/documents`, {
|
|
95
|
-
method: "POST",
|
|
96
|
-
headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
|
|
97
|
-
body: JSON.stringify(body),
|
|
98
|
-
});
|
|
99
|
-
const text = await r.text();
|
|
100
|
-
let data;
|
|
101
|
-
try {
|
|
102
|
-
data = text ? JSON.parse(text) : {};
|
|
103
|
-
} catch {
|
|
104
|
-
if (!r.ok) {
|
|
105
|
-
throw new Error(`HTTP ${r.status} ${r.statusText} — ${text.slice(0, 200)}`);
|
|
106
|
-
}
|
|
107
|
-
throw new Error(`HTTP ${r.status} lieferte ungültiges JSON: ${text.slice(0, 200)}`);
|
|
108
|
-
}
|
|
109
|
-
if (!r.ok) throw new Error(data.error ?? `HTTP ${r.status} ${r.statusText}`);
|
|
110
|
-
return data;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export async function listTools() {
|
|
114
|
-
return await rpc("tools/list", {});
|
|
115
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Knowmind-API-Client.
|
|
3
|
+
*
|
|
4
|
+
* Spricht ausschließlich gegen den MCP-Endpoint /api/mcp/v1 (JSON-RPC),
|
|
5
|
+
* weil dieser bereits Bearer-Auth + Tools für recall/stats/health bietet.
|
|
6
|
+
* Document-Upload geht zusätzlich gegen die REST-API /api/documents.
|
|
7
|
+
*/
|
|
8
|
+
import { loadConfig } from "./config.js";
|
|
9
|
+
|
|
10
|
+
let rpcId = 1;
|
|
11
|
+
|
|
12
|
+
async function rpc(method, params, options = {}) {
|
|
13
|
+
const { apiUrl, token } = loadConfig();
|
|
14
|
+
if (!token) throw new Error("Kein Token konfiguriert — bitte `knowmind login` ausführen.");
|
|
15
|
+
const r = await fetch(`${apiUrl}/api/mcp/v1`, {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: {
|
|
18
|
+
"content-type": "application/json",
|
|
19
|
+
authorization: `Bearer ${token}`,
|
|
20
|
+
...(options.headers ?? {}),
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: rpcId++, method, params }),
|
|
23
|
+
signal: options.signal,
|
|
24
|
+
});
|
|
25
|
+
const data = await r.json();
|
|
26
|
+
if (data.error) throw new Error(`${data.error.code}: ${data.error.message}`);
|
|
27
|
+
return data.result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function recall(query, { k = 5, hops = 2 } = {}) {
|
|
31
|
+
const res = await rpc("tools/call", {
|
|
32
|
+
name: "knowmind.recall",
|
|
33
|
+
arguments: { query, k, hops },
|
|
34
|
+
});
|
|
35
|
+
// MCP-Antwort: { content: [{ type: "text", text: "<JSON>" }] }
|
|
36
|
+
const text = res.content?.[0]?.text;
|
|
37
|
+
if (!text) return null;
|
|
38
|
+
return JSON.parse(text);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function stats() {
|
|
42
|
+
const res = await rpc("tools/call", { name: "knowmind.stats", arguments: {} });
|
|
43
|
+
return JSON.parse(res.content?.[0]?.text ?? "{}");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function health() {
|
|
47
|
+
const res = await rpc("tools/call", { name: "knowmind.health", arguments: {} });
|
|
48
|
+
return JSON.parse(res.content?.[0]?.text ?? "{}");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Lädt ein Dokument hoch. Default-Pfad: Client rechnet die Embeddings
|
|
53
|
+
* lokal und schickt sie mit — der Server speichert nur noch, ohne eigene
|
|
54
|
+
* Berechnung. Skaliert deutlich besser.
|
|
55
|
+
*
|
|
56
|
+
* Wird KNOWMIND_EMBED_MODE=server gesetzt, geht der alte Pfad: Server
|
|
57
|
+
* rechnet selbst. Sinnvoll als Fallback, wenn der Client kein Modell
|
|
58
|
+
* laden kann (z. B. RAM-knapp).
|
|
59
|
+
*/
|
|
60
|
+
export async function uploadDocument(title, content) {
|
|
61
|
+
const { apiUrl, token } = loadConfig();
|
|
62
|
+
if (!token) throw new Error("Kein Token konfiguriert.");
|
|
63
|
+
|
|
64
|
+
const mode = (process.env.KNOWMIND_EMBED_MODE || "client").toLowerCase();
|
|
65
|
+
let body;
|
|
66
|
+
if (mode === "client") {
|
|
67
|
+
try {
|
|
68
|
+
const { prepareChunks, embedBatch, MODEL } = await import("./local-embedding.js");
|
|
69
|
+
// prepareChunks zerlegt Text in Standard-Chunks UND extrahiert
|
|
70
|
+
// Preference-/Fact-/Update-Statements als Zusatz-Chunks mit type-Tag.
|
|
71
|
+
// Recall-Server boostet die getaggten Chunks für passende Queries.
|
|
72
|
+
const prepared = await prepareChunks(content);
|
|
73
|
+
const vectors = await embedBatch(prepared.map((c) => c.content), "passage");
|
|
74
|
+
body = {
|
|
75
|
+
title,
|
|
76
|
+
content,
|
|
77
|
+
chunks: prepared.map((c, i) => ({
|
|
78
|
+
content: c.content,
|
|
79
|
+
embedding: vectors[i],
|
|
80
|
+
...(c.metadata ? { metadata: c.metadata } : {}),
|
|
81
|
+
})),
|
|
82
|
+
embeddingModel: MODEL,
|
|
83
|
+
};
|
|
84
|
+
} catch (err) {
|
|
85
|
+
process.stderr.write(
|
|
86
|
+
`[knowmind] lokales Embedding fehlgeschlagen, fallback auf Server: ${err.message}\n`,
|
|
87
|
+
);
|
|
88
|
+
body = { title, content };
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
body = { title, content };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const r = await fetch(`${apiUrl}/api/documents`, {
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
|
|
97
|
+
body: JSON.stringify(body),
|
|
98
|
+
});
|
|
99
|
+
const text = await r.text();
|
|
100
|
+
let data;
|
|
101
|
+
try {
|
|
102
|
+
data = text ? JSON.parse(text) : {};
|
|
103
|
+
} catch {
|
|
104
|
+
if (!r.ok) {
|
|
105
|
+
throw new Error(`HTTP ${r.status} ${r.statusText} — ${text.slice(0, 200)}`);
|
|
106
|
+
}
|
|
107
|
+
throw new Error(`HTTP ${r.status} lieferte ungültiges JSON: ${text.slice(0, 200)}`);
|
|
108
|
+
}
|
|
109
|
+
if (!r.ok) throw new Error(data.error ?? `HTTP ${r.status} ${r.statusText}`);
|
|
110
|
+
return data;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function listTools() {
|
|
114
|
+
return await rpc("tools/list", {});
|
|
115
|
+
}
|
package/src/mcp-stdio.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lokaler MCP-Stdio-Server.
|
|
2
|
+
* Lokaler MCP-Stdio-Server — dünner Proxy auf die Knowmind-Plattform.
|
|
3
3
|
*
|
|
4
|
-
* Forwarded JSON-RPC-Requests von stdin an
|
|
5
|
-
* und schreibt die Antworten auf stdout. Damit kann
|
|
6
|
-
* MCP-fähigen Client (Claude Code,
|
|
7
|
-
* werden, ohne dass der Client Bearer-Token
|
|
8
|
-
* verwaltet die Auth.
|
|
4
|
+
* Forwarded JSON-RPC-Requests von stdin an den Remote-MCP-Endpoint
|
|
5
|
+
* (POST {apiUrl}/api/mcp/v1) und schreibt die Antworten auf stdout. Damit kann
|
|
6
|
+
* Knowmind in jeden lokalen MCP-fähigen Client (Claude Code, Claude Desktop,
|
|
7
|
+
* ChatGPT, Cursor, ...) eingebunden werden, ohne dass der Client Bearer-Token
|
|
8
|
+
* kennen muss — der CLI-Wrapper verwaltet die Auth.
|
|
9
|
+
*
|
|
10
|
+
* DESIGN: Seit 0.1.18 ist dieser Server ein reiner Proxy. Tool-Definitionen,
|
|
11
|
+
* Namen (knowmind_recall, knowmind_store_memory, ...), Schemas und
|
|
12
|
+
* Safety-Annotations kommen direkt vom Server (tools/list wird durchgereicht).
|
|
13
|
+
* Dadurch können lokale Definitionen nie mehr vom Server-Stand abweichen —
|
|
14
|
+
* genau diese Abweichung (Punkt- vs. Unterstrich-Namen) hatte 0.1.17 unbrauchbar
|
|
15
|
+
* gemacht, nachdem die Plattform auf das MCP-Namensschema umgestellt wurde.
|
|
9
16
|
*
|
|
10
17
|
* Protokoll: stdio mit zeilenweise JSON (NDJSON-Style). Jedes Frame ist ein
|
|
11
18
|
* vollständiges JSON-RPC-Objekt.
|
|
@@ -13,285 +20,37 @@
|
|
|
13
20
|
import { loadConfig, VERSION } from "./config.js";
|
|
14
21
|
import { createInterface } from "node:readline";
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// automatisch materialisiert — der Agent setzt nur die Vorwärtsrichtung.
|
|
19
|
-
const REL_TYPES = [
|
|
20
|
-
"HAS_EMPLOYEE", "IS_EMPLOYEE_OF",
|
|
21
|
-
"IS_LED_BY", "LEADS_ORGANIZATION",
|
|
22
|
-
"OWNS", "OWNED_BY",
|
|
23
|
-
"HAS_SKILL", "WORKS_ON", "FOR_CLIENT",
|
|
24
|
-
"HAS_VERSION", "IS_VERSION_OF",
|
|
25
|
-
"HAS_CHUNK", "CHUNK_OF",
|
|
26
|
-
"HAS_EMBEDDING", "EMBEDDING_OF",
|
|
27
|
-
"INDEXED_IN",
|
|
28
|
-
"REFERENCES_ENTITY", "REFERENCED_BY",
|
|
29
|
-
"PRODUCES", "PRODUCED_BY",
|
|
30
|
-
"DEPENDS_ON", "ENABLES",
|
|
31
|
-
"APPLIES_TO", "HAS_RULE",
|
|
32
|
-
"REFERENCES", "SUPERSEDES", "SUPERSEDED_BY",
|
|
33
|
-
"WAS_GENERATED_BY", "GENERATED",
|
|
34
|
-
"USED", "USED_BY",
|
|
35
|
-
"WAS_DERIVED_FROM", "DERIVATION_TARGET_OF",
|
|
36
|
-
"WAS_ASSOCIATED_WITH",
|
|
37
|
-
"MEASURED_METRIC",
|
|
38
|
-
];
|
|
23
|
+
/** Methoden, die lokal beantwortet werden (alles andere geht an den Server). */
|
|
24
|
+
const LOCAL_METHODS = new Set(["initialize", "ping"]);
|
|
39
25
|
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"Hybride Suche im Knowmind-Wissensspeicher des aktuellen Mandanten. Liefert die passendsten Treffer mit Quellenverweis und Trefferqualität.",
|
|
45
|
-
inputSchema: {
|
|
46
|
-
type: "object",
|
|
47
|
-
properties: {
|
|
48
|
-
query: { type: "string", description: "Natürlichsprachliche Frage" },
|
|
49
|
-
k: { type: "integer", minimum: 1, maximum: 25, default: 5 },
|
|
50
|
-
hops: { type: "integer", minimum: 0, maximum: 3, default: 2 },
|
|
51
|
-
},
|
|
52
|
-
required: ["query"],
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: "knowmind.store",
|
|
57
|
-
description:
|
|
58
|
-
"Speichert eine neue Erinnerung im aktuellen Mandanten. Liefert die Dokument-ID und die Anzahl der indexierten Abschnitte zurück. Sofort über knowmind.recall auffindbar.",
|
|
59
|
-
inputSchema: {
|
|
60
|
-
type: "object",
|
|
61
|
-
properties: {
|
|
62
|
-
title: {
|
|
63
|
-
type: "string",
|
|
64
|
-
description: "Kurzer Titel für die Erinnerung (max. 500 Zeichen)",
|
|
65
|
-
},
|
|
66
|
-
content: {
|
|
67
|
-
type: "string",
|
|
68
|
-
description: "Inhalt der Erinnerung als Text oder Markdown (max. 1 MB)",
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
required: ["title", "content"],
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
name: "knowmind.link",
|
|
76
|
-
description:
|
|
77
|
-
"Legt eine typisierte Beziehung zwischen zwei Erinnerungen an. Die Gegen-Beziehung wird automatisch mit angelegt (zum Beispiel HAS_EMPLOYEE → IS_EMPLOYEE_OF). Der Agent setzt also nur die Vorwärtsrichtung. Verwende knowmind.recall, um zuvor die IDs zu finden.",
|
|
78
|
-
inputSchema: {
|
|
79
|
-
type: "object",
|
|
80
|
-
properties: {
|
|
81
|
-
fromId: { type: "string", description: "ID der Quell-Erinnerung" },
|
|
82
|
-
toId: { type: "string", description: "ID der Ziel-Erinnerung" },
|
|
83
|
-
relType: {
|
|
84
|
-
type: "string",
|
|
85
|
-
enum: REL_TYPES,
|
|
86
|
-
description: "Beziehungstyp aus der zulässigen Liste",
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
required: ["fromId", "toId", "relType"],
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: "knowmind.unlink",
|
|
94
|
-
description:
|
|
95
|
-
"Entfernt eine typisierte Beziehung. Die Gegen-Beziehung wird ebenfalls gelöscht.",
|
|
96
|
-
inputSchema: {
|
|
97
|
-
type: "object",
|
|
98
|
-
properties: {
|
|
99
|
-
fromId: { type: "string" },
|
|
100
|
-
toId: { type: "string" },
|
|
101
|
-
relType: { type: "string", enum: REL_TYPES },
|
|
102
|
-
},
|
|
103
|
-
required: ["fromId", "toId", "relType"],
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
name: "knowmind.relations",
|
|
108
|
-
description:
|
|
109
|
-
"Listet alle bestehenden Beziehungen einer Erinnerung. Hilfreich bevor neue Beziehungen angelegt werden, um Duplikate zu vermeiden.",
|
|
110
|
-
inputSchema: {
|
|
111
|
-
type: "object",
|
|
112
|
-
properties: {
|
|
113
|
-
memoryId: { type: "string", description: "ID der Erinnerung" },
|
|
114
|
-
},
|
|
115
|
-
required: ["memoryId"],
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: "knowmind.health",
|
|
120
|
-
description: "Service-Verfügbarkeit prüfen.",
|
|
121
|
-
inputSchema: { type: "object", properties: {} },
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
name: "knowmind.stats",
|
|
125
|
-
description: "Statistik des aktuellen Mandanten (Anzahl Erinnerungen, Beziehungen).",
|
|
126
|
-
inputSchema: { type: "object", properties: {} },
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
name: "knowmind.update_fact",
|
|
130
|
-
description:
|
|
131
|
-
"Bi-temporales Update: ersetzt eine bestehende Erinnerung durch eine neue. Die alte Erinnerung bleibt im Audit-Log mit validTo=now und wird per SUPERSEDES-Beziehung mit der neuen verbunden — so bleibt die Historie nachvollziehbar. Verwende dies, wenn sich Fakten ändern (Adresse, Vertragsstatus, Personen).",
|
|
132
|
-
inputSchema: {
|
|
133
|
-
type: "object",
|
|
134
|
-
properties: {
|
|
135
|
-
targetId: { type: "string", description: "ID der zu aktualisierenden Erinnerung" },
|
|
136
|
-
newTitle: { type: "string", description: "Titel der neuen, gültigen Version" },
|
|
137
|
-
newContent: { type: "string", description: "Inhalt der neuen Version" },
|
|
138
|
-
updateReason: {
|
|
139
|
-
type: "string",
|
|
140
|
-
description: "Warum hat sich der Fakt geändert (z. B. 'Umzug', 'Vertrag erneuert')",
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
required: ["targetId", "newTitle", "newContent"],
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: "knowmind.recall_at_time",
|
|
148
|
-
description:
|
|
149
|
-
"Recall mit Zeitfilter: liefert nur Erinnerungen, die zum gegebenen Zeitpunkt gültig waren. Antwort auf Fragen wie 'Was wussten wir am 14. März über den Kunden?' — der Knowmind-Vorteil gegenüber reinen Vector-Stores ohne Validity-Tracking.",
|
|
150
|
-
inputSchema: {
|
|
151
|
-
type: "object",
|
|
152
|
-
properties: {
|
|
153
|
-
query: { type: "string", description: "Natürlichsprachliche Frage" },
|
|
154
|
-
asOf: {
|
|
155
|
-
type: "string",
|
|
156
|
-
description:
|
|
157
|
-
"ISO-8601-Zeitstempel des Bezugszeitpunkts (Default: jetzt). Beispiel: '2026-03-14T00:00:00Z'",
|
|
158
|
-
},
|
|
159
|
-
k: { type: "integer", minimum: 1, maximum: 25, default: 5 },
|
|
160
|
-
},
|
|
161
|
-
required: ["query"],
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
];
|
|
26
|
+
async function forwardToServer(method, params) {
|
|
27
|
+
const { apiUrl, token } = loadConfig();
|
|
28
|
+
if (!token)
|
|
29
|
+
throw new Error("Knowmind: kein Token konfiguriert. `knowmind login` zuerst.");
|
|
165
30
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
async function restCall(apiUrl, token, path, init) {
|
|
169
|
-
const r = await fetch(`${apiUrl}${path}`, {
|
|
170
|
-
...init,
|
|
31
|
+
const r = await fetch(`${apiUrl}/api/mcp/v1`, {
|
|
32
|
+
method: "POST",
|
|
171
33
|
headers: {
|
|
172
34
|
"content-type": "application/json",
|
|
173
35
|
authorization: `Bearer ${token}`,
|
|
174
|
-
...(init?.headers ?? {}),
|
|
175
36
|
},
|
|
37
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
|
|
176
38
|
});
|
|
177
39
|
let data;
|
|
178
40
|
try {
|
|
179
41
|
data = await r.json();
|
|
180
42
|
} catch {
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
if (!r.ok) {
|
|
43
|
+
// HTTP-Status ohne parsebaren JSON-Body sauber als JSON-RPC-Fehler melden.
|
|
184
44
|
return {
|
|
185
45
|
error: {
|
|
186
|
-
code: -32000,
|
|
187
|
-
message:
|
|
188
|
-
|
|
46
|
+
code: r.ok ? -32700 : -32000,
|
|
47
|
+
message: r.ok
|
|
48
|
+
? "Knowmind-Server lieferte kein gültiges JSON."
|
|
49
|
+
: `Knowmind-Server: HTTP ${r.status}`,
|
|
189
50
|
},
|
|
190
51
|
};
|
|
191
52
|
}
|
|
192
|
-
return
|
|
193
|
-
result: {
|
|
194
|
-
content: [{ type: "text", text: JSON.stringify(data) }],
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async function callRestTool(apiUrl, token, name, args) {
|
|
200
|
-
switch (name) {
|
|
201
|
-
case "knowmind.store": {
|
|
202
|
-
const { title, content } = args;
|
|
203
|
-
if (!title || !content) {
|
|
204
|
-
return {
|
|
205
|
-
error: {
|
|
206
|
-
code: -32602,
|
|
207
|
-
message: "knowmind.store benötigt title und content.",
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
return await restCall(apiUrl, token, "/api/documents", {
|
|
212
|
-
method: "POST",
|
|
213
|
-
body: JSON.stringify({ title, content }),
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
case "knowmind.link": {
|
|
217
|
-
const { fromId, toId, relType } = args;
|
|
218
|
-
if (!fromId || !toId || !relType) {
|
|
219
|
-
return {
|
|
220
|
-
error: {
|
|
221
|
-
code: -32602,
|
|
222
|
-
message: "knowmind.link benötigt fromId, toId, relType.",
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
return await restCall(apiUrl, token, "/api/graph/relations", {
|
|
227
|
-
method: "POST",
|
|
228
|
-
body: JSON.stringify({ fromId, toId, relType }),
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
case "knowmind.unlink": {
|
|
232
|
-
const { fromId, toId, relType } = args;
|
|
233
|
-
if (!fromId || !toId || !relType) {
|
|
234
|
-
return {
|
|
235
|
-
error: {
|
|
236
|
-
code: -32602,
|
|
237
|
-
message: "knowmind.unlink benötigt fromId, toId, relType.",
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
const params = new URLSearchParams({ fromId, toId, relType });
|
|
242
|
-
return await restCall(apiUrl, token, `/api/graph/relations?${params.toString()}`, {
|
|
243
|
-
method: "DELETE",
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
case "knowmind.relations": {
|
|
247
|
-
const { memoryId } = args;
|
|
248
|
-
if (!memoryId) {
|
|
249
|
-
return {
|
|
250
|
-
error: {
|
|
251
|
-
code: -32602,
|
|
252
|
-
message: "knowmind.relations benötigt memoryId.",
|
|
253
|
-
},
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
const params = new URLSearchParams({ memoryId });
|
|
257
|
-
return await restCall(apiUrl, token, `/api/graph/relations?${params.toString()}`, {
|
|
258
|
-
method: "GET",
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
default:
|
|
262
|
-
return {
|
|
263
|
-
error: { code: -32601, message: `Unknown tool: ${name}` },
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
async function forwardToServer(method, params) {
|
|
269
|
-
const { apiUrl, token } = loadConfig();
|
|
270
|
-
if (!token)
|
|
271
|
-
throw new Error("Knowmind: kein Token konfiguriert. `knowmind login` zuerst.");
|
|
272
|
-
|
|
273
|
-
// Tools, die nicht über den MCP-Endpoint, sondern direkt gegen die
|
|
274
|
-
// REST-Schnittstelle laufen (Anlegen + Graph-Beziehungen).
|
|
275
|
-
if (
|
|
276
|
-
method === "tools/call" &&
|
|
277
|
-
params &&
|
|
278
|
-
typeof params.name === "string" &&
|
|
279
|
-
["knowmind.store", "knowmind.link", "knowmind.unlink", "knowmind.relations"].includes(
|
|
280
|
-
params.name,
|
|
281
|
-
)
|
|
282
|
-
) {
|
|
283
|
-
return await callRestTool(apiUrl, token, params.name, params.arguments ?? {});
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const r = await fetch(`${apiUrl}/api/mcp/v1`, {
|
|
287
|
-
method: "POST",
|
|
288
|
-
headers: {
|
|
289
|
-
"content-type": "application/json",
|
|
290
|
-
authorization: `Bearer ${token}`,
|
|
291
|
-
},
|
|
292
|
-
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
|
|
293
|
-
});
|
|
294
|
-
return await r.json();
|
|
53
|
+
return data;
|
|
295
54
|
}
|
|
296
55
|
|
|
297
56
|
function write(obj) {
|
|
@@ -337,7 +96,7 @@ async function probeAuth() {
|
|
|
337
96
|
jsonrpc: "2.0",
|
|
338
97
|
id: 1,
|
|
339
98
|
method: "tools/call",
|
|
340
|
-
params: { name: "
|
|
99
|
+
params: { name: "knowmind_health", arguments: {} },
|
|
341
100
|
}),
|
|
342
101
|
});
|
|
343
102
|
if (!r.ok) {
|
|
@@ -366,8 +125,7 @@ async function probeAuth() {
|
|
|
366
125
|
|
|
367
126
|
export async function runStdioServer() {
|
|
368
127
|
// Auth einmal am Start prüfen. Das Ergebnis cachen — der MCP-Client
|
|
369
|
-
// soll sofort beim initialize wissen, ob die Verbindung wirklich
|
|
370
|
-
// steht.
|
|
128
|
+
// soll sofort beim initialize wissen, ob die Verbindung wirklich steht.
|
|
371
129
|
const auth = await probeAuth();
|
|
372
130
|
if (!auth.ok) {
|
|
373
131
|
process.stderr.write(`[knowmind] AUTH-FEHLER: ${auth.reason}\n`);
|
|
@@ -389,87 +147,60 @@ export async function runStdioServer() {
|
|
|
389
147
|
continue;
|
|
390
148
|
}
|
|
391
149
|
try {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
},
|
|
416
|
-
});
|
|
417
|
-
break;
|
|
418
|
-
case "tools/list":
|
|
419
|
-
if (!auth.ok) {
|
|
420
|
-
write({
|
|
421
|
-
jsonrpc: "2.0",
|
|
422
|
-
id: req.id ?? null,
|
|
423
|
-
error: {
|
|
424
|
-
code: -32001,
|
|
425
|
-
message: `Knowmind nicht verbunden: ${auth.reason}`,
|
|
426
|
-
},
|
|
427
|
-
});
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
write({
|
|
431
|
-
jsonrpc: "2.0",
|
|
432
|
-
id: req.id ?? null,
|
|
433
|
-
result: { tools: KNOWMIND_TOOLS },
|
|
434
|
-
});
|
|
435
|
-
break;
|
|
436
|
-
case "tools/call": {
|
|
437
|
-
if (!auth.ok) {
|
|
438
|
-
write({
|
|
439
|
-
jsonrpc: "2.0",
|
|
440
|
-
id: req.id ?? null,
|
|
441
|
-
error: {
|
|
442
|
-
code: -32001,
|
|
443
|
-
message: `Knowmind nicht verbunden: ${auth.reason}`,
|
|
444
|
-
},
|
|
445
|
-
});
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
const upstream = await forwardToServer(req.method, req.params);
|
|
449
|
-
// Upstream-Response hat eigene jsonrpc/id-Felder — die müssen
|
|
450
|
-
// durch die Client-id ersetzt werden, damit Claude Code, Codex
|
|
451
|
-
// und Gemini ihre Anfragen korrekt zuordnen können.
|
|
452
|
-
const response = {
|
|
453
|
-
jsonrpc: "2.0",
|
|
454
|
-
id: req.id ?? null,
|
|
455
|
-
};
|
|
456
|
-
if (upstream && typeof upstream === "object" && "result" in upstream) {
|
|
457
|
-
response.result = upstream.result;
|
|
458
|
-
} else if (upstream && typeof upstream === "object" && "error" in upstream) {
|
|
459
|
-
response.error = upstream.error;
|
|
460
|
-
} else {
|
|
461
|
-
response.result = upstream;
|
|
462
|
-
}
|
|
463
|
-
write(response);
|
|
464
|
-
break;
|
|
150
|
+
// Notifications (kein id-Feld) bekommen per JSON-RPC keine Antwort.
|
|
151
|
+
const isNotification = req.id === undefined && typeof req.method === "string" && req.method.startsWith("notifications/");
|
|
152
|
+
if (isNotification) continue;
|
|
153
|
+
|
|
154
|
+
if (!auth.ok && req.method !== "ping") {
|
|
155
|
+
// Initialize (und alles weitere) FEHLSCHLAGEN lassen, damit der
|
|
156
|
+
// MCP-Client „connected" nicht fälschlich anzeigt. Claude Code,
|
|
157
|
+
// Codex und Cursor werten -32001 als harte Connection-Failure.
|
|
158
|
+
write({
|
|
159
|
+
jsonrpc: "2.0",
|
|
160
|
+
id: req.id ?? null,
|
|
161
|
+
error: {
|
|
162
|
+
code: -32001,
|
|
163
|
+
message: `Knowmind nicht verbunden: ${auth.reason}`,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (LOCAL_METHODS.has(req.method)) {
|
|
170
|
+
if (req.method === "ping") {
|
|
171
|
+
write({ jsonrpc: "2.0", id: req.id ?? null, result: {} });
|
|
172
|
+
continue;
|
|
465
173
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
174
|
+
// initialize
|
|
175
|
+
write({
|
|
176
|
+
jsonrpc: "2.0",
|
|
177
|
+
id: req.id ?? null,
|
|
178
|
+
result: {
|
|
179
|
+
protocolVersion: "2025-06-18",
|
|
180
|
+
serverInfo: { name: "knowmind", version: VERSION },
|
|
181
|
+
capabilities: { tools: {}, prompts: {} },
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Alles andere (tools/list, tools/call, prompts/list, prompts/get, …)
|
|
188
|
+
// geht 1:1 an den Server — Definitionen bleiben dadurch immer synchron.
|
|
189
|
+
const upstream = await forwardToServer(req.method, req.params);
|
|
190
|
+
// Upstream-Response hat eigene jsonrpc/id-Felder — die müssen durch
|
|
191
|
+
// die Client-id ersetzt werden, damit der Client korrekt zuordnet.
|
|
192
|
+
const response = {
|
|
193
|
+
jsonrpc: "2.0",
|
|
194
|
+
id: req.id ?? null,
|
|
195
|
+
};
|
|
196
|
+
if (upstream && typeof upstream === "object" && "result" in upstream) {
|
|
197
|
+
response.result = upstream.result;
|
|
198
|
+
} else if (upstream && typeof upstream === "object" && "error" in upstream) {
|
|
199
|
+
response.error = upstream.error;
|
|
200
|
+
} else {
|
|
201
|
+
response.result = upstream;
|
|
472
202
|
}
|
|
203
|
+
write(response);
|
|
473
204
|
} catch (e) {
|
|
474
205
|
write({
|
|
475
206
|
jsonrpc: "2.0",
|