返回提交历史
Modified
g4f/mcp/tools.py
+15
-15
XFEstudio/gpt4free
Update tools.py
c46dc390
代码差异
1 个文件
+15
-15
@@ -687,10 +687,10 @@ class FileReadLinesTool(MCPTool):
687
687
if end_line < start_line:
688
688
return {"error": "end_line must be greater than or equal to start_line"}
689
689
690
workspace = get_workspace_dir()
690
workspace = get_workspace_dir().resolve()
691
691
try:
692
692
target = (workspace / rel_path).resolve()
693
if not str(target).startswith(str(workspace.resolve())):
693
if not str(target).startswith(str(workspace)):
694
694
return {"error": "Access outside the workspace is not allowed"}
695
695
if not target.exists():
696
696
return {"error": f"File not found: {rel_path}"}
@@ -772,10 +772,10 @@ class FileWriteTool(MCPTool):
772
772
if content is None:
773
773
return {"error": "content parameter is required"}
774
774
775
workspace = get_workspace_dir()
775
workspace = get_workspace_dir().resolve()
776
776
try:
777
777
target = (workspace / rel_path).resolve()
778
if not str(target).startswith(str(workspace.resolve())):
778
if not str(target).startswith(str(workspace)):
779
779
return {"error": "Access outside the workspace is not allowed"}
780
780
target.parent.mkdir(parents=True, exist_ok=True)
781
781
if append:
@@ -868,10 +868,10 @@ class FileSearchTool(MCPTool):
868
868
if not pattern and not query:
869
869
return {"error": "At least one of pattern or query is required"}
870
870
871
workspace = get_workspace_dir()
871
workspace = get_workspace_dir().resolve()
872
872
try:
873
target = (workspace / rel_path).resolve() if rel_path else workspace.resolve()
874
if not str(target).startswith(str(workspace.resolve())):
873
target = (workspace / rel_path).resolve() if rel_path else workspace
874
if not str(target).startswith(str(workspace)):
875
875
return {"error": "Access outside the workspace is not allowed"}
876
876
if not target.exists():
877
877
return {"error": f"Directory not found: {rel_path or '/'}"}
@@ -970,12 +970,12 @@ class FileListTool(MCPTool):
970
970
rel_path = arguments.get("path", "") or ""
971
971
recursive = bool(arguments.get("recursive", False))
972
972
973
workspace = get_workspace_dir()
973
workspace = get_workspace_dir().resolve()
974
974
try:
975
target = (workspace / rel_path).resolve() if rel_path else workspace.resolve()
976
if not str(target).startswith(str(workspace.resolve())):
975
target = (workspace / rel_path).resolve() if rel_path else workspace
976
if not str(target).startswith(str(workspace)):
977
977
return {"error": "Access outside the workspace is not allowed"}
978
if self.safe_mode and target == workspace.resolve():
978
if self.safe_mode and target == workspace:
979
979
return {"error": "Listing the workspace root directory is not allowed in safe mode"}
980
980
if not target.exists():
981
981
return {"error": f"Directory not found: {rel_path or '/'}"}
@@ -1043,10 +1043,10 @@ class FileDeleteTool(MCPTool):
1043
1043
if not rel_path:
1044
1044
return {"error": "path parameter is required"}
1045
1045
1046
workspace = get_workspace_dir()
1046
workspace = get_workspace_dir().resolve()
1047
1047
try:
1048
1048
target = (workspace / rel_path).resolve()
1049
if not str(target).startswith(str(workspace.resolve())):
1049
if not str(target).startswith(str(workspace)):
1050
1050
return {"error": "Access outside the workspace is not allowed"}
1051
1051
if not target.exists():
1052
1052
return {"error": f"File not found: {rel_path}"}
@@ -1111,10 +1111,10 @@ class ApplyPatchTool(MCPTool):
1111
1111
patch_content = arguments.get("patch_content", "")
1112
1112
backup = bool(arguments.get("backup", False))
1113
1113
dry_run = bool(arguments.get("dry_run", False))
1114
workspace = get_workspace_dir()
1114
workspace = get_workspace_dir().resolve()
1115
1115
try:
1116
1116
target = (workspace / target_path).resolve()
1117
if not str(target).startswith(str(workspace.resolve())):
1117
if not str(target).startswith(str(workspace)):
1118
1118
return {"error": "Access outside the workspace is not allowed"}
1119
1119
if not target.exists():
1120
1120
return {"error": f"File not found: {target_path}"}