{
"event": "PreToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "\/opt\/mcp-servers\/mcp-code\/db.py",
"content": "\"\"\"Einfache DB-Connection für mcp-code.\"\"\"\nimport mysql.connector\nfrom config import Config\n\n\ndef get_connection():\n \"\"\"Erstellt eine DB-Connection.\"\"\"\n return mysql.connector.connect(\n host=Config.DB_HOST,\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n database=Config.DB_NAME,\n )\n\n\ndef execute_query(query: str, params: tuple = None, max_rows: int = 100) -> list:\n \"\"\"Führt Query aus und gibt Ergebnisse zurück.\"\"\"\n conn = get_connection()\n cursor = conn.cursor(dictionary=True, buffered=True)\n cursor.execute(query, params or ())\n rows = cursor.fetchmany(max_rows)\n cursor.close()\n conn.close()\n return rows\n\n\ndef execute_single(query: str, params: tuple = None) -> dict | None:\n \"\"\"Führt Query aus und gibt einzelnes Ergebnis zurück.\"\"\"\n rows = execute_query(query, params, max_rows=1)\n return rows[0] if rows else None\n"
}
}
{
"tool_response": {
"type": "create",
"filePath": "\/opt\/mcp-servers\/mcp-code\/db.py",
"content": "\"\"\"Einfache DB-Connection für mcp-code.\"\"\"\nimport mysql.connector\nfrom config import Config\n\n\ndef get_connection():\n \"\"\"Erstellt eine DB-Connection.\"\"\"\n return mysql.connector.connect(\n host=Config.DB_HOST,\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n database=Config.DB_NAME,\n )\n\n\ndef execute_query(query: str, params: tuple = None, max_rows: int = 100) -> list:\n \"\"\"Führt Query aus und gibt Ergebnisse zurück.\"\"\"\n conn = get_connection()\n cursor = conn.cursor(dictionary=True, buffered=True)\n cursor.execute(query, params or ())\n rows = cursor.fetchmany(max_rows)\n cursor.close()\n conn.close()\n return rows\n\n\ndef execute_single(query: str, params: tuple = None) -> dict | None:\n \"\"\"Führt Query aus und gibt einzelnes Ergebnis zurück.\"\"\"\n rows = execute_query(query, params, max_rows=1)\n return rows[0] if rows else None\n",
"structuredPatch": [],
"originalFile": null
}
}