Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(cli,mcp): implement callgraph query command and tool#8

Merged
iohub merged 11 commits into
mainfrom
feat-callgraph
Jul 7, 2026
Merged

feat(cli,mcp): implement callgraph query command and tool#8
iohub merged 11 commits into
mainfrom
feat-callgraph

Conversation

@iohub

@iohub iohub commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

iohub added 11 commits July 7, 2026 09:24
- Add Callgraph CLI command and codeseek_callgraph MCP tool for bidirectional dependency analysis
- Implement recursive graph traversal to collect callers and callees within a configurable depth (1-3)
- Enable JSON and text outputs for flexible consumption by external tools and developers
- Track visited nodes during JSON collection to prevent infinite recursion from cyclic dependencies
- Update CLI runner and project manifest to support the new command
- Remove mut from debounce_timer in watcher.rs since tokio::pin! internally
  handles the necessary mutability, leaving the explicit keyword unused.
- Add #[allow(dead_code)] to INJECTION_MARKER_END in mcp/server.rs as this
  constant is exclusively referenced in unit tests to verify injection markers,
  which triggers a warning during standard compilation.
…odule

Move the five core callgraph query functions from main.rs to a new
service module. Update mod.rs to properly export the module and its
public functions. Replace the original implementations in main.rs with
thin delegation wrappers to maintain existing function signatures and
call sites.

Add comprehensive unit tests to the new service module covering:
- Linear, branch, converge, cycle, diamond, and empty graph topologies
- Both JSON and text output formatting
- Depth boundary conditions and cycle detection prevention
- Edge cases such as missing functions and isolated nodes

This restructuring improves code organization, testability, and
maintainability without altering external behavior or breaking
existing integrations.
The services module already implements the underlying callgraph logic,
making the intermediate wrappers in main.rs redundant and triggering
dead_code compiler warnings.

- Remove four unused wrapper functions for callers and callees collection
- Update execute_callgraph to delegate directly to the services module
- Clean up unused uuid::Uuid import
…h traversal

Add a visited HashSet parameter to collect_callers_text and
collect_callees_text to track traversed function IDs during
recursion. This resolves an issue where functions reached via
multiple call paths or line numbers were redundantly listed.

- Align text traversal logic with the existing JSON implementation
  that already uses deduplication
- Initialize and pass dedicated visited sets in execute_callgraph
  for callers and callees
- Update affected unit tests to accommodate the new parameter
Update collect_callers_json and collect_callees_json to use a persistent visited set pattern.
The previous implementation modified and reverted the visited set during recursion, causing functions
to be visited multiple times across branches. This resulted in duplicate nodes in the JSON output.

The fix moves the visited check to the start of the loop iteration. If a function is already visited,
it is skipped immediately. Otherwise, it is marked as visited before recursing. This prevents cycles
and ensures consistent results across code paths, matching the behavior of the text functions.
…tool

Update MCP injection template and project documentation to include
the codeseek_callgraph tool at priority level 4. This guides AI
assistants to query full bi-directional calling context when exploring
code dependencies or preparing modifications.

- Sync INJECTION_CONTENT in rust-core/src/mcp/server.rs
- Update injection block in CLAUDE.md
- Add tool entries to MCP integration and CLI command tables in README.md
- Include a usage example demonstrating the callgraph query output
…server

- Update CLI usage block in build.sh to include callgraph query syntax
- Extend MCP server instructions with codeseek_callgraph tool description
- Improve discoverability of bi-directional depth query functionality
Modify the FusedCandidate structure to align with the updated API contract.
- Remove unused symbol_type and language fields from the response payload.
- Add custom serde serialization for final_score to retain exactly 3 decimal places.
- Update hybrid_search.rs to remove field initialization during struct construction.

BREAKING CHANGE: The semantic_search response no longer includes symbol_type and language fields. Clients consuming this API should remove references to these fields.
The language field was accidentally removed alongside symbol_type.
This commit restores it to the FusedCandidate struct definition and
initializes it with an empty string in both the dense fallback and
RRF fusion candidate construction paths. symbol_type remains removed
as requested.
The underlying petgraph::DiGraph allows multi-edges, and add_call_relation
previously lacked duplicate checks. This caused identical call relations to
accumulate, resulting in duplicate outputs for the callers and callees
commands.

- Deduplicate results in get_callers and get_callees using a HashSet
  keyed by (caller_id, callee_id, line_number).
- Add an early return in add_call_relation to skip inserting duplicate
  edges, preventing future data duplication at the source.
@iohub iohub requested a review from cdwenwang July 7, 2026 03:12
@iohub iohub merged commit 4fd92d7 into main Jul 7, 2026
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