| 311 | } |
| 312 | |
| 313 | func handleGetDiff(ctx context.Context, req *mcp.CallToolRequest, input DiffInput) (*mcp.CallToolResult, any, error) { |
| 314 | ref := input.Ref |
| 315 | if ref == "" { |
| 316 | ref = "main" |
| 317 | } |
| 318 | |
| 319 | absRoot, err := filepath.Abs(input.Path) |
| 320 | if err != nil { |
| 321 | return errorResult("Invalid path: " + err.Error()), nil, nil |
| 322 | } |
| 323 | |
| 324 | diffInfo, err := scanner.GitDiffInfo(absRoot, ref) |
| 325 | if err != nil { |
| 326 | return errorResult("Git diff error: " + err.Error() + "\nMake sure '" + ref + "' is a valid branch/ref"), nil, nil |
| 327 | } |
| 328 | |
| 329 | if len(diffInfo.Changed) == 0 { |
| 330 | return textResult("No files changed vs " + ref), nil, nil |
| 331 | } |
| 332 | |
| 333 | gitCache := scanner.NewGitIgnoreCache(input.Path) |
| 334 | files, err := scanner.ScanFiles(input.Path, gitCache, nil, nil) |
| 335 | if err != nil { |
| 336 | return errorResult("Scan error: " + err.Error()), nil, nil |
| 337 | } |
| 338 | |
| 339 | files = scanner.FilterToChangedWithInfo(files, diffInfo) |
| 340 | impact := scanner.AnalyzeImpact(absRoot, files) |
| 341 | |
| 342 | project := scanner.Project{ |
| 343 | Root: absRoot, |
| 344 | Mode: "tree", |
| 345 | Files: files, |
| 346 | DiffRef: ref, |
| 347 | Impact: impact, |
| 348 | } |
| 349 | |
| 350 | var buf bytes.Buffer |
| 351 | render.Tree(&buf, project) |
| 352 | output := stripANSI(buf.String()) |
| 353 | |
| 354 | return textResult(output), nil, nil |
| 355 | } |
| 356 | |
| 357 | func handleFindFile(ctx context.Context, req *mcp.CallToolRequest, input FindInput) (*mcp.CallToolResult, any, error) { |
| 358 | gitCache := scanner.NewGitIgnoreCache(input.Path) |