set_project_root
Set the project root directory to enable project-wide GDScript analysis, indexing all .gd files for efficient code navigation and understanding in Godot projects.
Instructions
Set the project root directory to enable project-wide analysis. This will index all .gd files in the project.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_root | Yes | Path to the project root directory |
Implementation Reference
- src/mcp_gdscript/tools.py:383-423 (handler)Core handler function implementing the 'set_project_root' tool logic: validates path, sets project root, indexes .gd files, returns JSON result.def _set_project_root(self, project_root: str) -> CallToolResult: """Set the project root directory. Args: project_root: Path to the project root Returns: CallToolResult with status """ try: root_path = Path(project_root).resolve() if not root_path.exists(): return CallToolResult( content=[TextContent(type="text", text=f"Project root does not exist: {project_root}")], isError=True, ) if not root_path.is_dir(): return CallToolResult( content=[TextContent(type="text", text=f"Project root is not a directory: {project_root}")], isError=True, ) self.project_root = root_path self._load_gdscript_files() result = { "project_root": str(self.project_root), "gdscript_files_count": len(self._gdscript_files), "status": "success", } return CallToolResult( content=[TextContent(type="text", text=json.dumps(result, indent=2))], isError=False, ) except Exception as e: return CallToolResult( content=[TextContent(type="text", text=f"Error setting project root: {str(e)}")], isError=True, )
- src/mcp_gdscript/tools.py:105-114 (schema)Input schema definition for the 'set_project_root' tool, specifying the required 'project_root' string parameter.inputSchema={ "type": "object", "properties": { "project_root": { "type": "string", "description": "Path to the project root directory", } }, "required": ["project_root"], },
- src/mcp_gdscript/tools.py:102-115 (registration)Registration of the 'set_project_root' tool in the get_tools() method's return list, including name, description, and schema.Tool( name="set_project_root", description="Set the project root directory to enable project-wide analysis. This will index all .gd files in the project.", inputSchema={ "type": "object", "properties": { "project_root": { "type": "string", "description": "Path to the project root directory", } }, "required": ["project_root"], }, ),
- src/mcp_gdscript/tools.py:166-167 (registration)Dispatch/registration in handle_tool_call method that routes 'set_project_root' calls to the _set_project_root handler.elif tool_name == "set_project_root": return self._set_project_root(tool_input["project_root"])
- src/mcp_gdscript/tools.py:373-382 (helper)Helper utility called by the handler to index all GDScript (.gd) files recursively from the project root.def _load_gdscript_files(self) -> None: """Load all .gd files from the project root.""" if not self.project_root: self._gdscript_files = [] return self._gdscript_files = [] for file_path in self.project_root.rglob("*.gd"): self._gdscript_files.append(file_path)