Skip to main content
Glama

twining_neighbors

Explore connections in a knowledge graph by traversing from an entity to related nodes, with configurable depth and relation filtering to understand entity relationships.

Instructions

Traverse the knowledge graph from an entity, returning neighbors up to a given depth (max 3). Supports filtering by relation type. Useful for understanding how entities connect.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityYesEntity ID or name to start traversal from
depthNoTraversal depth (1-3, default: 1)
relation_typesNoFilter to only these relation types

Implementation Reference

  • Registration and handler definition for twining_neighbors tool. It calls the engine.neighbors method.
    // twining_neighbors — Traverse neighbors from an entity
    server.registerTool(
      "twining_neighbors",
      {
        description:
          "Traverse the knowledge graph from an entity, returning neighbors up to a given depth (max 3). Supports filtering by relation type. Useful for understanding how entities connect.",
        inputSchema: {
          entity: z
            .string()
            .describe("Entity ID or name to start traversal from"),
          depth: z
            .number()
            .optional()
            .describe("Traversal depth (1-3, default: 1)"),
          relation_types: z
            .array(z.string())
            .optional()
            .describe("Filter to only these relation types"),
        },
      },
      async (args) => {
        try {
          const result = await engine.neighbors(
            args.entity,
            args.depth,
            args.relation_types,
          );
          return toolResult(result);
        } catch (e) {
          if (e instanceof TwiningError) {
            return toolError(e.message, e.code);
          }
          return toolError(
            e instanceof Error ? e.message : "Unknown error",
            "INTERNAL_ERROR",
          );
        }
      },
    );
  • Implementation of the neighbor traversal logic (GraphEngine.neighbors).
    async neighbors(
      entityIdOrName: string,
      depth?: number,
      relationTypes?: string[],
    ): Promise<NeighborsResult> {
      // Resolve center entity
      const center = await this.resolveEntity(entityIdOrName);
      if (!center) {
        throw new TwiningError(
          `Entity not found: "${entityIdOrName}"`,
          "NOT_FOUND",
        );
      }
    
      const maxDepth = Math.min(Math.max(depth ?? 1, 1), 3);
      const relations = await this.graphStore.getRelations();
      const entities = await this.graphStore.getEntities();
    
      // Build entity lookup map
      const entityMap = new Map<string, Entity>();
      for (const e of entities) {
        entityMap.set(e.id, e);
      }
    
      // Filter relations by type if specified
      const filteredRelations = relationTypes
        ? relations.filter((r) => relationTypes.includes(r.type))
        : relations;
    
      // Build adjacency list: entityId -> [{neighborId, relation, direction}]
      const adjacency = new Map<
        string,
        { neighborId: string; relation: Relation; direction: RelationDirection }[]
      >();
    
      for (const rel of filteredRelations) {
        // Outgoing: source -> target
        if (!adjacency.has(rel.source)) adjacency.set(rel.source, []);
        adjacency.get(rel.source)!.push({
          neighborId: rel.target,
          relation: rel,
          direction: "outgoing",
        });
    
        // Incoming: target -> source
        if (!adjacency.has(rel.target)) adjacency.set(rel.target, []);
        adjacency.get(rel.target)!.push({
          neighborId: rel.source,
          relation: rel,
          direction: "incoming",
        });
      }
    
      // BFS
      const visited = new Set<string>();
      visited.add(center.id);
    
      const result: NeighborEntry[] = [];
      let frontier = [center.id];
    
      for (let d = 0; d < maxDepth; d++) {
        const nextFrontier: string[] = [];
    
        for (const nodeId of frontier) {
          const neighbors = adjacency.get(nodeId) ?? [];
          for (const { neighborId, relation, direction } of neighbors) {
            if (!visited.has(neighborId)) {
              visited.add(neighborId);
              const entity = entityMap.get(neighborId);
              if (entity) {
                result.push({ entity, relation, direction });
                nextFrontier.push(neighborId);
              }
            }
          }
        }
    
        frontier = nextFrontier;
        if (frontier.length === 0) break;
      }
    
      return { center, neighbors: result };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions traversal depth limits (max 3) and filtering capabilities, but fails to cover critical aspects such as whether this is a read-only operation, potential performance impacts, error handling, or output format. For a graph traversal tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, consisting of two sentences that efficiently convey the core functionality and utility without unnecessary details. Every sentence earns its place by defining the operation and its use case.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of graph traversal, lack of annotations, and absence of an output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., structure of returned neighbors), error conditions, or behavioral constraints beyond depth limits. This leaves the agent under-informed for effective tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema already documents all parameters (entity, depth, relation_types) with descriptions. The description adds minimal value beyond the schema by implying the purpose of traversal and filtering, but doesn't provide additional syntax, format details, or examples. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: traversing a knowledge graph from an entity to return neighbors up to a depth of 3 with relation type filtering. It specifies the verb ('traverse'), resource ('knowledge graph'), and scope ('neighbors up to a given depth'). However, it doesn't explicitly differentiate from sibling tools like 'twining_graph_query' or 'twining_trace', which might have overlapping functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by stating it's 'useful for understanding how entities connect,' which suggests context for exploring relationships. However, it lacks explicit guidance on when to use this tool versus alternatives (e.g., 'twining_graph_query' or 'twining_trace'), prerequisites, or exclusions, leaving the agent to infer based on general utility.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daveangulo/twining-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server