Skip to main content
Glama

get_memory_graph

Read-onlyIdempotent

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 };
    }
Behavior4/5

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

Annotations already provide comprehensive behavioral hints (readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false). The description adds value by specifying the tool retrieves '메모리 지식 그래프' (memory knowledge graph) and provides usage examples that clarify it can retrieve either the entire graph or start from a specific key. This adds useful context beyond what annotations provide about the tool's scope and typical use cases.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with a clear purpose statement followed by keywords and usage examples. The structure is front-loaded with the core purpose first. The keywords section could be more concise, but overall the description avoids unnecessary verbosity while providing useful information.

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

Completeness4/5

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

Given the comprehensive annotations (which cover safety and behavioral aspects) and 100% schema description coverage, the description provides adequate context. The lack of an output schema means the description doesn't explain return values, but this is acceptable given the annotations indicate it's a read-only operation. The description could be more complete by explicitly differentiating from sibling tools, but it provides sufficient context for basic usage.

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

Parameters3/5

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

With 100% schema description coverage, the input schema already fully documents all 4 parameters. The description doesn't add any additional parameter semantics beyond what's in the schema descriptions. The usage examples imply parameter usage (e.g., 'project-architecture의 관계 그래프 보여줘' suggests using the 'key' parameter), but don't provide new information about parameter meaning or behavior.

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

Purpose4/5

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

The description clearly states the tool's purpose as '메모리 지식 그래프를 조회합니다' (retrieves memory knowledge graph), which is a specific verb+resource combination. However, it doesn't explicitly differentiate this from sibling tools like 'analyze_dependency_graph' or 'list_memories', which might have overlapping functionality. The keywords provide additional context but don't enhance the core purpose statement.

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

Usage Guidelines3/5

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

The description provides usage examples that imply when to use this tool (e.g., '전체 메모리 그래프 조회' for retrieving the entire graph), but doesn't explicitly state when to use it versus alternatives like 'analyze_dependency_graph' or 'list_memories'. The examples give contextual guidance but lack explicit when/when-not statements or named alternatives.

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

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