Skip to content

refactor: consolidate call hierarchy tools into single unified tool #140

@BumpyClock

Description

@BumpyClock

Summary

The current LSP-MCP server exposes 3 separate call hierarchy tools that could be consolidated into a single, more intuitive tool.

Current State

Three separate tools:

  1. prepare_call_hierarchy

    • Returns call hierarchy items at a position
    • This is an intermediate LSP call - not useful standalone
    • Requires follow-up with incoming_calls or outgoing_calls
  2. incoming_calls

    • Finds functions that call the function at position
    • Requires internal handling of prepare_call_hierarchy first
  3. outgoing_calls

    • Finds functions called by the function at position
    • Also requires prepare_call_hierarchy internally

Problems:

  1. prepare_call_hierarchy is useless alone - An LLM has to know to call incoming_calls or outgoing_calls afterward
  2. Three tools for one concept - Adds cognitive overhead and tool list bloat
  3. Inconsistent with other tools - No other LSP feature is split across multiple tools like this

Proposed Change

Consolidate into a single call_graph tool:

#[tool(description = "Find incoming/outgoing function calls at a position")]
async fn call_graph(
    &self,
    path: String,
    line: u32,
    character: u32,
    direction: String,  // "incoming" | "outgoing" | "both"
    include_raw_response: Option<bool>,
) -> ToolOutput

Usage examples:

// Find what calls this function
{"path": "src/mcp.rs", "line": 32, "character": 13, "direction": "incoming"}

// Find what this function calls
{"path": "src/mcp.rs", "line": 32, "character": 13, "direction": "outgoing"}

// Get full call graph (both directions)
{"path": "src/mcp.rs", "line": 32, "character": 13, "direction": "both"}

Response format:

{
  "function": {
    "name": "definitions_in_file",
    "location": {"path": "src/mcp.rs", "line": 32, "character": 13}
  },
  "incoming_calls": [...],  // present if direction is "incoming" or "both"
  "outgoing_calls": [...]   // present if direction is "outgoing" or "both"
}

Implementation Notes

  • Internally, call_graph would still call prepare_call_hierarchy first
  • The consolidation is purely at the MCP tool interface level
  • Backwards compatibility: Keep old tools available but remove from presets

Impact

  • Reduces tool count by 2 (3 tools → 1 tool)
  • Simpler mental model for LLM agents
  • More intuitive API - one tool for call relationships
  • Optional "both" direction enables richer analysis in single call

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions