analyze_gdscript_code
Analyze GDScript code structure to extract symbols, functions, and dependencies for understanding Godot game engine codebases.
Instructions
Analyze GDScript code provided directly and extract its structure.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | GDScript source code to analyze |
Implementation Reference
- src/mcp_gdscript/tools.py:337-371 (handler)The main handler function for the 'analyze_gdscript_code' tool. It parses the provided GDScript code using the GDScriptParser, extracts symbols and structure, computes a summary, and returns a JSON-formatted result.def _analyze_code(self, code: str) -> CallToolResult: """Analyze GDScript code provided directly. Args: code: GDScript source code Returns: CallToolResult with analysis """ try: tree = self.parser.parse(code) symbols = self.parser.get_symbols(tree) structure = self.parser.get_structure(tree, code) result = { "structure": structure, "symbols": symbols, "summary": { "total_classes": len(symbols["classes"]), "total_functions": len(symbols["functions"]), "total_signals": len(symbols["signals"]), "total_variables": len(symbols["variables"]), "total_enums": len(symbols["enums"]), }, } 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 analyzing code: {str(e)}")], isError=True, )
- src/mcp_gdscript/tools.py:88-101 (schema)The schema definition for the 'analyze_gdscript_code' tool, specifying the input as a string 'code' parameter.Tool( name="analyze_gdscript_code", description="Analyze GDScript code provided directly and extract its structure.", inputSchema={ "type": "object", "properties": { "code": { "type": "string", "description": "GDScript source code to analyze", } }, "required": ["code"], }, ),
- src/mcp_gdscript/tools.py:164-165 (registration)Registration dispatch in handle_tool_call method that routes calls to the _analyze_code handler.elif tool_name == "analyze_gdscript_code": return self._analyze_code(tool_input["code"])
- src/mcp_gdscript/server.py:40-47 (registration)MCP server handler for tool calls, which delegates to GDScriptTools.handle_tool_call including for analyze_gdscript_code.async def call_tool(name: str, arguments: dict[str, Any]) -> CallToolResult: """Handle tool calls.""" logger.info(f"Calling tool: {name} with arguments: {arguments}") result = self.tools.handle_tool_call(name, arguments) return CallToolResult(content=result.content, isError=result.isError)
- src/mcp_gdscript/server.py:33-38 (registration)MCP server handler for listing tools, which returns the list from GDScriptTools.get_tools() including the analyze_gdscript_code tool.@self.server.list_tools() async def list_tools() -> list[Tool]: """List available tools.""" logger.info("Listing available tools") return self.tools.get_tools()