Skip to main content
Glama

get_graph

Retrieve graph data showing connections between pages, including links, backlinks, and tags, to visualize relationships in your Logseq knowledge graph.

Instructions

페이지 간 연결 그래프 데이터 조회. 링크/백링크/태그 관계 포함

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
centerNo중심 페이지 이름 (선택)
depthNo탐색 깊이 (기본값: 1)

Implementation Reference

  • Core handler implementing getGraph tool logic: builds graph nodes (pages, journals, tags) and edges (links, backlinks, tags) from page metadata, with optional center node BFS traversal limited by depth.
    async getGraph(options?: { center?: string; depth?: number }): Promise<Graph> {
      const nodes: GraphNode[] = [];
      const edges: GraphEdge[] = [];
      const nodeSet = new Set<string>();
      const pages = await this.listPages();
    
      const addNode = (id: string, name: string, type: GraphNode['type']) => {
        if (!nodeSet.has(id)) {
          nodeSet.add(id);
          nodes.push({ id, name, type });
        }
      };
    
      if (options?.center) {
        // Build graph around center node
        const visited = new Set<string>();
        const queue: { name: string; depth: number }[] = [{ name: options.center, depth: 0 }];
        // 보안: depth는 0 이상, MAX_DEPTH 이하로 제한
        const requestedDepth = options.depth ?? 1;
        const maxDepth = Math.max(0, Math.min(requestedDepth, MAX_DEPTH));
    
        while (queue.length > 0) {
          const { name, depth } = queue.shift()!;
          if (visited.has(name) || depth > maxDepth) continue;
          visited.add(name);
    
          const page = pages.find(p => p.name === name);
          if (!page) continue;
    
          const nodeType = page.isJournal ? 'journal' : 'page';
          addNode(name, name, nodeType);
    
          // Add links
          for (const link of page.links) {
            addNode(link, link, 'page');
            edges.push({ source: name, target: link, type: 'link' });
            if (depth < maxDepth) {
              queue.push({ name: link, depth: depth + 1 });
            }
          }
    
          // Add backlinks
          for (const backlink of page.backlinks) {
            addNode(backlink, backlink, 'page');
            edges.push({ source: backlink, target: name, type: 'backlink' });
            if (depth < maxDepth) {
              queue.push({ name: backlink, depth: depth + 1 });
            }
          }
    
          // Add tags
          for (const tag of page.tags) {
            addNode(`tag:${tag}`, tag, 'tag');
            edges.push({ source: name, target: `tag:${tag}`, type: 'tag' });
          }
        }
      } else {
        // Full graph
        for (const page of pages) {
          const nodeType = page.isJournal ? 'journal' : 'page';
          addNode(page.name, page.name, nodeType);
    
          for (const link of page.links) {
            addNode(link, link, 'page');
            edges.push({ source: page.name, target: link, type: 'link' });
          }
    
          for (const tag of page.tags) {
            addNode(`tag:${tag}`, tag, 'tag');
            edges.push({ source: page.name, target: `tag:${tag}`, type: 'tag' });
          }
        }
      }
    
      return { nodes, edges };
    }
  • Input schema validation using Zod for get_graph tool parameters: center (optional page name), depth (optional integer 0-10).
    const GetGraphSchema = z.object({
      center: z.string().max(MAX_NAME_LENGTH).optional().describe('중심 페이지 이름 (선택)'),
      depth: z.number().int().min(0).max(10).optional().describe('탐색 깊이 (기본값: 1, 최대: 10)'),
    });
  • src/index.ts:205-215 (registration)
    MCP tool registration in server's TOOLS array defining get_graph with name, description, and inputSchema.
    {
      name: 'get_graph',
      description: '페이지 간 연결 그래프 데이터 조회. 링크/백링크/태그 관계 포함',
      inputSchema: {
        type: 'object' as const,
        properties: {
          center: { type: 'string', description: '중심 페이지 이름 (선택)' },
          depth: { type: 'number', description: '탐색 깊이 (기본값: 1)' },
        },
      },
    },
  • MCP CallToolRequestSchema handler case for get_graph: parses input, invokes GraphService.getGraph, returns JSON stringified response.
    case 'get_graph': {
      const { center, depth } = GetGraphSchema.parse(args);
      const graphData = await graph.getGraph({ center, depth });
      return {
        content: [{ type: 'text', text: JSON.stringify(graphData, null, 2) }],
      };
    }
  • TypeScript interfaces defining output schema for get_graph: GraphNode, GraphEdge, and Graph structures.
    export interface GraphNode {
      id: string;
      name: string;
      type: 'page' | 'tag' | 'journal';
    }
    
    export interface GraphEdge {
      source: string;
      target: string;
      type: 'link' | 'tag' | 'backlink';
    }
    
    export interface Graph {
      nodes: GraphNode[];
      edges: GraphEdge[];
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions what data is included (links/backlinks/tag relationships) but doesn't disclose critical behavioral traits like whether this is a read-only operation, performance characteristics, pagination, error conditions, or authentication requirements. For a data retrieval tool with zero annotation coverage, this leaves significant gaps.

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 extremely concise - a single sentence in Korean that efficiently communicates the core functionality. Every word earns its place with no wasted text, making it front-loaded and easy to parse despite the language difference.

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

Completeness2/5

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

Given the complexity of graph data retrieval and the absence of both annotations and output schema, the description is insufficient. It doesn't explain what format the graph data returns, how relationships are represented, what happens when parameters are omitted, or any limitations of the tool. For a graph query tool with no structured output documentation, this leaves too many unknowns.

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?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description doesn't add any meaningful parameter semantics beyond what the schema provides - it doesn't explain how 'center' and 'depth' interact or provide examples of valid values. Baseline 3 is appropriate when the schema does the heavy lifting.

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 'retrieving page connection graph data' with specific components mentioned (links/backlinks/tag relationships). It uses a specific verb ('retrieve') and resource ('page connection graph data'), though it doesn't explicitly differentiate from sibling tools like 'get_backlinks' which might overlap in functionality.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'get_backlinks' and 'list_pages' available, there's no indication of when this graph retrieval tool is preferable or what specific use cases it addresses compared to those 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/dearcloud09/logseq-mcp'

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