feat: MCP-Server für remote_execute + Inline-Choice-UI
- Python MCP-Server (stdio, JSON-RPC 2.0) für remote_execute via Claude CLI - Interner API-Endpoint /api/internal/remote-execute mit Token-Auth - MCP-Config wird automatisch generiert wenn Remote-Verbindung vorhanden - Auth-Middleware: /api/internal/ von Auth ausgenommen - Frontend: :::ASK_USER_CHOICE::: Blöcke als interaktive Buttons rendern - Streaming: Unvollständige Choice-Blöcke werden während des Streams versteckt - tool-ui.js: MCP-Tool-Namen generisch normalisieren (mcp__server__tool → tool) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
ee0b817f25
commit
3b068a7866
14 files changed
+576
-6
No files matched your search
@@ -0,0 +1,126 @@
|
||||
# Plan: MCP-Server für `remote_execute` in der CLI
|
||||
|
||||
## Übersicht
|
||||
|
||||
Ein eigener MCP-Server (Model Context Protocol, stdio-basiert) der `remote_execute` als Tool für die Claude Code CLI exposed. Die CLI erkennt MCP-Tools nativ und kann sie wie Built-in-Tools verwenden.
|
||||
|
||||
## Architektur
|
||||
|
||||
```
|
||||
Claude CLI ←→ MCP-Server (stdio) ←→ gott HTTP-API ←→ RemoteEndpoint → SSH/Exec
|
||||
```
|
||||
|
||||
## Komponenten
|
||||
|
||||
### 1. MCP-Server: `scripts/mcp-server` (oder `Services/McpServer.cs`)
|
||||
|
||||
**Variante A: Standalone Script (Python/Node/Bash+jq)**
|
||||
- Leichtgewichtig, unabhängig von .NET Runtime
|
||||
- Kommuniziert über stdin/stdout (JSON-RPC 2.0)
|
||||
- Ruft gott's interne HTTP-API auf
|
||||
|
||||
**Variante B: .NET Console App**
|
||||
- Kann ToolService/RemoteService direkt referenzieren
|
||||
- Gleiche Codebase, keine API-Zwischenschicht nötig
|
||||
- Aber: Eigener Prozess, muss separat gebaut werden
|
||||
|
||||
**Empfehlung: Variante A** – ein einfaches Script das die gott-API aufruft. Minimaler Overhead, keine Build-Abhängigkeit.
|
||||
|
||||
### 2. Interner API-Endpoint
|
||||
|
||||
```
|
||||
POST /api/internal/remote-execute
|
||||
Authorization: (interner Token oder localhost-only)
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"command": "docker ps",
|
||||
"sessionId": "abc123", // für Zuordnung zur Chat-Session
|
||||
"serverId": "optional" // falls mehrere Server
|
||||
}
|
||||
```
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"exitCode": 0,
|
||||
"stdout": "CONTAINER ID IMAGE ...",
|
||||
"stderr": "",
|
||||
"durationMs": 234
|
||||
}
|
||||
```
|
||||
|
||||
### 3. MCP-Server Konfiguration
|
||||
|
||||
In `.claude/settings.json` oder per `--mcp-config`:
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"gott-remote": {
|
||||
"command": "/app/gott/scripts/mcp-remote-execute",
|
||||
"type": "stdio",
|
||||
"env": {
|
||||
"GOTT_API_URL": "http://localhost:5000",
|
||||
"GOTT_SESSION_ID": "${SESSION_ID}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. MCP-Protokoll (stdio, JSON-RPC 2.0)
|
||||
|
||||
**Tool-Definition (tools/list Response):**
|
||||
```json
|
||||
{
|
||||
"name": "remote_execute",
|
||||
"description": "Führt einen Befehl auf dem Remote-Server aus (via SSH oder lokal)",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "Der auszuführende Befehl"
|
||||
}
|
||||
},
|
||||
"required": ["command"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Tool-Call (tools/call):**
|
||||
- MCP-Server empfängt JSON-RPC Request
|
||||
- Ruft `POST /api/internal/remote-execute` auf
|
||||
- Gibt stdout/stderr als Text-Content zurück
|
||||
|
||||
### 5. Integration in ClaudeCliService
|
||||
|
||||
- MCP-Server-Config wird beim CLI-Start übergeben
|
||||
- `--mcp-config /tmp/gott-mcp-{sessionId}.json` oder globale Config
|
||||
- SessionId/ServerId werden als Environment-Variablen an den MCP-Server übergeben
|
||||
|
||||
### 6. AnthropicService: CLI-Aufruf anpassen
|
||||
|
||||
In `StreamChatViaCli` den MCP-Config-Pfad generieren und an `ChatStreamingAsync` übergeben:
|
||||
```csharp
|
||||
var mcpConfig = GenerateMcpConfig(sessionId, serverId);
|
||||
var mcpConfigPath = WriteTempMcpConfig(mcpConfig);
|
||||
// CLI-Aufruf mit --mcp-config mcpConfigPath
|
||||
```
|
||||
|
||||
## Dateien
|
||||
|
||||
| Datei | Aktion | Beschreibung |
|
||||
|-------|--------|-------------|
|
||||
| `scripts/mcp-remote-execute` | **NEU** | MCP-Server Script (stdio) |
|
||||
| `Endpoints/InternalEndpoint.cs` | **NEU** | Interner API-Endpoint für remote-execute |
|
||||
| `Services/ClaudeCliService.cs` | **EDIT** | MCP-Config übergeben |
|
||||
| `Services/AnthropicService.cs` | **EDIT** | MCP-Config generieren |
|
||||
| `.claude/settings.json` | **EDIT** | MCP-Server registrieren (oder dynamisch per --mcp-config) |
|
||||
|
||||
## Offene Fragen
|
||||
|
||||
1. **Script-Sprache**: Python (weit verbreitet), Node (npm-Ökosystem), oder Shell+curl+jq (keine Runtime-Abhängigkeit)?
|
||||
2. **Auth für internen Endpoint**: Nur localhost erlauben? Oder interner Token?
|
||||
3. **Server-Auswahl**: Wenn mehrere Remote-Server konfiguriert sind – soll der MCP-Server alle als separate Tools exposen oder einen Default verwenden?
|
||||
4. **Tool-Ergebnis-Mapping**: Wie sollen remote_execute-Results in der gott-UI angezeigt werden? Als normales Tool-Result oder speziell formatiert?
|
||||
Reference in new issue
Block a user