MCP-Docs Architektur
Verzeichnisstruktur und Komponenten des MCP-Docs Servers.
Verzeichnisstruktur
/var/www/mcp-servers/mcp_docs/
├── server.py # Entry Point (FastMCP)
├── config.py # Konfiguration
├── .env # Credentials (DB_HOST, DB_USER, etc.)
├── requirements.txt # Dependencies (mcp, pymysql, python-dotenv)
├── venv/ # Python Virtual Environment
├── __pycache__/ # Python Cache
│
├── domain/
│ ├── __init__.py
│ └── dokumentation.py # Entities (Dokumentation, DocStatus, LogEntry)
│
├── infrastructure/
│ ├── __init__.py
│ └── docs_repository.py # CRUD-Operationen (nutzt shared.db_connection)
│
└── tools/
├── __init__.py
└── docs_tools/ # MCP-Tools Verzeichnis
├── __init__.py
└── tools.py # 9 MCP-Tools
Hinweis: Die Datenbankverbindung und Logging werden aus dem shared-Modul importiert (/var/www/mcp-servers/shared/), nicht lokal definiert.
Layer-Architektur
| Layer | Verantwortung | Dateien |
|---|---|---|
| Tools | MCP-Tool-Definitionen | tools/docs_tools/ |
| Domain | Entities, Dataclasses | domain/dokumentation.py |
| Infrastructure | Repository | infrastructure/docs_repository.py |
| Shared | DB-Connection, Logging | /var/www/mcp-servers/shared/ |
Komponenten
server.py
Entry Point mit FastMCP-Initialisierung:
from mcp.server.fastmcp import FastMCP
from tools.docs_tools import register_docs_tools
mcp = FastMCP("mcp-docs", instructions="...")
register_docs_tools(mcp)
if __name__ == "__main__":
mcp.run(transport="stdio")
domain/dokumentation.py
Dataclasses für Dokumentations-Entities:
@dataclass
class Dokumentation:
id: int
parent_id: Optional[int]
slug: str
path: str
title: str
description: Optional[str]
content: str
status: str # draft, published, archived
sort_order: int
depth: int
created_at: datetime
updated_at: datetime
def to_dict(self) -> dict
def to_dict_compact(self) -> dict # ohne content
infrastructure/docs_repository.py
CRUD-Operationen auf ki_dev.dokumentation:
find_by_id(),find_by_path()find_all()mit Filternfind_children()- Kind-Dokumenteget_hierarchy()- Vollständiger Baumget_breadcrumb()- Pfad zum Dokumentcreate(),update(),delete()move()- Parent ändernget_statistics()
Datenbank-Schema
-- ki_dev.dokumentation
CREATE TABLE dokumentation (
id INT AUTO_INCREMENT PRIMARY KEY,
parent_id INT DEFAULT NULL,
depth TINYINT UNSIGNED DEFAULT 0,
sort_order INT UNSIGNED DEFAULT 0,
slug VARCHAR(100) NOT NULL,
path VARCHAR(500) NOT NULL UNIQUE,
title VARCHAR(200) NOT NULL,
description VARCHAR(500),
content LONGTEXT NOT NULL,
content_format ENUM('html','markdown') DEFAULT 'html',
status ENUM('draft','published','archived') DEFAULT 'published',
version INT UNSIGNED DEFAULT 1,
created_by VARCHAR(100) DEFAULT 'system',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_by VARCHAR(100),
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (parent_id) REFERENCES dokumentation(id) ON DELETE SET NULL
);
Hierarchie-Konzept
| Feld | Beschreibung | Beispiel |
|---|---|---|
parent_id | Verweis auf Eltern-Dokument | 1 (oder NULL für Root) |
depth | Tiefe im Baum | 0=Root, 1=Kapitel, 2=Unterkapitel |
path | Vollständiger URL-Pfad | /server/ssh |
slug | URL-Segment | ssh |
sort_order | Sortierung innerhalb Parent | 1, 2, 3... |
Datenfluss
Claude Code
↓ MCP Tool Call
FastMCP (server.py)
↓ docs_get()
docs_tools.py
↓ Repository
docs_repository.py
↓ SQL (shared.db_connection)
ki_dev.dokumentation + ki_protokoll.mcp_log
Besonderheiten
- Zwei Datenbanken: Daten in ki_dev, Logging in ki_protokoll
- Shared Module: DB-Connection und Logging aus /var/www/mcp-servers/shared/
- Pfad-Berechnung: Automatisch aus Parent-Pfad + Slug
- Depth-Berechnung: Parent-Depth + 1
- Token-Optimierung:
to_dict_compact()ohne Content