Skip to main content
Glama

update_file_analysis

Update or create file analysis data including symbols, imports, and exports to keep code summaries accurate.

Instructions

Update or create analysis data for a specific file in the TreeSummary system

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file to analyze or update. Used as the primary key for storing analysis data.
analysisDataYesComplete analysis data for the file including symbols, imports, exports, and metadata

Implementation Reference

  • Registration of the 'update_file_analysis' MCP tool in the getTools() method, defining its name, description, input/output schemas, and binding to the updateFileAnalysis handler.
    return [
      {
        name: "update_file_analysis",
        description:
          "Update or create analysis data for a specific file in the TreeSummary system",
        inputSchema: zodToJsonSchema(UpdateFileAnalysisSchema),
        outputSchema: zodToJsonSchema(UpdateFileAnalysisResponseSchema),
        handler: this.updateFileAnalysis.bind(this),
  • The updateFileAnalysis handler method that normalizes snake_case/camelCase args, parses date strings, calls the TreeSummaryService, and returns success/error responses.
    private async updateFileAnalysis(args: any): Promise<TreeSummaryResponse> {
      const startTime = Date.now();
      
      // Map snake_case to camelCase for compatibility
      const normalizedArgs = {
        filePath: args.filePath || args.file_path,
        analysisData: args.analysisData || args.analysis_data
      };
      
      const { filePath, analysisData } = normalizedArgs;
    
      try {
        // Parse date if it's a string
        if (typeof analysisData.lastModified === "string") {
          analysisData.lastModified = new Date(analysisData.lastModified);
        }
    
        const success = await this.treeSummaryService.updateFileAnalysis(
          filePath,
          analysisData
        );
    
        if (success) {
          return createSuccessResponse(
            `Successfully updated analysis for ${filePath}`,
            {
              file_path: filePath,
              analysis_updated: true,
            },
            Date.now() - startTime
          );
        } else {
          return createErrorResponse(
            `Failed to update analysis for ${filePath}`,
            "Update operation returned false",
            "UPDATE_FAILED"
          );
        }
      } catch (error) {
        return createErrorResponse(
          `Error updating analysis for ${filePath}`,
          error instanceof Error ? error.message : String(error),
          "UPDATE_ERROR"
        );
      }
    }
  • The UpdateFileAnalysisSchema Zod schema defining the input shape: filePath (string) and analysisData (object with filePath, hash, lastModified, symbols, imports, exports, size, language).
    export const UpdateFileAnalysisSchema = z.object({
      filePath: z.string().describe("Absolute path to the file to analyze or update. Used as the primary key for storing analysis data."),
      analysisData: z.object({
        filePath: z.string().describe("Absolute path to the file (should match the parent filePath parameter)"),
        hash: z.string().describe("SHA-256 hash of the file content, used to detect changes and avoid unnecessary re-analysis"),
        lastModified: z.string().describe("ISO 8601 timestamp of when the file was last modified"),
        symbols: z.array(z.object({
          name: z.string().describe("Name of the symbol (function, class, variable, etc.)"),
          type: z.enum(['function', 'class', 'variable', 'interface', 'type', 'enum']).describe("Type of the symbol found in the code"),
          line: z.number().describe("Line number where the symbol is defined (1-based)"),
          column: z.number().describe("Column number where the symbol is defined (1-based)"),
          accessibility: z.enum(['public', 'private', 'protected']).optional().describe("Accessibility modifier for the symbol (mainly for class members)"),
          isExported: z.boolean().describe("Whether this symbol is exported from the module")
        })).describe("Array of all symbols (functions, classes, variables, etc.) found in the file"),
        imports: z.array(z.string()).describe("Array of all import statements/dependencies used by this file"),
        exports: z.array(z.string()).describe("Array of all symbols exported by this file"),
        size: z.number().describe("File size in bytes"),
        language: z.string().describe("Programming language detected (e.g., 'typescript', 'javascript', 'python')")
      }).describe("Complete analysis data for the file including symbols, imports, exports, and metadata")
    });
  • The UpdateFileAnalysisResponseSchema Zod schema defining the output shape: success, message, timestamp, execution_time_ms, and data (file_path, analysis_updated).
    export const UpdateFileAnalysisResponseSchema = z.object({
      success: z.boolean().describe("Whether the file analysis update operation succeeded. True if the file analysis was successfully stored or updated in the TreeSummary database."),
      message: z.string().describe("Human-readable message describing the result of the operation. Typically 'Successfully updated analysis for [file_path]' on success or an error description on failure."),
      timestamp: z.string().describe("ISO 8601 timestamp of when the operation completed, automatically generated when the response is created."),
      execution_time_ms: z.number().optional().describe("Time taken to execute the operation in milliseconds, measured from the start of the operation until completion."),
      data: z.object({
        file_path: z.string().describe("Absolute path to the file that was analyzed. This matches the input filePath parameter."),
        analysis_updated: z.boolean().describe("Whether the analysis data was successfully updated. Always true for successful operations, indicating the file's symbols, imports, exports, and metadata were stored.")
      }).optional().describe("Additional data about the operation result. Contains the file path and confirmation that analysis was updated. Only present on successful operations.")
    });
  • The TreeSummaryService.updateFileAnalysis() method: finds project root, invalidates foundation cache, ensures .treesummary directory, writes analysis to .treesummary/files/<relative-path>.json atomically (temp file + rename), and updates project metadata.
    async updateFileAnalysis(filePath: string, analysisData: FileAnalysis): Promise<boolean> {
      try {
        const projectPath = this.findProjectRoot(filePath);
        const treeSummaryPath = path.join(projectPath, this.treeSummaryDir);
        
        // Invalidate relevant foundation cache entries
        if (this.foundationCache) {
          try {
            // Invalidate project-level caches since file analysis changed
            await this.foundationCache.invalidateCache({
              filePath: projectPath,
              templateId: 'project_overview'
            });
          } catch (error) {
            console.warn('Failed to invalidate foundation cache:', error);
          }
        }
        
        // Ensure .treesummary directory exists
        await this.ensureTreeSummaryDirectory(treeSummaryPath);
        
        // Create atomic file write with directory structure preservation
        const relativeFilePath = path.relative(projectPath, filePath);
        
        // Create clean mirror structure: .treesummary/files/path/to/file.ext.json
        const analysisFile = path.join(treeSummaryPath, 'files', relativeFilePath + '.json');
        
        // Ensure files directory exists
        await fs.mkdir(path.dirname(analysisFile), { recursive: true });
        
        // Write to temporary file first for atomic operation
        const tempFile = analysisFile + '.tmp';
        await fs.writeFile(tempFile, JSON.stringify(analysisData, null, 2));
        
        // Atomic rename
        await fs.rename(tempFile, analysisFile);
        
        // Update project metadata
        await this.updateProjectMetadata(projectPath);
        
        return true;
      } catch (error) {
        console.error(`Failed to update file analysis for ${filePath}:`, error);
        return false;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It does not disclose mutation effects, idempotency, permissions, or side effects. The agent cannot infer consequences of invoking this tool beyond the stated purpose.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that front-loads the purpose. No redundant words or unnecessary details. Every word contributes to understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of the input schema (nested object with many fields) and the lack of an output schema, the description is too brief. It fails to explain expected behavior on update vs create, return values, or error conditions, leaving the agent underinformed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with detailed descriptions for all parameters. The description adds a high-level summary ('Complete analysis data...') but does not provide additional meaning beyond what the schema already offers. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Update or create'), the resource ('analysis data for a specific file'), and the system ('TreeSummary system'). It distinguishes from siblings like 'analyze_file_symbols' (which likely performs the actual analysis) and 'remove_file_analysis' (deletion).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives such as 'analyze_file_symbols' (which might create initial analysis) or when to update vs create. No prerequisites, exclusions, or contextual hints are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/ZachHandley/ZMCPTools'

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