Skip to main content
Glama

graph-path

Identify paths between nodes in a graph by specifying start and end points using IDs or labels. Supports exploration of relationships with customizable depth for efficient analysis.

Instructions

Find a path of nodes from A to B (by id or label/type).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromYes
maxDepthNo
toYes

Implementation Reference

  • MCP tool handler for 'graph-path': parses arguments using GraphPathSchema, invokes graph.path() method, and returns JSON serialized path nodes.
    case 'graph-path': { const parsed = GraphPathSchema.parse(args); const nodes = graph.path(parsed.from as any, parsed.to as any, parsed.maxDepth); return { content: [{ type: 'text', text: JSON.stringify(nodes) }] }; }
  • Zod schema definition GraphPathSchema used for input validation of the graph-path tool, supporting node IDs or label/type objects for 'from' and 'to', with optional maxDepth.
    export const GraphPathSchema = z.object({ from: z.union([ z.number().int().positive(), z.object({ label: z.string(), type: z.string().optional() }), ]), to: z.union([ z.number().int().positive(), z.object({ label: z.string(), type: z.string().optional() }), ]), maxDepth: z.number().int().positive().max(10).optional().default(4), }); export type GraphPathInput = z.infer<typeof GraphPathSchema>;
  • src/mcp.ts:175-178 (registration)
    Tool registration object added to the MCP tools array, defining name, description, and inputSchema for graph-path.
    name: 'graph-path', description: 'Find a path of nodes from A to B (by id or label/type).', inputSchema: { type: 'object', properties: { from: { anyOf: [{ type: 'number' }, { type: 'object', properties: { label: { type: 'string' }, type: { type: 'string' } }, required: ['label'] }] }, to: { anyOf: [{ type: 'number' }, { type: 'object', properties: { label: { type: 'string' }, type: { type: 'string' } }, required: ['label'] }] }, maxDepth: { type: 'number' } }, required: ['from', 'to'] }, },
  • Core path-finding implementation in SqliteGraphStore using BFS (via bfsPath helper), resolving node IDs, querying DB for path nodes, and mapping to GraphNode objects.
    path(from: number | { label: string; type?: string }, to: number | { label: string; type?: string }, maxDepth = 4): GraphNode[] { const fromId = this.resolveNodeId(from); const toId = this.resolveNodeId(to); if (!fromId || !toId) return []; const ids = this.bfsPath(fromId, toId, maxDepth); if (!ids.length) return []; const rows = this.db.prepare(`SELECT id,label,type,props FROM graph_nodes WHERE id IN (${ids.map(() => '?').join(',')})`).all(...ids) as any[]; const byId = new Map(rows.map((r) => [r.id, r] as const)); return ids.map((id) => this.mapRow(byId.get(id)!)); }
  • IGraphStore interface definition for the path method, which the tool handler invokes.
    path(from: number | { label: string; type?: string }, to: number | { label: string; type?: string }, maxDepth?: number): GraphNode[];

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