get_gdscript_dependencies
Extract dependencies from a GDScript file to identify extends, preload, and import statements for code analysis.
Instructions
Extract dependencies from a GDScript file (extends, preload, import statements).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the GDScript file |
Input Schema (JSON Schema)
{
"properties": {
"file_path": {
"description": "Path to the GDScript file",
"type": "string"
}
},
"required": [
"file_path"
],
"type": "object"
}
Implementation Reference
- src/mcp_gdscript/tools.py:301-335 (handler)The primary handler function for the 'get_gdscript_dependencies' tool. Reads the GDScript file, parses it with GDScriptParser, retrieves dependencies using the parser's get_dependencies method, formats the result as JSON, and returns a CallToolResult.def _get_dependencies(self, file_path: str) -> CallToolResult: """Get dependencies from a GDScript file. Args: file_path: Path to the file Returns: CallToolResult with dependencies """ try: path = Path(file_path) if not path.exists(): return CallToolResult( content=[TextContent(type="text", text=f"File not found: {file_path}")], isError=True, ) code = path.read_text(encoding="utf-8") tree = self.parser.parse(code) dependencies = self.parser.get_dependencies(tree, code) result = { "file": file_path, "dependencies": dependencies, } 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 getting dependencies: {str(e)}")], isError=True, )
- src/mcp_gdscript/tools.py:74-87 (schema)The tool's schema definition, including name, description, and input validation schema requiring a 'file_path' parameter.Tool( name="get_gdscript_dependencies", description="Extract dependencies from a GDScript file (extends, preload, import statements).", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the GDScript file", } }, "required": ["file_path"], }, ),
- src/mcp_gdscript/tools.py:162-163 (registration)Registration of the tool handler within the central handle_tool_call dispatcher method.elif tool_name == "get_gdscript_dependencies": return self._get_dependencies(tool_input["file_path"])
- src/mcp_gdscript/parser.py:211-229 (helper)Helper method in GDScriptParser that orchestrates dependency extraction by calling _extract_dependencies on the parse tree root.def get_dependencies(self, tree: Tree, code: str) -> dict[str, list[str]]: """Extract dependencies (extends, preload) from the file. Args: tree: The parsed syntax tree code: The original source code Returns: Dictionary with lists of dependencies """ dependencies = { "extends": [], "preload": [], "import": [], } self._extract_dependencies(tree.root_node, dependencies) return dependencies
- src/mcp_gdscript/parser.py:230-268 (helper)Core recursive helper that traverses the parse tree to identify and collect 'extends', 'preload', and 'import' dependencies.def _extract_dependencies(self, node: Node, deps: dict[str, list[str]]) -> None: """Recursively extract dependencies from tree nodes. Args: node: Current tree node deps: Dependencies dictionary to populate """ node_type = node.type # Check for extends statement if node_type in ("extends_statement", "extend_statement"): # For extends, the type is in the "type" child node for child in node.children: if child.type == "type": path = child.text.decode("utf-8") if isinstance(child.text, bytes) else str(child.text) if path: deps["extends"].append(path) elif child.type == "identifier": path = child.text.decode("utf-8") if isinstance(child.text, bytes) else str(child.text) if path and path != "extends": deps["extends"].append(path) # Check for preload function calls (both function_call and call node types) elif node_type in ("function_call", "call"): if self._is_preload_call(node): path = self._extract_string_argument(node) if path: deps["preload"].append(path) # Check for import statements elif node_type == "import_statement": path = self._extract_string_value(node) if path: deps["import"].append(path) # Recursively process child nodes for child in node.children: self._extract_dependencies(child, deps)