Ragex.MCP.Handlers.Tools (Ragex v0.32.1)

View Source

Handles MCP tool-related requests (tools/list and tools/call).

Implements the full Ragex MCP tool catalogue (~50 tools across categories):

  • Core analysis: analyze_file, analyze_directory, query_graph, list_nodes
  • File watching: watch_directory, unwatch_directory, list_watched
  • Semantic search: semantic_search, hybrid_search, get_embeddings_stats, metaast_search, cross_language_alternatives, expand_query, find_metaast_pattern
  • Graph algorithms: find_paths, find_callers, graph_stats, betweenness_centrality, closeness_centrality, detect_communities, export_graph
  • Code editing: edit_file, edit_files, validate_edit, rollback_edit, edit_history, refactor_code, advanced_refactor
  • Refactor previews: preview_refactor, refactor_conflicts, undo_refactor, refactor_history, visualize_impact
  • Quality & complexity: analyze_quality, quality_report, find_complex_code
  • Security: scan_security, security_audit, check_secrets, analyze_security_issues
  • Code analysis: find_dead_code, analyze_dead_code_patterns, find_duplicates, find_similar_code, detect_smells, analyze_business_logic
  • Dependencies: analyze_dependencies, find_circular_dependencies, coupling_report
  • Impact & suggestions: analyze_impact, estimate_refactoring_effort, risk_assessment, suggest_refactorings, explain_suggestion
  • Semantic / OpKind: semantic_operations, semantic_analysis
  • RAG pipeline: rag_query, rag_explain, rag_suggest (+ _stream variants)
  • AI features: validate_with_ai
  • AI usage tracking: get_ai_usage, get_ai_cache_stats, clear_ai_cache
  • Agent: agent_analyze, agent_chat, agent_session_info, agent_list_sessions, agent_clear_session, read_file
  • Git archaeology: git_blame, git_history, git_pr_info, co_change_analysis, git_enrich

Summary

Functions

Full-featured betweenness_centrality implementation (honors max_nodes/ normalize, sorts and formats results). Public so Ragex.Plugins.GraphAnalytics can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

Executes a tool call.

Executes a streaming tool call, pushing partial chunks via progress_fn.

Executes multiple tool calls concurrently in parallel.

Full-featured check_secrets implementation (file or directory, uses the Security analyzer's :hardcoded_secret category -- not BusinessLogic). Public so Ragex.Plugins.SecurityAudit can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

Full-featured detect_smells implementation (file or directory, thresholds, smell_types filter, min_severity). Public so Ragex.Plugins.CodeQuality can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

Full-featured find_dead_code implementation (scope, min_confidence, exclude_tests, include_callbacks, multiple output formats). Public so Ragex.Plugins.CodeQuality can delegate to it rather than shadowing it with a single-file stub -- see the Ragex Codebase Health & Architecture Improvement Plan.

Full-featured find_duplicates implementation (two-file comparison mode, directory scanning, threshold/exclude_patterns options, error handling). Public so Ragex.Plugins.CodeQuality can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

Lists all available tools.

Full-featured query_graph implementation (find_module/find_function/get_calls/ get_dependencies/get_callers, with PageRank enrichment). Public so Ragex.Plugins.GraphAnalytics can delegate to it rather than shadowing it with a stub -- see the Ragex Codebase Health & Architecture Improvement Plan.

Full-featured scan_security implementation (file or directory, category filtering, aggregated severity counts). Public so Ragex.Plugins.SecurityAudit can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

Functions

betweenness_centrality_tool(params)

@spec betweenness_centrality_tool(map()) :: {:ok, map()}

Full-featured betweenness_centrality implementation (honors max_nodes/ normalize, sorts and formats results). Public so Ragex.Plugins.GraphAnalytics can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

call_tool(tool_name, arguments)

Executes a tool call.

call_tool_streaming(tool_name, arguments, progress_fn)

@spec call_tool_streaming(String.t(), map(), function()) :: term()

Executes a streaming tool call, pushing partial chunks via progress_fn.

progress_fn has signature (partial_text :: String.t(), done :: boolean()) -> any(). It is called once per content chunk from the underlying AI stream, and once with done: true after the final chunk. Non-streaming tools fall back to call_tool/2.

call_tools(tool_requests)

Executes multiple tool calls concurrently in parallel.

check_secrets_tool(params)

@spec check_secrets_tool(map()) :: {:ok, map()}

Full-featured check_secrets implementation (file or directory, uses the Security analyzer's :hardcoded_secret category -- not BusinessLogic). Public so Ragex.Plugins.SecurityAudit can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

detect_smells_tool(params)

@spec detect_smells_tool(map()) :: {:ok, map()} | {:error, term()}

Full-featured detect_smells implementation (file or directory, thresholds, smell_types filter, min_severity). Public so Ragex.Plugins.CodeQuality can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

find_dead_code_tool(params)

@spec find_dead_code_tool(map()) :: {:ok, map()} | {:error, term()}

Full-featured find_dead_code implementation (scope, min_confidence, exclude_tests, include_callbacks, multiple output formats). Public so Ragex.Plugins.CodeQuality can delegate to it rather than shadowing it with a single-file stub -- see the Ragex Codebase Health & Architecture Improvement Plan.

find_duplicates_tool(params)

@spec find_duplicates_tool(map()) :: {:ok, term()} | {:error, term()}

Full-featured find_duplicates implementation (two-file comparison mode, directory scanning, threshold/exclude_patterns options, error handling). Public so Ragex.Plugins.CodeQuality can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.

format_reason(reason)

@spec format_reason(term()) :: String.t()

list_tools()

@spec list_tools() :: map()

Lists all available tools.

query_graph(arg1)

@spec query_graph(map()) :: {:ok, map()} | {:error, String.t()}

Full-featured query_graph implementation (find_module/find_function/get_calls/ get_dependencies/get_callers, with PageRank enrichment). Public so Ragex.Plugins.GraphAnalytics can delegate to it rather than shadowing it with a stub -- see the Ragex Codebase Health & Architecture Improvement Plan.

scan_security_tool(params)

@spec scan_security_tool(map()) :: {:ok, map()}

Full-featured scan_security implementation (file or directory, category filtering, aggregated severity counts). Public so Ragex.Plugins.SecurityAudit can delegate to it -- see the Ragex Codebase Health & Architecture Improvement Plan.