Skip to main content
Glama
graph.ts1.18 kB
/** * Graph data structure and utilities */ import type { NodeDefinition } from "../types/config.js"; export class Graph { private nodes: Map<string, NodeDefinition>; private edges: Map<string, string[]>; // nodeId -> array of next node IDs constructor(nodes: NodeDefinition[]) { this.nodes = new Map(); this.edges = new Map(); for (const node of nodes) { this.nodes.set(node.id, node); // Build edges if ("next" in node && node.next) { const current = this.edges.get(node.id) || []; current.push(node.next); this.edges.set(node.id, current); } // Handle switch nodes with multiple targets if (node.type === "switch") { const targets = node.conditions.map((c) => c.target); this.edges.set(node.id, targets); } } } getNode(nodeId: string): NodeDefinition | undefined { return this.nodes.get(nodeId); } getNextNodes(nodeId: string): string[] { return this.edges.get(nodeId) || []; } getAllNodes(): NodeDefinition[] { return Array.from(this.nodes.values()); } hasNode(nodeId: string): boolean { return this.nodes.has(nodeId); } }

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/TeamSparkAI/mcpGraph'

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