{
"event": "PreToolUse",
"tool_name": "mcp__mcp-docs__docs_update",
"tool_input": {
"id": 44,
"content": "<nav class=\"breadcrumb\">\n <a href=\"\/docs\">Dokumentation<\/a> » <a href=\"\/docs\/mcp\/mcp-db\">MCP-DB<\/a> » Infrastructure\n<\/nav>\n\n<h1>MCP-DB Infrastructure<\/h1>\n<p>Database Connection Pool für sichere Datenbankzugriffe.<\/p>\n\n<h2>DatabaseConnection<\/h2>\n<p>Singleton Connection Pool für Datenbankzugriffe.<\/p>\n\n<pre><code>\"\"\"Database Connection Pool\"\"\"\nfrom contextlib import contextmanager\nimport mysql.connector\nfrom mysql.connector import pooling\nfrom config import Config\n\nclass DatabaseConnection:\n \"\"\"Singleton Connection Pool - SRP: Nur Verbindungsmanagement\"\"\"\n\n _pool = None\n\n @classmethod\n def get_pool(cls):\n \"\"\"Erstellt oder gibt existierenden Connection Pool zurück\"\"\"\n if cls._pool is None:\n cls._pool = pooling.MySQLConnectionPool(\n pool_name=\"mcp_pool\",\n pool_size=5,\n host=Config.DB_HOST,\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n charset=\"utf8mb4\",\n connection_timeout=10,\n autocommit=True,\n )\n return cls._pool\n\n @classmethod\n @contextmanager\n def get_connection(cls, database: str):\n \"\"\"\n Context Manager für DB Connection.\n\n Args:\n database: Datenbankname (bereits validiert)\n \"\"\"\n conn = cls.get_pool().get_connection()\n try:\n # Datenbank wechseln (USE statement)\n cursor = conn.cursor()\n cursor.execute(f\"USE {database}\")\n\n # Query Timeout setzen (MariaDB: max_statement_time in Sekunden)\n try:\n cursor.execute(\n f\"SET SESSION max_statement_time = {Config.QUERY_TIMEOUT_SEC}\"\n )\n except Exception:\n pass # Falls Variable nicht unterstützt wird\n cursor.close()\n\n yield conn\n finally:\n conn.close()<\/code><\/pre>\n\n<h3>Pool-Konfiguration<\/h3>\n<table>\n <tr><th>Parameter<\/th><th>Wert<\/th><th>Beschreibung<\/th><\/tr>\n <tr><td>pool_size<\/td><td>5<\/td><td>Maximale Verbindungen<\/td><\/tr>\n <tr><td>connection_timeout<\/td><td>10<\/td><td>Verbindungs-Timeout in Sekunden<\/td><\/tr>\n <tr><td>autocommit<\/td><td>True<\/td><td>Automatisches Commit<\/td><\/tr>\n <tr><td>charset<\/td><td>utf8mb4<\/td><td>Unicode-Support<\/td><\/tr>\n<\/table>\n\n<h3>Query Timeout<\/h3>\n<p>Bei jeder Verbindung wird <code>max_statement_time<\/code> gesetzt (MariaDB-spezifisch):<\/p>\n<pre><code>SET SESSION max_statement_time = 30 # 30 Sekunden<\/code><\/pre>\n<p><strong>Hinweis:<\/strong> MySQL verwendet <code>max_execution_time<\/code> in Millisekunden, MariaDB verwendet <code>max_statement_time<\/code> in Sekunden.<\/p>\n\n<h2>Logging<\/h2>\n<p>Alle MCP-DB Operationen werden direkt in <code>ki_dev.mcp_log<\/code> protokolliert. Das Logging erfolgt inline in den Tool-Implementierungen, nicht über eine separate Logger-Klasse.<\/p>\n\n<h3>Logging-Ablauf<\/h3>\n<ol>\n <li>Tool wird aufgerufen (z.B. db_select)<\/li>\n <li>Query wird validiert<\/li>\n <li>Query wird ausgeführt<\/li>\n <li>Ergebnis wird in mcp_log geschrieben<\/li>\n<\/ol>\n\n<h3>mcp_log Tabelle<\/h3>\n<pre><code>CREATE TABLE IF NOT EXISTS mcp_log (\n id INT AUTO_INCREMENT PRIMARY KEY,\n timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n client_name VARCHAR(50) NOT NULL DEFAULT 'mcp-db',\n request TEXT,\n status ENUM('success', 'error', 'denied') NOT NULL,\n duration_ms INT DEFAULT 0,\n error_message TEXT,\n INDEX idx_timestamp (timestamp),\n INDEX idx_status (status)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;<\/code><\/pre>\n\n<h3>Log-Felder<\/h3>\n<table>\n <tr><th>Feld<\/th><th>Typ<\/th><th>Beschreibung<\/th><\/tr>\n <tr><td>timestamp<\/td><td>DATETIME<\/td><td>Zeitstempel der Operation<\/td><\/tr>\n <tr><td>client_name<\/td><td>VARCHAR(50)<\/td><td>Client-Identifikation (mcp-db)<\/td><\/tr>\n <tr><td>request<\/td><td>TEXT<\/td><td>Query-Text (gekürzt auf 200 Zeichen)<\/td><\/tr>\n <tr><td>status<\/td><td>ENUM<\/td><td>success, error, denied<\/td><\/tr>\n <tr><td>duration_ms<\/td><td>INT<\/td><td>Ausführungsdauer in Millisekunden<\/td><\/tr>\n <tr><td>error_message<\/td><td>TEXT<\/td><td>Fehlerdetails (bei Fehlern)<\/td><\/tr>\n<\/table>\n\n<h2>Nutzung<\/h2>\n<pre><code># DatabaseConnection mit Context Manager\nwith DatabaseConnection.get_connection(\"ki_dev\") as conn:\n cursor = conn.cursor(dictionary=True)\n cursor.execute(\"SELECT * FROM mcp_log LIMIT 10\")\n rows = cursor.fetchall()\n cursor.close()\n\n# Log-Eintrag schreiben (inline in Tool)\ncursor.execute(\n \"\"\"INSERT INTO mcp_log\n (client_name, request, status, duration_ms, error_message)\n VALUES (%s, %s, %s, %s, %s)\"\"\",\n (\"mcp-db\", query[:200], \"success\", duration_ms, None)\n)<\/code><\/pre>\n\n<h2>Verzeichnisstruktur<\/h2>\n<pre><code>\/var\/www\/mcp-servers\/mcp_db\/infrastructure\/\n├── __init__.py\n└── db_connection.py # DatabaseConnection Klasse<\/code><\/pre>\n\n<h2>Verwandte Kapitel<\/h2>\n<ul>\n <li><a href=\"\/docs\/mcp\/mcp-db-security\">Sicherheit<\/a> - Separate DB-User<\/li>\n <li><a href=\"\/docs\/mcp\/mcp-db-contracts\">Contracts<\/a> - Datenstrukturen<\/li>\n <li><a href=\"\/docs\/mcp\/mcp-db-config\">Konfiguration<\/a> - Environment Variables<\/li>\n<\/ul>"
}
}
{
"tool_response": [
{
"type": "text",
"text": "{\n \"success\": true,\n \"doc\": {\n \"id\": 44,\n \"parent_id\": 36,\n \"slug\": \"mcp-db-infrastructure\",\n \"path\": \"\/mcp\/mcp-db\/mcp-db-infrastructure\",\n \"title\": \"Infrastructure\",\n \"description\": \"Connection Pool und Protokoll Logger.\",\n \"content\": \"<nav class=\\\"breadcrumb\\\">\\n <a href=\\\"\/docs\\\">Dokumentation<\/a> » <a href=\\\"\/docs\/mcp\/mcp-db\\\">MCP-DB<\/a> » Infrastructure\\n<\/nav>\\n\\n<h1>MCP-DB Infrastructure<\/h1>\\n<p>Database Connection Pool für sichere Datenbankzugriffe.<\/p>\\n\\n<h2>DatabaseConnection<\/h2>\\n<p>Singleton Connection Pool für Datenbankzugriffe.<\/p>\\n\\n<pre><code>\\\"\\\"\\\"Database Connection Pool\\\"\\\"\\\"\\nfrom contextlib import contextmanager\\nimport mysql.connector\\nfrom mysql.connector import pooling\\nfrom config import Config\\n\\nclass DatabaseConnection:\\n \\\"\\\"\\\"Singleton Connection Pool - SRP: Nur Verbindungsmanagement\\\"\\\"\\\"\\n\\n _pool = None\\n\\n @classmethod\\n def get_pool(cls):\\n \\\"\\\"\\\"Erstellt oder gibt existierenden Connection Pool zurück\\\"\\\"\\\"\\n if cls._pool is None:\\n cls._pool = pooling.MySQLConnectionPool(\\n pool_name=\\\"mcp_pool\\\",\\n pool_size=5,\\n host=Config.DB_HOST,\\n user=Config.DB_USER,\\n password=Config.DB_PASSWORD,\\n charset=\\\"utf8mb4\\\",\\n connection_timeout=10,\\n autocommit=True,\\n )\\n return cls._pool\\n\\n @classmethod\\n @contextmanager\\n def get_connection(cls, database: str):\\n \\\"\\\"\\\"\\n Context Manager für DB Connection.\\n\\n Args:\\n database: Datenbankname (bereits validiert)\\n \\\"\\\"\\\"\\n conn = cls.get_pool().get_connection()\\n try:\\n # Datenbank wechseln (USE statement)\\n cursor = conn.cursor()\\n cursor.execute(f\\\"USE {database}\\\")\\n\\n # Query Timeout setzen (MariaDB: max_statement_time in Sekunden)\\n try:\\n cursor.execute(\\n f\\\"SET SESSION max_statement_time = {Config.QUERY_TIMEOUT_SEC}\\\"\\n )\\n except Exception:\\n pass # Falls Variable nicht unterstützt wird\\n cursor.close()\\n\\n yield conn\\n finally:\\n conn.close()<\/code><\/pre>\\n\\n<h3>Pool-Konfiguration<\/h3>\\n<table>\\n <tr><th>Parameter<\/th><th>Wert<\/th><th>Beschreibung<\/th><\/tr>\\n <tr><td>pool_size<\/td><td>5<\/td><td>Maximale Verbindungen<\/td><\/tr>\\n <tr><td>connection_timeout<\/td><td>10<\/td><td>Verbindungs-Timeout in Sekunden<\/td><\/tr>\\n <tr><td>autocommit<\/td><td>True<\/td><td>Automatisches Commit<\/td><\/tr>\\n <tr><td>charset<\/td><td>utf8mb4<\/td><td>Unicode-Support<\/td><\/tr>\\n<\/table>\\n\\n<h3>Query Timeout<\/h3>\\n<p>Bei jeder Verbindung wird <code>max_statement_time<\/code> gesetzt (MariaDB-spezifisch):<\/p>\\n<pre><code>SET SESSION max_statement_time = 30 # 30 Sekunden<\/code><\/pre>\\n<p><strong>Hinweis:<\/strong> MySQL verwendet <code>max_execution_time<\/code> in Millisekunden, MariaDB verwendet <code>max_statement_time<\/code> in Sekunden.<\/p>\\n\\n<h2>Logging<\/h2>\\n<p>Alle MCP-DB Operationen werden direkt in <code>ki_dev.mcp_log<\/code> protokolliert. Das Logging erfolgt inline in den Tool-Implementierungen, nicht über eine separate Logger-Klasse.<\/p>\\n\\n<h3>Logging-Ablauf<\/h3>\\n<ol>\\n <li>Tool wird aufgerufen (z.B. db_select)<\/li>\\n <li>Query wird validiert<\/li>\\n <li>Query wird ausgeführt<\/li>\\n <li>Ergebnis wird in mcp_log geschrieben<\/li>\\n<\/ol>\\n\\n<h3>mcp_log Tabelle<\/h3>\\n<pre><code>CREATE TABLE IF NOT EXISTS mcp_log (\\n id INT AUTO_INCREMENT PRIMARY KEY,\\n timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\\n client_name VARCHAR(50) NOT NULL DEFAULT 'mcp-db',\\n request TEXT,\\n status ENUM('success', 'error', 'denied') NOT NULL,\\n duration_ms INT DEFAULT 0,\\n error_message TEXT,\\n INDEX idx_timestamp (timestamp),\\n INDEX idx_status (status)\\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;<\/code><\/pre>\\n\\n<h3>Log-Felder<\/h3>\\n<table>\\n <tr><th>Feld<\/th><th>Typ<\/th><th>Beschreibung<\/th><\/tr>\\n <tr><td>timestamp<\/td><td>DATETIME<\/td><td>Zeitstempel der Operation<\/td><\/tr>\\n <tr><td>client_name<\/td><td>VARCHAR(50)<\/td><td>Client-Identifikation (mcp-db)<\/td><\/tr>\\n <tr><td>request<\/td><td>TEXT<\/td><td>Query-Text (gekürzt auf 200 Zeichen)<\/td><\/tr>\\n <tr><td>status<\/td><td>ENUM<\/td><td>success, error, denied<\/td><\/tr>\\n <tr><td>duration_ms<\/td><td>INT<\/td><td>Ausführungsdauer in Millisekunden<\/td><\/tr>\\n <tr><td>error_message<\/td><td>TEXT<\/td><td>Fehlerdetails (bei Fehlern)<\/td><\/tr>\\n<\/table>\\n\\n<h2>Nutzung<\/h2>\\n<pre><code># DatabaseConnection mit Context Manager\\nwith DatabaseConnection.get_connection(\\\"ki_dev\\\") as conn:\\n cursor = conn.cursor(dictionary=True)\\n cursor.execute(\\\"SELECT * FROM mcp_log LIMIT 10\\\")\\n rows = cursor.fetchall()\\n cursor.close()\\n\\n# Log-Eintrag schreiben (inline in Tool)\\ncursor.execute(\\n \\\"\\\"\\\"INSERT INTO mcp_log\\n (client_name, request, status, duration_ms, error_message)\\n VALUES (%s, %s, %s, %s, %s)\\\"\\\"\\\",\\n (\\\"mcp-db\\\", query[:200], \\\"success\\\", duration_ms, None)\\n)<\/code><\/pre>\\n\\n<h2>Verzeichnisstruktur<\/h2>\\n<pre><code>\/var\/www\/mcp-servers\/mcp_db\/infrastructure\/\\n├── __init__.py\\n└── db_connection.py # DatabaseConnection Klasse<\/code><\/pre>\\n\\n<h2>Verwandte Kapitel<\/h2>\\n<ul>\\n <li><a href=\\\"\/docs\/mcp\/mcp-db-security\\\">Sicherheit<\/a> - Separate DB-User<\/li>\\n <li><a href=\\\"\/docs\/mcp\/mcp-db-contracts\\\">Contracts<\/a> - Datenstrukturen<\/li>\\n <li><a href=\\\"\/docs\/mcp\/mcp-db-config\\\">Konfiguration<\/a> - Environment Variables<\/li>\\n<\/ul>\",\n \"status\": \"published\",\n \"sort_order\": 8,\n \"depth\": 2,\n \"created_at\": \"2025-12-20T11:13:58\",\n \"updated_at\": \"2025-12-31T05:07:22\"\n },\n \"message\": \"Document #44 updated\"\n}"
}
]
}