Skip to content

get_node and get_neighbors disagree on the same label — get_node returns an arbitrary iteration-order match #3160

Closed

Description

@noQbot

Summary

The MCP get_node and get_neighbors tools resolve a label differently, so the same lookup can return inconsistent answers. get_node does a raw substring scan over G.nodes(data=True) and returns matches[0] — whichever node comes first in graph iteration order. get_neighbors uses the tiered _find_node ranking plus find_node_ambiguity, which was added specifically so equally-good matches aren't
silently broken by iteration order.

For a hub name that matches several nodes in different files, get_node returns an arbitrary one while get_neighbors correctly reports the lookup as ambiguous.

Steps to reproduce

  1. Run the MCP server against a graph where one label matches multiple nodes in different files (e.g. extract — an extract() entrypoint plus several extract_* helper nodes).
  2. get_node({"label": "extract"}) → returns one node, e.g. extract_bash() in graphify/extractors/bash.py.
  3. get_neighbors({"label": "extract"}) on the same server → returns Ambiguous: 'extract' matches N nodes in different files … retry with the repo-relative path or the full node id.

Expected behavior

Both tools resolve the same label the same way — either both return the same node, or both report it as ambiguous. A hub-name lookup should not silently pick one symbol.

Actual behavior

get_node returns an arbitrary match determined by G.nodes() iteration order (so a graph rebuild that reorders nodes can change the answer), while get_neighbors reports ambiguity. A caller looking up a hub name via get_node gets the wrong symbol with no signal that a tie was broken.

Root cause

  • _tool_get_node (graphify/serve.py): matches = [(nid, d) for nid, d in G.nodes(data=True) if <substring>] then matches[0].
  • _tool_get_neighbors (graphify/serve.py): _find_node(G, label) + find_node_ambiguity(G, label).

find_node_ambiguity exists precisely to stop [0]-of-a-tie from presenting one arbitrary file as "the answer"; get_node never went through it.

Fix

Route get_node through the same resolver as get_neighbors so both share one resolution contract (tiered match + cross-file ambiguity). get_node then returns the tiered winner, or the same "Ambiguous — retry with path or id" message when the
winning tier spans several files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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