{
"event": "PreToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "\/var\/www\/mcp-servers\/mcp-docs\/tools\/docs_tools\/docs_hierarchy.py",
"content": "\"\"\"Hierarchy operations for documentation management.\"\"\"\n\nimport json\nimport sys\nimport time\nfrom typing import Optional\n\nsys.path.insert(0, \"\/opt\/mcp-servers\/mcp-docs\")\nfrom domain.dokumentation import LogEntry\nfrom infrastructure.docs_repository import get_repository\nfrom infrastructure.protokoll_logger import get_logger\n\nfrom .constants import MS_PER_SECOND\n\n\ndef register_hierarchy_tools(mcp) -> None:\n \"\"\"\n Register hierarchy documentation tools with the MCP server.\n\n Args:\n mcp: The MCP server instance to register tools with\n \"\"\"\n\n @mcp.tool()\n def docs_hierarchy() -> dict:\n \"\"\"\n Retrieve the complete documentation tree.\n\n Returns:\n Dict containing hierarchical tree of all documents\n \"\"\"\n start_time = time.time()\n logger = get_logger()\n repo = get_repository()\n\n try:\n hierarchy = repo.get_hierarchy()\n\n logger.log(LogEntry(\n tool_name=\"docs_hierarchy\",\n request=\"{}\",\n status=\"success\",\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n\n return {\n \"success\": True,\n \"hierarchy\": hierarchy\n }\n\n except Exception as e:\n logger.log(LogEntry(\n tool_name=\"docs_hierarchy\",\n request=\"{}\",\n status=\"error\",\n error_message=str(e),\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n return {\"success\": False, \"error\": str(e)}\n\n @mcp.tool()\n def docs_move(\n id: int,\n new_parent_id: Optional[int] = None,\n new_sort_order: Optional[int] = None\n ) -> dict:\n \"\"\"\n Move a document to a new parent.\n\n Args:\n id: Document ID (required)\n new_parent_id: New parent ID (None for root)\n new_sort_order: New sort order\n\n Returns:\n Dict containing updated document\n \"\"\"\n start_time = time.time()\n logger = get_logger()\n repo = get_repository()\n\n try:\n doc = repo.find_by_id(id)\n if not doc:\n return {\n \"success\": False,\n \"error\": f\"Document with ID {id} not found\"\n }\n\n success = repo.move(id, new_parent_id, new_sort_order)\n if success:\n updated_doc = repo.find_by_id(id)\n\n logger.log(LogEntry(\n tool_name=\"docs_move\",\n request=json.dumps({\n \"id\": id,\n \"new_parent_id\": new_parent_id\n }),\n status=\"success\",\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n\n return {\n \"success\": True,\n \"doc\": updated_doc.to_dict_compact() if updated_doc else None,\n \"message\": f\"Document #{id} moved\"\n }\n else:\n return {\"success\": False, \"error\": \"Move failed\"}\n\n except Exception as e:\n logger.log(LogEntry(\n tool_name=\"docs_move\",\n request=json.dumps({\"id\": id}),\n status=\"error\",\n error_message=str(e),\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n return {\"success\": False, \"error\": str(e)}\n"
}
}
{
"tool_response": {
"type": "create",
"filePath": "\/var\/www\/mcp-servers\/mcp-docs\/tools\/docs_tools\/docs_hierarchy.py",
"content": "\"\"\"Hierarchy operations for documentation management.\"\"\"\n\nimport json\nimport sys\nimport time\nfrom typing import Optional\n\nsys.path.insert(0, \"\/opt\/mcp-servers\/mcp-docs\")\nfrom domain.dokumentation import LogEntry\nfrom infrastructure.docs_repository import get_repository\nfrom infrastructure.protokoll_logger import get_logger\n\nfrom .constants import MS_PER_SECOND\n\n\ndef register_hierarchy_tools(mcp) -> None:\n \"\"\"\n Register hierarchy documentation tools with the MCP server.\n\n Args:\n mcp: The MCP server instance to register tools with\n \"\"\"\n\n @mcp.tool()\n def docs_hierarchy() -> dict:\n \"\"\"\n Retrieve the complete documentation tree.\n\n Returns:\n Dict containing hierarchical tree of all documents\n \"\"\"\n start_time = time.time()\n logger = get_logger()\n repo = get_repository()\n\n try:\n hierarchy = repo.get_hierarchy()\n\n logger.log(LogEntry(\n tool_name=\"docs_hierarchy\",\n request=\"{}\",\n status=\"success\",\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n\n return {\n \"success\": True,\n \"hierarchy\": hierarchy\n }\n\n except Exception as e:\n logger.log(LogEntry(\n tool_name=\"docs_hierarchy\",\n request=\"{}\",\n status=\"error\",\n error_message=str(e),\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n return {\"success\": False, \"error\": str(e)}\n\n @mcp.tool()\n def docs_move(\n id: int,\n new_parent_id: Optional[int] = None,\n new_sort_order: Optional[int] = None\n ) -> dict:\n \"\"\"\n Move a document to a new parent.\n\n Args:\n id: Document ID (required)\n new_parent_id: New parent ID (None for root)\n new_sort_order: New sort order\n\n Returns:\n Dict containing updated document\n \"\"\"\n start_time = time.time()\n logger = get_logger()\n repo = get_repository()\n\n try:\n doc = repo.find_by_id(id)\n if not doc:\n return {\n \"success\": False,\n \"error\": f\"Document with ID {id} not found\"\n }\n\n success = repo.move(id, new_parent_id, new_sort_order)\n if success:\n updated_doc = repo.find_by_id(id)\n\n logger.log(LogEntry(\n tool_name=\"docs_move\",\n request=json.dumps({\n \"id\": id,\n \"new_parent_id\": new_parent_id\n }),\n status=\"success\",\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n\n return {\n \"success\": True,\n \"doc\": updated_doc.to_dict_compact() if updated_doc else None,\n \"message\": f\"Document #{id} moved\"\n }\n else:\n return {\"success\": False, \"error\": \"Move failed\"}\n\n except Exception as e:\n logger.log(LogEntry(\n tool_name=\"docs_move\",\n request=json.dumps({\"id\": id}),\n status=\"error\",\n error_message=str(e),\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n return {\"success\": False, \"error\": str(e)}\n",
"structuredPatch": [],
"originalFile": null
}
}