Add find_dead_code MCP tool#7
Merged
Merged
Conversation
Flags functions, methods, and classes with no references outside their own body. Each candidate is scored with a confidence in [0.0, 0.99] and a list of human-readable reasons covering privacy, name-share count, language-specific caveats, re-export filenames, and decorators. Excludes Python dunders, 'main', anonymous symbols, and test files (opt in via include_tests=True). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dee7776 to
30ec816
Compare
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
find_dead_codethat flags functions, methods, and classes with no references outside their own body, returning each with a confidence score (0.0-0.99) and human-readable reasons.validate_directory,validate_top_k,ToolLogger,errors.format_error) and matches the response/validation patterns of the other tools.symbolsandreferences_tables; pre-fetches references once and groups by name to avoid an N+1 query pattern.How it works
[line_start, line_end]of its own definition._foo/__foo), public-API risk, name-share count, kind, file (__init__.py/index.{js,ts}/mod.rslower it), and decorator detection (best-effort by reading the line above).main, anonymous symbols, file-fallback symbols, and test files (override viainclude_tests=True).Files changed
queries.py—find_dead_codeplus_is_test_path,_is_excluded_from_dead_code,_score_dead_code_candidate,_has_decorator_above,_source_excerpt.server.py—@mcp.tool() find_dead_code(directory, min_confidence=0.5, kinds=None, include_tests=False, top_k=50)with full input validation.api_types.py—DeadCodeCandidateandFindDeadCodeResponseTypedDicts; added toToolResponseunion.tests/test_dead_code.py— 59 new tests covering helpers, exclusions, scoring, basic detection (dead/alive/recursive/sibling-method), filters (min_confidence/kinds/top_k), response shape, cross-file behavior, server validation, and end-to-end via a pre-populated DB that bypasses embedding-model loading.Test plan
_is_test_path,_is_excluded_from_dead_code,_score_dead_code_candidate,_has_decorator_above,_source_excerpt)main, anonymous, file-fallback, test files (default + opt-in)min_confidence,kinds,top_k, empty kinds list, sorted-desc outputmin_confidence, invalid kinds, oversizedtop_kserver.find_dead_codeagainst a pre-populated DBruff checkclean🤖 Generated with Claude Code