Skip to main content
Glama

export_behavioral_graph

Export the current repository's behavioral graph as JSON for downstream analysis or visualization. Includes all code nodes, dependency and invocation edges, with each node colored by semantic workflow domain.

Instructions

Exports the full behavioral graph of the current repository as JSON: nodes (every class, method, top-level function detected by ts-morph) and edges (DependsOn from imports plus real Invokes from call-expression resolution). Each node is colored by its semantic workflow domain (Authentication, Payments, Webhooks, Caching, Queue, and 20 more). Use this when you need machine-readable graph data for downstream analysis or visualization. Returns nodeCount, edgeCount, and the full nodes/edges arrays.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • BehavioralGraphEngine.buildGraphFromReport() – builds nodes (classes, methods, functions) and edges (DependsOn from imports, Invokes from CallExpression resolution). The core graph construction logic.
        public buildGraphFromReport(report: RepositoryIntelligenceReport): BehavioralGraph {
            const graph = new BehavioralGraph();
    
            // Index callable nodes by short name for cross-file invoke resolution
            const calleeIndex: Map<string, string[]> = new Map();
            const indexCallable = (name: string, nodeId: string) => {
                const list = calleeIndex.get(name) || [];
                list.push(nodeId);
                calleeIndex.set(name, list);
            };
    
            // Index files by basename (without extension) and by lowercased basename
            // for fast cross-file resolution of imports.
            const fileByBaseName: Map<string, VerisFile[]> = new Map();
            for (const f of report.files) {
                const segs = f.filePath.split(/[\\\/]/);
                const last = segs[segs.length - 1] || '';
                const base = last.replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/i, '').toLowerCase();
                if (!base) continue;
                const list = fileByBaseName.get(base) || [];
                list.push(f);
                fileByBaseName.set(base, list);
            }
    
            // 1. Nodes
            report.files.forEach(file => {
                file.classes.forEach(cls => {
                    const classNodeId = `${file.filePath}::${cls.name}`;
                    graph.addNode({ id: classNodeId, type: NodeType.Service, label: cls.name });
    
                    cls.methods.forEach(method => {
                        const methodNodeId = `${classNodeId}::${method.name}`;
                        graph.addNode({ id: methodNodeId, type: NodeType.Method, label: method.name });
                        graph.addEdge({ sourceId: classNodeId, targetId: methodNodeId, type: EdgeType.DependsOn });
                        indexCallable(method.name, methodNodeId);
                    });
                });
    
                file.functions.forEach(fn => {
                    const funcNodeId = `${file.filePath}::${fn.name}`;
                    graph.addNode({ id: funcNodeId, type: NodeType.Function, label: fn.name });
                    indexCallable(fn.name, funcNodeId);
                });
            });
    
            // 2. DependsOn edges via imports (file-level coupling, basename-indexed).
            // Heuristic: only count edges for imports that look like relative paths
            // (starts with '.', '..', '/', or '~/') OR a TS path-alias-shaped specifier.
            // Bare package imports like 'fs', 'express', 'lodash' don't create graph edges.
            const isLocalImportSpec = (imp: string): boolean => {
                if (!imp) return false;
                if (imp.startsWith('.') || imp.startsWith('/') || imp.startsWith('~/')) return true;
                // TS path aliases (Next.js, NestJS): @/foo, ~/foo, $foo/bar etc. — let basename win.
                if (imp.startsWith('@/') || imp.startsWith('$/')) return true;
                return false;
            };
    
            report.files.forEach(file => {
                const imports = report.dependencyMap[file.filePath];
                if (!imports) return;
    
                file.classes.forEach(sourceCls => {
                    const sourceId = `${file.filePath}::${sourceCls.name}`;
                    imports.forEach(imp => {
                        if (!isLocalImportSpec(imp)) return;
                        const baseImpName = (imp.split('/').pop() || imp).toLowerCase();
                        if (!baseImpName) return;
                        const targetFiles = fileByBaseName.get(baseImpName);
                        if (!targetFiles) return;
                        // Cap basename collisions: if more than 5 files share a basename,
                        // skip — almost certainly a generic name (e.g. 'index', 'utils')
                        // that would just create noise edges.
                        if (targetFiles.length > 5) return;
                        for (const targetFile of targetFiles) {
                            if (targetFile.filePath === file.filePath) continue;
                            for (const targetCls of targetFile.classes) {
                                const targetId = `${targetFile.filePath}::${targetCls.name}`;
                                graph.addEdge({ sourceId, targetId, type: EdgeType.DependsOn });
                            }
                        }
                    });
                });
            });
    
            // 3. Invokes edges from CallExpression analysis
            report.files.forEach(file => {
                file.classes.forEach(cls => {
                    const classNodeId = `${file.filePath}::${cls.name}`;
                    cls.methods.forEach(method => {
                        const methodNodeId = `${classNodeId}::${method.name}`;
                        (method.calls || []).forEach(callee => {
                            const targets = calleeIndex.get(callee);
                            if (!targets) return;
                            targets.forEach(targetId => {
                                if (targetId === methodNodeId) return;
                                graph.addEdge({ sourceId: methodNodeId, targetId, type: EdgeType.Invokes });
                            });
                        });
                    });
                });
    
                file.functions.forEach(fn => {
                    const funcNodeId = `${file.filePath}::${fn.name}`;
                    (fn.calls || []).forEach(callee => {
                        const targets = calleeIndex.get(callee);
                        if (!targets) return;
                        targets.forEach(targetId => {
                            if (targetId === funcNodeId) return;
                            graph.addEdge({ sourceId: funcNodeId, targetId, type: EdgeType.Invokes });
                        });
                    });
                });
            });
    
            return graph;
        }
    }
Behavior4/5

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

Without annotations, the description details output structure (nodes, edges, colors, counts) and detection method (ts-morph). It does not mention performance considerations or side effects, but being a read-only export, the behavioral traits are adequately covered.

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 a single paragraph with no redundant sentences. It front-loads the core purpose, then provides details and usage guidance efficiently.

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

Completeness5/5

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

Given no output schema and no annotations, the description thoroughly covers return values (nodeCount, edgeCount, nodes/edges arrays), including node coloring by domain. It is complete for the tool's zero-param, export-oriented nature.

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

Parameters4/5

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

Input schema has zero parameters with 100% coverage, so the description adds no param semantics. Baseline 4 is appropriate since no additional meaning is needed.

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

Purpose5/5

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

The description clearly states the tool exports a 'full behavioral graph' as JSON, specifying nodes (classes, methods, functions) and edges (DependsOn, Invokes). It distinguishes from siblings like 'analyze_repository' or 'export_onboarding' by focusing on raw graph export.

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

Usage Guidelines4/5

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

The description explicitly says 'Use this when you need machine-readable graph data for downstream analysis or visualization.' It lacks explicit exclusions or alternatives but provides clear usage context.

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/vighriday/Veris'

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