set_project_root
Configure the project root directory to enable comprehensive analysis of GDScript code structure, dependencies, and symbols across all files in your Godot project.
Instructions
Set the project root directory to enable project-wide analysis. This will index all .gd files in the project.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_root | Yes | Path to the project root directory |
Input Schema (JSON Schema)
{
"properties": {
"project_root": {
"description": "Path to the project root directory",
"type": "string"
}
},
"required": [
"project_root"
],
"type": "object"
}
Implementation Reference
- src/mcp_gdscript/tools.py:383-423 (handler)The core handler function that implements the set_project_root tool. It validates the provided project_root path, sets it as the instance's project root if valid, loads all .gd files recursively from the project, and returns a JSON result with the root path and count of GDScript files indexed.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:102-115 (registration)Registers the set_project_root tool in the list returned by get_tools(), including its name, description, and input schema requiring a 'project_root' string.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 (handler)The dispatch logic in handle_tool_call that routes calls to the set_project_root tool to its implementation method.elif tool_name == "set_project_root": return self._set_project_root(tool_input["project_root"])
- src/mcp_gdscript/tools.py:373-382 (helper)Helper method called by set_project_root to index all GDScript (.gd) files recursively under 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)