type_check_file
Check Python file type errors with Pyrefly's inference engine to identify and fix annotation issues.
Instructions
Run type checking on a Python file using Pyrefly
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the Python file to type check |
Implementation Reference
- Handler implementation in handle_call_tool for 'type_check_file': validates file_path, calls run_pyrefly_check helper, formats and returns type check results as text content.elif name == "type_check_file": file_path = arguments.get("file_path") 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}") result = await run_pyrefly_check(file_path) if result["success"]: return [types.TextContent( type="text", text=f"Type checking passed for {file_path}\n\nOutput:\n{result['output']}" )] else: return [types.TextContent( type="text", text=f"Type checking found issues in {file_path}\n\nErrors:\n{result['output']}\n{result.get('errors', '')}" )]
- src/mcp_pyrefly_autotype/server.py:385-398 (registration)Registration of the 'type_check_file' tool in the list_tools() handler, including its description and input schema requiring 'file_path'.types.Tool( name="type_check_file", description="Run type checking on a Python file using Pyrefly", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Python file to type check" } }, "required": ["file_path"], }, ),
- Input schema definition for the 'type_check_file' tool: object with required 'file_path' string property.inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Python file to type check" } }, "required": ["file_path"], },
- Helper function that executes the 'pyrefly check' subprocess command on a given file_path and returns a structured result dict with success status, output, and errors.async def run_pyrefly_check(file_path: str) -> Dict[str, Any]: """Run pyrefly type checking on a file.""" try: result = subprocess.run( ["uv", "run", "pyrefly", "check", file_path], capture_output=True, text=True, timeout=30 ) return { "success": result.returncode == 0, "output": result.stdout, "errors": result.stderr, "returncode": result.returncode } except subprocess.TimeoutExpired: return { "success": False, "error": "Pyrefly check execution timed out" } except Exception as e: return { "success": False, "error": str(e) }