Skip to content

Expose bounded AST diff summaries in MCP results#1069

Open
thromel wants to merge 1 commit into
tsantalis:masterfrom
thromel:romel/refactoringminer-mcp-ast-summary
Open

Expose bounded AST diff summaries in MCP results#1069
thromel wants to merge 1 commit into
tsantalis:masterfrom
thromel:romel/refactoringminer-mcp-ast-summary

Conversation

@thromel

@thromel thromel commented May 17, 2026

Copy link
Copy Markdown
Contributor

Why

The MCP tools can already report detected refactorings, but that is often not enough for an agent reviewing a change. For many refactorings, the Git diff is the wrong first view: moved or extracted code turns into a large delete/add block, and the agent has to read a lot before it knows where the structural edits are.

This PR adds a bounded astDiffs field to MCP results. It gives clients a small AST-level index of the change: file pairs, mapping/action counts, counts by action type, sampled actions, line ranges, update values, and move metadata.

Changes

  • Added McpAstDiffResult.
  • Return astDiffs from analysis tools for file contents, worktrees, commits, pull requests, and directories.
  • Added maxAstDiffs and maxActionsPerAstDiff; maxAstDiffs=0 omits the payload.
  • Return the same bounded summaries from WebDiff tools while preserving localhost URL behavior.
  • Tightened sampled action details:
    • missing positions use -1 for offsets and lines
    • GumTree end offsets are treated as exclusive
    • multi-move actions use a real targetFilePath plus separate moveGroupId
  • Reject fractional numeric MCP arguments instead of truncating them.
  • Updated documentation/mcp.md.

What this gives MCP clients

A client can use RefactoringMiner as the first pass in review: see which file pairs changed structurally, which action types dominate, and which nodes deserve source inspection. It does not try to prove a refactoring is safe. It gives the agent a better map before it opens files.

Validation

  • ./gradlew test --tests org.refactoringminer.mcp.RefactoringMinerMcpServiceTest --tests org.refactoringminer.mcp.RefactoringMinerMcpToolsTest --tests org.refactoringminer.mcp.WebDiffBrowserLauncherTest --no-daemon --console=plain
  • ./gradlew shadowJar mcpSmoke --no-daemon --console=plain
  • git diff --check
  • Live Claude Code MCP checks with Sonnet 4.6:
    • file-content analysis returns bounded astDiffs
    • worktree analysis uses astDiffs on this RefactoringMiner branch
    • all 14 MCP tools were exercised in a real tool sweep
    • WebDiff tools return URLs while respecting maxAstDiffs=0
    • fractional maxRefactorings=1.5 is rejected with an error

Related to #1058.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant