MCP-Tasks Installation

Aktualisiert: 2025-12-31

Setup, Registrierung und Test des MCP-Tasks Servers.

Voraussetzungen

1. Verzeichnis erstellen

mkdir -p /var/www/mcp-servers/mcp_tasks
cd /var/www/mcp-servers/mcp_tasks

2. Virtual Environment

python3 -m venv venv
source venv/bin/activate
pip install mcp pymysql python-dotenv requests pyyaml

3. Dateien erstellen

Siehe Architektur für vollständige Verzeichnisstruktur.

# Struktur
/var/www/mcp-servers/mcp_tasks/
├── server.py               # Hauptdatei
├── config.py               # Konfiguration
├── requirements.txt
├── venv/
├── domain/
│   ├── __init__.py
│   └── contracts.py        # Dataclasses
├── infrastructure/
│   ├── __init__.py
│   └── task_repository.py  # CRUD-Operationen
├── tools/
│   ├── __init__.py
│   ├── task_tools.py
│   └── quality_tools.py
└── validators/
    ├── __init__.py
    └── workflow_validator.py

4. Datenbank vorbereiten (ki_dev)

Task-Tabellen erstellen

-- Haupttabelle
CREATE TABLE IF NOT EXISTS tasks (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    uuid VARCHAR(36) NOT NULL,
    title VARCHAR(255) NOT NULL,
    description TEXT DEFAULT NULL,
    type ENUM('human_task', 'ai_task', 'mixed') NOT NULL DEFAULT 'human_task',
    status ENUM('pending', 'in_progress', 'completed', 'failed', 'cancelled') NOT NULL DEFAULT 'pending',
    created_by VARCHAR(100) NOT NULL,
    created_by_type ENUM('human', 'ai') NOT NULL DEFAULT 'human',
    parent_task_id BIGINT UNSIGNED DEFAULT NULL,
    due_date DATETIME DEFAULT NULL,
    created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
    updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    completed_at DATETIME(6) DEFAULT NULL,
    metadata LONGTEXT CHECK (JSON_VALID(metadata)),
    UNIQUE KEY uk_uuid (uuid),
    INDEX idx_status (status),
    INDEX idx_created_by (created_by),
    INDEX idx_type (type),
    INDEX idx_parent_task (parent_task_id),
    INDEX idx_created_at (created_at),
    INDEX idx_status_created (status, created_at),
    CONSTRAINT fk_parent_task FOREIGN KEY (parent_task_id) REFERENCES tasks(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Zuweisungen
CREATE TABLE IF NOT EXISTS task_assignments (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    task_id BIGINT UNSIGNED NOT NULL,
    assignee VARCHAR(100) NOT NULL,
    assignee_type ENUM('human', 'ollama', 'claude', 'anthropic_api') NOT NULL,
    model_name VARCHAR(100) DEFAULT NULL,
    assigned_by VARCHAR(100) NOT NULL,
    assigned_by_type ENUM('human', 'ai') NOT NULL DEFAULT 'human',
    status ENUM('pending', 'accepted', 'rejected', 'in_progress', 'completed') NOT NULL DEFAULT 'pending',
    assigned_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
    accepted_at DATETIME(6) DEFAULT NULL,
    completed_at DATETIME(6) DEFAULT NULL,
    notes TEXT DEFAULT NULL,
    INDEX idx_task_id (task_id),
    INDEX idx_assignee (assignee),
    INDEX idx_assignee_type (assignee_type),
    INDEX idx_status (status),
    INDEX idx_assigned_at (assigned_at),
    CONSTRAINT fk_assignment_task FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Ergebnisse
CREATE TABLE IF NOT EXISTS task_results (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    task_id BIGINT UNSIGNED NOT NULL,
    assignment_id BIGINT UNSIGNED DEFAULT NULL,
    executor VARCHAR(100) NOT NULL,
    executor_type ENUM('human', 'ollama', 'claude', 'anthropic_api') NOT NULL,
    model_name VARCHAR(100) DEFAULT NULL,
    request TEXT DEFAULT NULL,
    response LONGTEXT DEFAULT NULL,
    request_timestamp DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
    response_timestamp DATETIME(6) DEFAULT NULL,
    duration_ms INT UNSIGNED DEFAULT NULL,
    tokens_input INT UNSIGNED DEFAULT NULL,
    tokens_output INT UNSIGNED DEFAULT NULL,
    tokens_total INT UNSIGNED DEFAULT NULL,
    cost_usd DECIMAL(10,6) DEFAULT NULL,
    status ENUM('success', 'error', 'partial') NOT NULL DEFAULT 'success',
    error_message TEXT DEFAULT NULL,
    created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
    INDEX idx_task_id (task_id),
    INDEX idx_assignment_id (assignment_id),
    INDEX idx_executor (executor),
    INDEX idx_executor_type (executor_type),
    INDEX idx_model (model_name),
    INDEX idx_status (status),
    INDEX idx_created_at (created_at),
    CONSTRAINT fk_result_task FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE,
    CONSTRAINT fk_result_assignment FOREIGN KEY (assignment_id) REFERENCES task_assignments(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

5. In Claude Code registrieren

User-Scope (Global)

Registrierung für alle Projekte:

claude mcp add mcp-tasks \
  /var/www/mcp-servers/mcp_tasks/venv/bin/python \
  /var/www/mcp-servers/mcp_tasks/server.py

Projekt-Scope (Lokal)

Registrierung nur für ein bestimmtes Projekt:

cd /var/www
claude mcp add mcp-tasks \
  /var/www/mcp-servers/mcp_tasks/venv/bin/python \
  /var/www/mcp-servers/mcp_tasks/server.py

6. Registrierung prüfen

# Liste aller MCP Server
claude mcp list

# Erwartete Ausgabe:
# mcp-tasks: connected

# In Claude Code Session
/mcp

7. Tools testen

# Task-Management
tasks_list()
tasks_statistics()

# Task erstellen und ausführen
tasks_create(title="Test-Task", type="ai_task")
tasks_execute(id=1, model="mistral")

# Quality-Checks
contracts_list()
quality_check(path="/var/www/dev.campus.systemische-tools.de/src")

Ollama-Integration

Für tasks_execute muss Ollama laufen:

# Ollama Status prüfen
ollama list

# Modell laden (falls nicht vorhanden)
ollama pull mistral

# Test
curl http://localhost:11434/api/tags

Troubleshooting

Server startet nicht

# Dependencies prüfen
pip list | grep -E "mcp|pymysql|dotenv"

# Python Version
python --version  # Muss 3.10+ sein

# Import-Fehler finden
python -c "from tools.task_tools import register_task_tools"

Verbindungsfehler

# DB-Verbindung testen (über MCP)
tasks_list(limit=1)

Ollama-Fehler

# Ollama Status
systemctl status ollama

# API erreichbar?
curl http://localhost:11434/api/tags

# Modell vorhanden?
ollama list | grep mistral

Updates

# Dependencies aktualisieren
cd /var/www/mcp-servers/mcp_tasks
source venv/bin/activate
pip install --upgrade mcp pymysql python-dotenv requests pyyaml

# Server wird beim nächsten Claude Code Start neu geladen

Deinstallation

# Aus Claude Code entfernen
claude mcp remove mcp-tasks

# Verzeichnis löschen (optional)
rm -rf /var/www/mcp-servers/mcp_tasks

# Tabellen behalten oder löschen (optional)
DROP TABLE task_results;
DROP TABLE task_assignments;
DROP TABLE tasks;

Verwandte Themen