XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Update mcp

ee891210
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

3 个文件 +16 -4
Modified g4f/gui/server/website.py +11 -0
@@ -132,6 +132,14 @@ class Website:
132 132 'function': self._playground,
133 133 'methods': ['GET']
134 134 },
135 '/apps/': {
136 'function': self._apps,
137 'methods': ['GET']
138 },
139 '/apps/<path:filename>': {
140 'function': self._apps,
141 'methods': ['GET']
142 },
135 143 }
136 144
137 145 def _index(self, filename = "home"):
@@ -156,6 +164,9 @@ class Website:
156 164
157 165 def _dist(self, name: str):
158 166 return render(f"dist/{name}")
167
168 def _apps(self, filename: str = "index.html"):
169 return render(f"apps/{filename}")
159 170
160 171 def _playground(self, filename: str = "index.html"):
161 172 PLAYGROUND_URL = "https://raw.githubusercontent.com/gpt4free/playground/refs/heads/main/"
Modified g4f/mcp/server.py +3 -2
@@ -435,12 +435,13 @@ class MCPServer:
435 435 header so they run in an isolated null origin.
436 436 """
437 437 from .pa_provider import get_workspace_dir
438 workspace = get_workspace_dir()
438 workspace = get_workspace_dir().resolve()
439 439
440 440 file_path = request.match_info.get("file_path", "")
441 441 try:
442 442 resolved = (workspace / file_path).resolve()
443 resolved.relative_to(workspace.resolve())
443 # Security: ensure the resolved path is still inside the workspace directory
444 resolved.relative_to(workspace)
444 445 except (ValueError, Exception):
445 446 return web.Response(status=403, text="Path traversal is not allowed")
446 447
Modified g4f/mcp/tools.py +2 -2
@@ -609,10 +609,10 @@ class FileReadTool(MCPTool):
609 609 if not rel_path:
610 610 return {"error": "path parameter is required"}
611 611
612 workspace = get_workspace_dir()
612 workspace = get_workspace_dir().resolve()
613 613 try:
614 614 target = (workspace / rel_path).resolve()
615 if not str(target).startswith(str(workspace.resolve())):
615 if not str(target).startswith(str(workspace)):
616 616 return {"error": "Access outside the workspace is not allowed"}
617 617 if not target.exists():
618 618 return {"error": f"File not found: {rel_path}"}