Skip to main content
Glama

analyze_diff

Analyze git diffs (staged, unstaged, or all changes) against IDE rules to detect violations. Apply filters like 'Violations' or 'Human Review Required' and speed up analysis with speed mode. Returns a list of rule violations for review.

Instructions

This tool is used to analyze a git diff (unstaged, staged, or all changes) against IDE rules to identify rule violations. By default, the tool will use the staged changes, unless the user explicitly asks for unstaged or all changes.

Parameters:

  • params: An object containing:

    • speedMode: boolean - A mode that can be enabled to speed up the analysis. Default value is false.

    • filterBy: enum - "Violations" | "Compliants" | "Human Review Required" | "None" - A filter that can be applied to set the focus of the analysis. Default is None.

    • diff: string - A git diff string.

    • rules: string - Rules to use for analysis, found in the rules subdirectory of the IDE workspace settings. Combine all rules from multiple files by separating them with ---

Returns:

  • A list of rule violations found in the git diff.

Input Schema

NameRequiredDescriptionDefault
paramsNo

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "params": { "additionalProperties": false, "properties": { "diff": { "description": "Git diff content to analyze. Defaults to staged changes, unless the user explicitly asks for unstaged changes or all changes.", "type": "string" }, "filterBy": { "default": "None", "description": "Analysis filter. Defaults to None", "enum": [ "Violations", "Compliants", "Human Review Required", "None" ], "type": "string" }, "rules": { "description": "Rules to use for analysis, found in the rules subdirectory of the IDE workspace settings. Combine all rules from multiple files by separating them with ---", "type": "string" }, "speedMode": { "default": false, "description": "The status of speed mode. Defaults to false.", "type": "boolean" } }, "required": [ "diff", "rules" ], "type": "object" } }, "type": "object" }

Implementation Reference

  • The main handler function that executes the analyze_diff tool logic. It uses CircletClient to review git diff against provided rules and returns violations or compliance message.
    export const analyzeDiff: ToolCallback<{ params: typeof analyzeDiffInputSchema; }> = async (args) => { const { diff, rules, speedMode, filterBy } = args.params; const circlet = new CircletClient(); if (!diff) { return { content: [ { type: 'text', text: 'No diff found. Please provide a diff to analyze.', }, ], }; } if (!rules) { return { content: [ { type: 'text', text: 'No rules found. Please add rules to your repository.', }, ], }; } const response = await circlet.circlet.ruleReview({ diff, rules, filterBy, speedMode, }); if (!response.isRuleCompliant) { return { content: [ { type: 'text', text: response.relatedRules.violations .map((violation) => { return `Rule: ${violation.rule}\nReason: ${violation.reason}\nConfidence Score: ${violation.confidenceScore}`; }) .join('\n\n'), }, ], }; } return { content: [ { type: 'text', text: `All rules are compliant.`, }, ], }; };
  • Zod schema defining the input parameters for the analyze_diff tool: speedMode, filterBy, diff, rules.
    export const analyzeDiffInputSchema = z.object({ speedMode: z .boolean() .default(false) .describe('The status of speed mode. Defaults to false.'), filterBy: z .nativeEnum(FilterBy) .default(FilterBy.none) .describe(`Analysis filter. Defaults to ${FilterBy.none}`), diff: z .string() .describe( 'Git diff content to analyze. Defaults to staged changes, unless the user explicitly asks for unstaged changes or all changes.', ), rules: z .string() .describe( 'Rules to use for analysis, found in the rules subdirectory of the IDE workspace settings. Combine all rules from multiple files by separating them with ---', ), });
  • Local tool registration exporting the analyzeDiffTool object with name 'analyze_diff', description, and inputSchema.
    export const analyzeDiffTool = { name: 'analyze_diff' as const, description: ` This tool is used to analyze a git diff (unstaged, staged, or all changes) against IDE rules to identify rule violations. By default, the tool will use the staged changes, unless the user explicitly asks for unstaged or all changes. Parameters: - params: An object containing: - speedMode: boolean - A mode that can be enabled to speed up the analysis. Default value is false. - filterBy: enum - "${FilterBy.violations}" | "${FilterBy.compliants}" | "${FilterBy.humanReviewRequired}" | "${FilterBy.none}" - A filter that can be applied to set the focus of the analysis. Default is ${FilterBy.none}. - diff: string - A git diff string. - rules: string - Rules to use for analysis, found in the rules subdirectory of the IDE workspace settings. Combine all rules from multiple files by separating them with --- Returns: - A list of rule violations found in the git diff. `, inputSchema: analyzeDiffInputSchema, };
  • Registration of analyze_diff tool in the main CircleCI tools list: imported, added to CCI_TOOLS array (line 42), and handler mapped in CCI_HANDLERS (line 70). Note: startLine approximate for block.
    import { analyzeDiffTool } from './tools/analyzeDiff/tool.js'; import { analyzeDiff } from './tools/analyzeDiff/handler.js'; import { runRollbackPipelineTool } from './tools/runRollbackPipeline/tool.js'; import { runRollbackPipeline } from './tools/runRollbackPipeline/handler.js'; // Define the tools with their configurations export const CCI_TOOLS = [ getBuildFailureLogsTool, getFlakyTestLogsTool, getLatestPipelineStatusTool, getJobTestResultsTool, configHelperTool, createPromptTemplateTool, recommendPromptTemplateTestsTool, runPipelineTool, listFollowedProjectsTool, runEvaluationTestsTool, rerunWorkflowTool, analyzeDiffTool, runRollbackPipelineTool, ]; // Extract the tool names as a union type type CCIToolName = (typeof CCI_TOOLS)[number]['name']; export type ToolHandler<T extends CCIToolName> = ToolCallback<{ params: Extract<(typeof CCI_TOOLS)[number], { name: T }>['inputSchema']; }>; // Create a type for the tool handlers that directly maps each tool to its appropriate input schema type ToolHandlers = { [K in CCIToolName]: ToolHandler<K>; }; export const CCI_HANDLERS = { get_build_failure_logs: getBuildFailureLogs, find_flaky_tests: getFlakyTestLogs, get_latest_pipeline_status: getLatestPipelineStatus, get_job_test_results: getJobTestResults, config_helper: configHelper, create_prompt_template: createPromptTemplate, recommend_prompt_template_tests: recommendPromptTemplateTests, run_pipeline: runPipeline, list_followed_projects: listFollowedProjects, run_evaluation_tests: runEvaluationTests, rerun_workflow: rerunWorkflow, analyze_diff: analyzeDiff, run_rollback_pipeline: runRollbackPipeline, } satisfies ToolHandlers;

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/ampcome-mcps/circleci-mcp'

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