read_interface
Extract function signatures, class definitions, and docstrings from code files to understand module usage without reading full implementations.
Instructions
📖 READ INTERFACE: Get a high-level overview of a file without reading implementation.
Returns function signatures, class definitions, and docstrings. Perfect for understanding how to USE a module without reading the whole thing.
INPUTS:
root_path: The ABSOLUTE path to the project root
file_path: The path to the specific file you want to read (can be relative to root)
EXAMPLE: read_interface("/Users/john/project", "src/auth.py")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| root_path | Yes | ||
| file_path | Yes |
Implementation Reference
- src/xray/mcp_server.py:200-219 (handler)MCP tool handler decorated with @mcp.tool. Delegates to XRayIndexer.read_interface after getting the indexer instance for the root_path.@mcp.tool def read_interface(root_path: str, file_path: str) -> str: """ 📖 READ INTERFACE: Get a high-level overview of a file without reading implementation. Returns function signatures, class definitions, and docstrings. Perfect for understanding how to USE a module without reading the whole thing. INPUTS: - root_path: The ABSOLUTE path to the project root - file_path: The path to the specific file you want to read (can be relative to root) EXAMPLE: read_interface("/Users/john/project", "src/auth.py") """ try: indexer = get_indexer(root_path) return indexer.read_interface(file_path) except Exception as e: return f"Error reading interface: {str(e)}"
- src/xray/core/indexer.py:282-319 (helper)Core logic for reading a file's interface: resolves path, extracts skeleton using _get_file_skeleton_enhanced (signatures and docstrings via AST/regex), handles errors.def read_interface(self, file_path: str) -> str: """ Read the interface (skeleton) of a specific file. Returns function signatures, class definitions, and types, but hides implementation details. """ try: # Resolve path target_path = Path(file_path) if not target_path.is_absolute(): target_path = (self.root_path / target_path).resolve() # Security check: ensure inside root try: target_path.relative_to(self.root_path) except ValueError: if not str(target_path).startswith(str(self.root_path)): # Allow if it's the file itself provided as root, otherwise strictly enforce pass if not target_path.exists() or not target_path.is_file(): return f"Error: File '{file_path}' not found or is not a file." # Use the existing skeleton logic, but with a high limit on symbols skeleton = self._get_file_skeleton_enhanced(target_path, max_symbols=1000) if not skeleton: # Fallback: if no symbols found or language not supported, # maybe just read the first few lines? or return message? language = LANGUAGE_MAP.get(target_path.suffix.lower()) if not language: return f"File type '{target_path.suffix}' not supported for interface extraction." return "No symbols found in file." return "\n".join(skeleton) except Exception as e: return f"Error reading interface: {str(e)}"