Skip to main content
Glama

get_memory_graph

Visualize memory relationships and connections within the Hi-AI system. Retrieve knowledge graphs to understand how information is linked, filter by relation types, and explore connections at specified depths.

Instructions

메모리 지식 그래프를 조회합니다.

키워드: 그래프, 관계도, 연결 보기, memory graph, relations, connections

사용 예시:

  • "project-architecture의 관계 그래프 보여줘"

  • "전체 메모리 그래프 조회"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyNo시작 메모리 키 (없으면 전체 그래프)
depthNo탐색 깊이 (기본값: 2)
relationTypeNo필터링할 관계 유형
formatNo출력 형식

Implementation Reference

  • Main tool handler: processes input arguments, retrieves memory graph from MemoryManager, applies filters and formatting (tree/list/mermaid), adds statistics, handles errors.
    export async function getMemoryGraph(args: GetMemoryGraphArgs): Promise<ToolResult> {
      try {
        const { key, depth = 2, relationType, format = 'tree' } = args;
        const memoryManager = MemoryManager.getInstance();
    
        const graph = memoryManager.getMemoryGraph(key, depth);
    
        if (graph.nodes.length === 0) {
          return {
            content: [{
              type: 'text',
              text: key
                ? `✗ 메모리를 찾을 수 없거나 관계가 없습니다: ${key}`
                : `✗ 저장된 메모리가 없습니다`
            }]
          };
        }
    
        // Filter by relation type if specified
        let filteredEdges = graph.edges;
        if (relationType) {
          filteredEdges = graph.edges.filter(e => e.relationType === relationType);
        }
    
        let output = '';
    
        switch (format) {
          case 'mermaid':
            output = generateMermaidDiagram(graph.nodes, filteredEdges);
            break;
          case 'list':
            output = generateListFormat(graph.nodes, filteredEdges);
            break;
          case 'tree':
          default:
            output = generateTreeFormat(key, graph.nodes, filteredEdges);
        }
    
        // Add statistics
        const stats = `
    ---
    **통계**
    - 노드 수: ${graph.nodes.length}
    - 관계 수: ${filteredEdges.length}
    - 클러스터 수: ${graph.clusters.length}
    ${graph.clusters.length > 0 ? `- 클러스터: ${graph.clusters.map(c => `[${c.join(', ')}]`).join(', ')}` : ''}`;
    
        return {
          content: [{
            type: 'text',
            text: output + stats
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `✗ 오류: ${error instanceof Error ? error.message : '알 수 없는 오류'}`
          }]
        };
      }
    }
  • ToolDefinition object defining the tool's name, description, inputSchema (key, depth, relationType, format), and annotations.
    export const getMemoryGraphDefinition: ToolDefinition = {
      name: 'get_memory_graph',
      description: `메모리 지식 그래프를 조회합니다.
    
    키워드: 그래프, 관계도, 연결 보기, memory graph, relations, connections
    
    사용 예시:
    - "project-architecture의 관계 그래프 보여줘"
    - "전체 메모리 그래프 조회"`,
      inputSchema: {
        type: 'object',
        properties: {
          key: {
            type: 'string',
            description: '시작 메모리 키 (없으면 전체 그래프)'
          },
          depth: {
            type: 'number',
            description: '탐색 깊이 (기본값: 2)',
            minimum: 1,
            maximum: 5
          },
          relationType: {
            type: 'string',
            description: '필터링할 관계 유형'
          },
          format: {
            type: 'string',
            description: '출력 형식',
            enum: ['tree', 'list', 'mermaid']
          }
        }
      },
      annotations: {
        title: 'Get Memory Graph',
        audience: ['user', 'assistant'],
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false
      }
    };
  • src/index.ts:170-170 (registration)
    Handler registration: maps 'get_memory_graph' tool name to the getMemoryGraph function in the toolHandlers registry used by MCP server.
    'get_memory_graph': getMemoryGraph,
  • src/index.ts:103-103 (registration)
    Definition registration: adds getMemoryGraphDefinition to the tools list returned by ListToolsRequest.
    getMemoryGraphDefinition,
  • Core helper in MemoryManager: constructs the memory graph (nodes, edges, clusters) via BFS traversal from optional start key or full graph, detects clusters.
    public getMemoryGraph(key?: string, depth: number = 2): MemoryGraph {
      const nodes: MemoryGraphNode[] = [];
      const edges: MemoryRelation[] = [];
      const visited = new Set<string>();
    
      if (key) {
        // BFS from starting key
        this.buildGraphFromKey(key, depth, visited, nodes, edges);
      } else {
        // Get all memories and relations
        const allMemories = this.list();
        for (const memory of allMemories) {
          const relations = this.getRelations(memory.key, 'outgoing');
          nodes.push({
            key: memory.key,
            value: memory.value,
            category: memory.category,
            relations
          });
          edges.push(...relations);
        }
      }
    
      // Detect clusters using simple connected components
      const clusters = this.detectClusters(nodes, edges);
    
      return { nodes, edges, clusters };
    }

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/su-record/hi-ai'

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