Skip to main content
Glama
minami110

GDScript Code Analyzer

by minami110

analyze_gdscript_file

Extract GDScript file structure including classes, functions, signals, and variables to understand code organization without reading entire files.

Instructions

Analyze a GDScript file and extract its structure (classes, functions, signals, variables, enums). Returns a comprehensive overview without reading the entire file into context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the GDScript file to analyze

Implementation Reference

  • The core handler function that executes the 'analyze_gdscript_file' tool logic. It validates the file path, reads the GDScript content, parses it using GDScriptParser, extracts symbols (classes, functions, signals, variables, enums), computes summary statistics, and returns a structured JSON result.
    def _analyze_file(self, file_path: str) -> CallToolResult:
        """Analyze a GDScript file.
    
        Args:
            file_path: Path to the file
    
        Returns:
            CallToolResult with analysis
        """
        try:
            path = Path(file_path)
            if not path.exists():
                return CallToolResult(
                    content=[TextContent(type="text", text=f"File not found: {file_path}")],
                    isError=True,
                )
    
            if not path.suffix.lower() in [".gd", ".gdscript"]:
                return CallToolResult(
                    content=[TextContent(type="text", text="File must be a .gd or .gdscript file")],
                    isError=True,
                )
    
            code = path.read_text(encoding="utf-8")
            tree = self.parser.parse(code)
            symbols = self.parser.get_symbols(tree)
    
            result = {
                "file": file_path,
                "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 file: {str(e)}")],
                isError=True,
            )
  • Tool registration definition in GDScriptTools.get_tools(), including the tool name, description, and input schema for MCP compatibility.
    Tool(
        name="analyze_gdscript_file",
        description="Analyze a GDScript file and extract its structure (classes, functions, signals, variables, enums). Returns a comprehensive overview without reading the entire file into context.",
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {
                    "type": "string",
                    "description": "Path to the GDScript file to analyze",
                }
            },
            "required": ["file_path"],
        },
    ),
  • Input schema definition specifying an object with a required 'file_path' string property for the tool.
    inputSchema={
        "type": "object",
        "properties": {
            "file_path": {
                "type": "string",
                "description": "Path to the GDScript file to analyze",
            }
        },
        "required": ["file_path"],
    },
  • MCP server registration of the call_tool handler, which delegates to GDScriptTools.handle_tool_call(name, arguments), enabling execution of 'analyze_gdscript_file'.
    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)
  • MCP server registration of list_tools, which returns tools from GDScriptTools.get_tools(), including 'analyze_gdscript_file'.
    @self.server.list_tools()
    async def list_tools() -> list[Tool]:
        """List available tools."""
        logger.info("Listing available tools")
        return self.tools.get_tools()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/minami110/mcp-gdscript'

If you have feedback or need assistance with the MCP directory API, please join our Discord server