Skip to main content
Glama

get_file_summary

Summarize file details, including line count, function/class definitions, import statements, and complexity metrics, to analyze and understand code structure efficiently.

Instructions

Get a summary of a specific file, including: - Line count - Function/class definitions (for supported languages) - Import statements - Basic complexity metrics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes

Implementation Reference

  • Registration and handler for the MCP 'get_file_summary' tool. Delegates to CodeIntelligenceService.analyze_file()
    @mcp.tool() @handle_mcp_tool_errors(return_type='dict') def get_file_summary(file_path: str, ctx: Context) -> Dict[str, Any]: """ Get a summary of a specific file, including: - Line count - Function/class definitions (for supported languages) - Import statements - Basic complexity metrics """ return CodeIntelligenceService(ctx).analyze_file(file_path)
  • Service layer handler analyze_file that retrieves summary from index_manager.get_file_summary() and handles cases where deep index is missing
    def analyze_file(self, file_path: str) -> Dict[str, Any]: """ Analyze a file and return comprehensive intelligence. This is the main business method that orchestrates the file analysis workflow, choosing the best analysis strategy and providing rich insights about the code. Args: file_path: Path to the file to analyze (relative to project root) Returns: Dictionary with comprehensive file analysis Raises: ValueError: If file path is invalid or analysis fails """ # Business validation self._validate_analysis_request(file_path) # Use the global index manager index_manager = get_index_manager() # Debug logging logger.info(f"Getting file summary for: {file_path}") logger.info(f"Index manager state - Project path: {index_manager.project_path}") logger.info(f"Index manager state - Has builder: {index_manager.index_builder is not None}") if index_manager.index_builder: logger.info(f"Index manager state - Has index: {index_manager.index_builder.in_memory_index is not None}") # Get file summary from JSON index summary = index_manager.get_file_summary(file_path) logger.info(f"Summary result: {summary is not None}") # If deep index isn't available yet, return a helpful hint instead of error if not summary: return { "status": "needs_deep_index", "message": "Deep index not available. Please run build_deep_index before calling get_file_summary.", "file_path": file_path } return summary
  • Core implementation of get_file_summary: queries SQLite database for file metadata and symbols, categorizes functions/classes/methods, and constructs the summary dictionary
    def get_file_summary(self, file_path: str) -> Optional[Dict[str, Any]]: """Return summary information for a file from SQLite storage.""" with self._lock: if not isinstance(file_path, str): logger.error("File path must be a string, got %s", type(file_path)) return None if not self.store or not self._is_loaded: if not self.load_index(): return None normalized = _normalize_path(file_path) with self.store.connect() as conn: row = conn.execute( """ SELECT id, language, line_count, imports, exports, docstring FROM files WHERE path = ? """, (normalized,), ).fetchone() if not row: logger.warning("File not found in index: %s", normalized) return None symbol_rows = conn.execute( """ SELECT type, line, signature, docstring, called_by, short_name FROM symbols WHERE file_id = ? ORDER BY line ASC """, (row["id"],), ).fetchall() imports = _safe_json_loads(row["imports"]) exports = _safe_json_loads(row["exports"]) categorized = _categorize_symbols(symbol_rows) return { "file_path": normalized, "language": row["language"], "line_count": row["line_count"], "symbol_count": len(symbol_rows), "functions": categorized["functions"], "classes": categorized["classes"], "methods": categorized["methods"], "imports": imports, "exports": exports, "docstring": row["docstring"], }
  • Thin wrapper in DeepIndexManager delegating to SQLiteIndexManager
    def get_file_summary(self, file_path: str) -> Optional[Dict[str, Any]]: return self._mgr.get_file_summary(file_path)
  • Helper function to categorize symbols into functions, classes, and methods for the file summary
    def _categorize_symbols(symbol_rows) -> Dict[str, List[Dict[str, Any]]]: functions: List[Dict[str, Any]] = [] classes: List[Dict[str, Any]] = [] methods: List[Dict[str, Any]] = [] for row in symbol_rows: symbol_type = row["type"] called_by = _safe_json_loads(row["called_by"]) info = { "name": row["short_name"], "called_by": called_by, "line": row["line"], "signature": row["signature"], "docstring": row["docstring"], } signature = row["signature"] or "" if signature.startswith("def ") and "::" in signature: methods.append(info) elif signature.startswith("def "): functions.append(info) elif signature.startswith("class ") or symbol_type == "class": classes.append(info) else: if symbol_type == "method": methods.append(info) elif symbol_type == "class": classes.append(info) else: functions.append(info) functions.sort(key=lambda item: item.get("line") or 0) classes.sort(key=lambda item: item.get("line") or 0) methods.sort(key=lambda item: item.get("line") or 0) return { "functions": functions, "classes": classes, "methods": methods, }

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/johnhuang316/code-index-mcp'

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