{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/mcp-servers\/mcp-docs\/tools\/docs_tools\/docs_hierarchy.py",
"old_string": " 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)}",
"new_string": " success = repo.move(id, new_parent_id, new_sort_order)\n if success:\n updated_doc = repo.find_by_id(id)\n _log_operation(\n logger, \"docs_move\",\n {\"id\": id, \"new_parent_id\": new_parent_id},\n start_time\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 _log_operation(\n logger, \"docs_move\", {\"id\": id}, start_time, \"error\", str(e)\n )\n return {\"success\": False, \"error\": str(e)}"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/mcp-servers\/mcp-docs\/tools\/docs_tools\/docs_hierarchy.py",
"oldString": " 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)}",
"newString": " success = repo.move(id, new_parent_id, new_sort_order)\n if success:\n updated_doc = repo.find_by_id(id)\n _log_operation(\n logger, \"docs_move\",\n {\"id\": id, \"new_parent_id\": new_parent_id},\n start_time\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 _log_operation(\n logger, \"docs_move\", {\"id\": id}, start_time, \"error\", str(e)\n )\n return {\"success\": False, \"error\": str(e)}",
"originalFile": "\"\"\"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 _log_operation(\n logger,\n tool_name: str,\n request_data: dict,\n start_time: float,\n status: str = \"success\",\n error: Optional[str] = None\n) -> None:\n \"\"\"Log an operation with timing information.\"\"\"\n logger.log(LogEntry(\n tool_name=tool_name,\n request=json.dumps(request_data),\n status=status,\n error_message=error,\n duration_ms=int((time.time() - start_time) * MS_PER_SECOND)\n ))\n\n\ndef register_hierarchy_tools(mcp) -> None:\n \"\"\"Register hierarchy documentation tools with the MCP server.\"\"\"\n\n @mcp.tool()\n def docs_hierarchy() -> dict:\n \"\"\"Retrieve the complete documentation tree.\"\"\"\n start_time = time.time()\n logger = get_logger()\n repo = get_repository()\n\n try:\n hierarchy = repo.get_hierarchy()\n _log_operation(logger, \"docs_hierarchy\", {}, start_time)\n return {\"success\": True, \"hierarchy\": hierarchy}\n\n except Exception as e:\n _log_operation(\n logger, \"docs_hierarchy\", {}, start_time, \"error\", str(e)\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 \"\"\"Move a document to a new parent.\"\"\"\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": [
{
"oldStart": 74,
"oldLines": 17,
"newStart": 74,
"newLines": 11,
"lines": [
" success = repo.move(id, new_parent_id, new_sort_order)",
" if success:",
" updated_doc = repo.find_by_id(id)",
"-",
"- logger.log(LogEntry(",
"- tool_name=\"docs_move\",",
"- request=json.dumps({",
"- \"id\": id,",
"- \"new_parent_id\": new_parent_id",
"- }),",
"- status=\"success\",",
"- duration_ms=int((time.time() - start_time) * MS_PER_SECOND)",
"- ))",
"-",
"+ _log_operation(",
"+ logger, \"docs_move\",",
"+ {\"id\": id, \"new_parent_id\": new_parent_id},",
"+ start_time",
"+ )",
" return {",
" \"success\": True,",
" \"doc\": updated_doc.to_dict_compact() if updated_doc else None,"
]
},
{
"oldStart": 94,
"oldLines": 11,
"newStart": 88,
"newLines": 7,
"lines": [
" return {\"success\": False, \"error\": \"Move failed\"}",
" ",
" except Exception as e:",
"- logger.log(LogEntry(",
"- tool_name=\"docs_move\",",
"- request=json.dumps({\"id\": id}),",
"- status=\"error\",",
"- error_message=str(e),",
"- duration_ms=int((time.time() - start_time) * MS_PER_SECOND)",
"- ))",
"+ _log_operation(",
"+ logger, \"docs_move\", {\"id\": id}, start_time, \"error\", str(e)",
"+ )",
" return {\"success\": False, \"error\": str(e)}"
]
}
],
"userModified": false,
"replaceAll": false
}
}