Skip to main content
Glama

graph-neighbors

Find connected nodes in a knowledge graph by specifying a node ID or label, exploring relationships up to a defined depth and limit. Supports semantic analysis and concept mapping.

Instructions

Get neighbors of a node (by id or label/type) up to a depth and limit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
depthNo
limitNo
nodeYes

Implementation Reference

  • Handler for the 'graph-neighbors' MCP tool. Parses input using GraphNeighborsSchema and calls the graph store's neighbors method to retrieve neighboring nodes.
    case 'graph-neighbors': { const parsed = GraphNeighborsSchema.parse(args); const nodes = graph.neighbors(parsed.node as any, parsed.depth, parsed.limit); return { content: [{ type: 'text', text: JSON.stringify(nodes) }] };
  • Zod schema defining the input structure for the graph-neighbors tool, including node identifier, optional depth and limit parameters.
    export const GraphNeighborsSchema = z.object({ node: z.union([ z.number().int().positive(), z.object({ label: z.string(), type: z.string().optional() }), ]), depth: z.number().int().positive().max(6).optional().default(1), limit: z.number().int().positive().max(200).optional().default(50), }); export type GraphNeighborsInput = z.infer<typeof GraphNeighborsSchema>;
  • src/mcp.ts:170-173 (registration)
    MCP tool registration in the tools array, defining name, description, and basic input schema for 'graph-neighbors'.
    name: 'graph-neighbors', description: 'Get neighbors of a node (by id or label/type) up to a depth and limit.', inputSchema: { type: 'object', properties: { node: { anyOf: [{ type: 'number' }, { type: 'object', properties: { label: { type: 'string' }, type: { type: 'string' } }, required: ['label'] }] }, depth: { type: 'number' }, limit: { type: 'number' } }, required: ['node'] }, },
  • Core implementation of the neighbors traversal algorithm in SqliteGraphStore using BFS to collect neighboring nodes up to specified depth and limit.
    neighbors(node: number | { label: string; type?: string }, depth = 1, limit = 50): GraphNode[] { const startId = this.resolveNodeId(node); if (!startId) return []; const collected: number[] = []; this.bfsTraverse(startId, depth, (dst) => { collected.push(dst); return collected.length < limit; }); return this.nodesByIds(collected); }

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/vjsr007/mcp-index-notes'

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