Skip to main content
Glama
vjsr007
by vjsr007

graph-import-from-notes

Extract nodes and edges from notes to build knowledge graphs. Import note-to-key and note-to-tag relationships, enabling structured visualization and analysis of semantic connections.

Instructions

Import nodes and edges from existing notes: note -> key and note -> tags.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyNo
sourceNo

Implementation Reference

  • src/mcp.ts:179-183 (registration)
    Tool registration in the MCP server tools array, defining name, description, and input schema.
    {
      name: 'graph-import-from-notes',
      description: 'Import nodes and edges from existing notes: note -> key and note -> tags.',
      inputSchema: { type: 'object', properties: { source: { type: 'string', enum: ['all', 'key'] }, key: { type: 'string' } } },
    },
  • Zod schema for validating input parameters: source ('all' or 'key') and optional key.
    export const GraphImportSchema = z.object({
      source: z.enum(['all', 'key']).optional().default('all'),
      key: z.string().optional(),
    });
  • MCP tool call handler: parses input, fetches notes, calls graph.importFromNotes, returns result.
    case 'graph-import-from-notes': {
      const parsed = GraphImportSchema.parse(args ?? {});
      const notes = parsed.source === 'key' && parsed.key ? db.getByKey(parsed.key, 1000) : db.exportAll();
      const res = graph.importFromNotes(notes);
      return { content: [{ type: 'text', text: JSON.stringify(res) }] };
  • SqliteGraphStore.importFromNotes: core implementation creating note/key/tag nodes and edges (note->key, note->tag). Primary impl used when SQLite available.
    importFromNotes(notes: Note[]): { nodes: number; edges: number } {
      let nodesCnt = 0;
      let edgesCnt = 0;
      const tx = this.db.transaction((items: Note[]) => {
        for (const n of items) {
          const noteNodeId = this.upsertNode({ label: `note:${n.id ?? n.key}:${(n.created_at || '').slice(0,10)}`, type: 'note', props: { key: n.key, tags: n.tags ?? [], metadata: n.metadata ?? {} } });
          const keyNodeId = this.upsertNode({ label: `key:${n.key}`, type: 'key' });
          edgesCnt += this.addEdge({ src: noteNodeId, dst: keyNodeId, type: 'has_key' }) ? 1 : 0;
          nodesCnt += 2; // approximate, since upsert may not create new
          for (const t of n.tags ?? []) {
            const tagId = this.upsertNode({ label: `tag:${t}`, type: 'tag' });
            edgesCnt += this.addEdge({ src: noteNodeId, dst: tagId, type: 'has_tag' }) ? 1 : 0;
            nodesCnt++;
          }
        }
      });
      tx(notes);
      // Adjust nodes count by querying totals
      const totals = this.stats();
      return { nodes: totals.nodes, edges: totals.edges };
  • LiteGraphStore.importFromNotes: fallback in-memory implementation with same node/edge creation logic.
    importFromNotes(notes: Note[]): { nodes: number; edges: number } {
      for (const n of notes) {
        const noteNodeId = this.upsertNode({ label: `note:${n.id ?? n.key}:${(n.created_at || '').slice(0,10)}`, type: 'note', props: { key: n.key, tags: n.tags ?? [], metadata: n.metadata ?? {} } });
        const keyNodeId = this.upsertNode({ label: `key:${n.key}`, type: 'key' });
        this.addEdge({ src: noteNodeId, dst: keyNodeId, type: 'has_key' });
        for (const t of n.tags ?? []) {
          const tagId = this.upsertNode({ label: `tag:${t}`, type: 'tag' });
          this.addEdge({ src: noteNodeId, dst: tagId, type: 'has_tag' });
        }
      }
      return this.stats();

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/vjsr007/mcp-index-notes'

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