Skip to main content
Glama
lolpack

MCP Pyrefly Autotype Server

by lolpack

analyze_python_file

Identify missing type annotations in Python files to enhance code clarity and maintainability, supporting detailed analysis when needed.

Instructions

Analyze a Python file for missing type annotations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
detailedNoInclude detailed analysis information
file_pathYesPath to the Python file to analyze

Implementation Reference

  • Executes the analyze_python_file tool: validates input, runs Pyrefly analysis via analyzer, formats detailed or summary results as text content.
    if name == "analyze_python_file": file_path = arguments.get("file_path") detailed = arguments.get("detailed", False) if not file_path: raise ValueError("Missing file_path argument") if not os.path.exists(file_path): raise ValueError(f"File not found: {file_path}") analysis = await pyrefly_analyzer.analyze_file(file_path) if detailed: result_text = f"""Detailed Pyrefly Analysis for {file_path}: Functions needing types ({len(analysis.get('functions_needing_types', []))}): {chr(10).join(f" - {func}" for func in analysis.get('functions_needing_types', []))} Variables needing types ({len(analysis.get('variables_needing_types', []))}): {chr(10).join(f" - {var}" for var in analysis.get('variables_needing_types', []))} Suggested types: {chr(10).join(f" - {name}: {type_hint}" for name, type_hint in analysis.get('suggested_types', {}).items())} Pyrefly Output: {analysis.get('pyrefly_output', 'No output available')}""" else: result_text = f"""Pyrefly Analysis for {file_path}: Functions needing types: {len(analysis.get('functions_needing_types', []))} Variables needing types: {len(analysis.get('variables_needing_types', []))}""" return [types.TextContent(type="text", text=result_text)]
  • Pydantic-style input schema for analyze_python_file tool, defining required file_path and optional detailed flag.
    inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Python file to analyze" }, "detailed": { "type": "boolean", "description": "Include detailed analysis information", "default": False } }, "required": ["file_path"], },
  • Tool registration in handle_list_tools(): defines name, description, and schema for analyze_python_file.
    types.Tool( name="analyze_python_file", description="Analyze a Python file for missing type annotations", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Python file to analyze" }, "detailed": { "type": "boolean", "description": "Include detailed analysis information", "default": False } }, "required": ["file_path"], }, ),
  • PyreflyAnalyzer.analyze_file: core helper that runs 'uv run pyrefly autotype' on the file, parses output for functions/variables needing types.
    async def analyze_file(self, file_path: str) -> Dict[str, Any]: """Analyze a Python file using Pyrefly's analysis capabilities.""" try: # Use Pyrefly to analyze the file result = await self.run_pyrefly_command([ "uv", "run", "pyrefly", "autotype", file_path ]) if result["success"]: # Parse Pyrefly's output for analysis information analysis = self._parse_pyrefly_analysis(result["stdout"], file_path) return analysis else: return { "error": result.get("error", result.get("stderr", "Unknown error")), "file_path": file_path } except Exception as e: return {"error": str(e), "file_path": file_path}

Other Tools

Related 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/lolpack/mcp-pyrefly-autotype'

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