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
| Name | Required | Description | Default |
|---|---|---|---|
| depth | No | ||
| limit | No | ||
| node | Yes |
Implementation Reference
- src/mcp.ts:1274-1277 (handler)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) }] };
- src/types.ts:60-68 (schema)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'] }, },
- src/graph.ts:159-168 (helper)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); }