toon-memory 3.2.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toon-memory",
3
- "version": "3.2.0",
3
+ "version": "3.3.1",
4
4
  "description": "MCP server giving AI coding agents offline, token-efficient persistent memory — 29 tools, 80% fewer tool calls, recall decisions, patterns, and bugs across sessions. No LLM, no server; works with 15+ agents.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -35,11 +35,14 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@inquirer/prompts": "^8.5.2",
38
- "@modelcontextprotocol/server": "^2.0.0-beta.5",
38
+ "@modelcontextprotocol/ext-apps": "^1.7.5",
39
+ "@modelcontextprotocol/sdk": "^1.30.0",
39
40
  "@toon-format/toon": "^2.3.0",
40
41
  "zod": "^4.4.3"
41
42
  },
42
43
  "devDependencies": {
44
+ "@mcp-ui/server": "^6.1.0",
45
+ "@modelcontextprotocol/inspector": "^2.0.0",
43
46
  "@types/node": "^26.1.1",
44
47
  "esbuild": "^0.25.0",
45
48
  "gpt-tokenizer": "^3.4.0",
@@ -34,6 +34,9 @@ Persistent memory for this project. Use it to avoid re-investigating things.
34
34
  1. Run memory_stats to see what's in memory.
35
35
  2. If the user asks something that might be in memory, run memory_recall BEFORE reading files.
36
36
 
37
+ ## When asked to see the memory graph
38
+ - Call memory_visualize() to open the interactive graph viewer inline.
39
+
37
40
  ## When making decisions
38
41
  - Before implementing a non-trivial change: memory_remember(category='decision')
39
42
  - When you resolve a complex bug: memory_remember(category='bug')
@@ -53,4 +56,5 @@ Persistent memory for this project. Use it to avoid re-investigating things.
53
56
  export const OPENCODE_PASSIVE_INSTRUCTION = `# toon-memory
54
57
 
55
58
  Memory auto-injects via .opencode/instructions/memory-autoload.md; use memory_recall only as fallback.
59
+ When the user asks to see the memory graph, call memory_visualize().
56
60
  `
@@ -1,4 +1,4 @@
1
- import type { McpServer } from "@modelcontextprotocol/server"
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
2
2
  import { z } from "zod"
3
3
  import { readMemory } from "./memory-io"
4
4
  import { parseEntries } from "../lib/graph"
@@ -1,10 +1,14 @@
1
- import type { McpServer } from "@modelcontextprotocol/server"
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
2
+ import { registerAppResource } from "@modelcontextprotocol/ext-apps/server"
3
+ import { createUIResource } from "@mcp-ui/server"
2
4
  import { readMemory } from "./memory-io"
3
5
  import { isExpired } from "./entries"
4
6
  import { generateSystemPrimer } from "../lib/quality"
7
+ import { buildViewerData } from "../viewer/data"
8
+ import { generateHtml } from "../viewer/html"
5
9
 
6
10
  /**
7
- * Register memory MCP resources (entries, stats, summaries).
11
+ * Register memory MCP resources (entries, stats, summaries, viewer).
8
12
  */
9
13
  export function registerResources(server: McpServer): void {
10
14
  server.registerResource(
@@ -54,4 +58,19 @@ export function registerResources(server: McpServer): void {
54
58
  return { contents: [{ uri: uri.href, text: primer }] }
55
59
  }
56
60
  )
61
+
62
+ // MCP Apps: interactive graph viewer rendered inline in MCP hosts
63
+ const viewerResource = createUIResource({
64
+ uri: "ui://viewer",
65
+ content: { type: "rawHtml", htmlString: generateHtml(buildViewerData()) },
66
+ encoding: "text",
67
+ adapters: { mcpApps: { enabled: true } },
68
+ })
69
+ registerAppResource(
70
+ server as unknown as Parameters<typeof registerAppResource>[0],
71
+ "Memory Graph Viewer",
72
+ viewerResource.resource.uri,
73
+ { description: "Interactive memory graph viewer (D3.js force-directed graph with stats, timeline, detail panel)" },
74
+ async () => ({ contents: [viewerResource.resource] }),
75
+ )
57
76
  }
package/src/mcp/server.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { McpServer } from "@modelcontextprotocol/server"
2
- import { StdioServerTransport } from "@modelcontextprotocol/server/stdio"
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
3
+ import { InitializeRequestSchema, SUPPORTED_PROTOCOL_VERSIONS, LATEST_PROTOCOL_VERSION } from "@modelcontextprotocol/sdk/types.js"
3
4
  import { registerTools } from "./tools"
4
5
  import { registerResources } from "./resources"
5
6
  import { pruneExpiredEntries } from "./archive"
@@ -8,9 +9,27 @@ declare const TOON_VERSION: string
8
9
 
9
10
  const server = new McpServer(
10
11
  { name: "toon-memory", version: TOON_VERSION },
11
- { capabilities: { tools: { listChanged: true }, resources: { listChanged: true } } }
12
+ { capabilities: { tools: { listChanged: true }, resources: { listChanged: true }, experimental: { "io.modelcontextprotocol/ui": {} } } }
12
13
  )
13
14
 
15
+ // MCP Apps support is advertised via capabilities.experimental.
16
+ // We DO NOT set top-level extensions here — for STDIO transport that
17
+ // triggers OAuth in some hosts (e.g. Inspector v2). The experimental
18
+ // field is sufficient for MCP Apps–compatible clients.
19
+ const s = server.server as any
20
+ s.setRequestHandler(InitializeRequestSchema, async (request: any) => {
21
+ const requestedVersion = request.params.protocolVersion
22
+ s._clientCapabilities = request.params.capabilities
23
+ s._clientVersion = request.params.clientInfo
24
+ const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : LATEST_PROTOCOL_VERSION
25
+ return {
26
+ protocolVersion,
27
+ capabilities: s.getCapabilities(),
28
+ serverInfo: { name: "toon-memory", version: TOON_VERSION },
29
+ ...(s._instructions && { instructions: s._instructions }),
30
+ }
31
+ })
32
+
14
33
  registerResources(server)
15
34
  registerTools(server)
16
35
 
package/src/mcp/tools.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { McpServer } from "@modelcontextprotocol/server"
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
2
+ import { registerAppTool } from "@modelcontextprotocol/ext-apps/server"
2
3
  import { z } from "zod"
3
4
  import { readFileSync, writeFileSync, existsSync, copyFileSync, mkdirSync, readdirSync } from "fs"
4
5
  import { join, basename } from "path"
@@ -1550,6 +1551,35 @@ server.registerTool(
1550
1551
  }
1551
1552
  )
1552
1553
 
1554
+ // ── memory_visualize (MCP Apps) ──────────────────────────────────────────────
1555
+
1556
+ registerAppTool(
1557
+ server as unknown as Parameters<typeof registerAppTool>[0],
1558
+ "memory_visualize",
1559
+ {
1560
+ title: "Open Memory Graph Viewer",
1561
+ description: "Open the interactive memory graph viewer (force-directed graph, stats, timeline, detail panel). Renders inline in MCP Apps-compatible hosts.",
1562
+ inputSchema: {
1563
+ query: z.string().optional().default("").describe("Optional search query to highlight entries in the viewer"),
1564
+ },
1565
+ _meta: { ui: { resourceUri: "ui://viewer" } },
1566
+ },
1567
+ async ({ query }) => {
1568
+ const data = readMemory()
1569
+ const entries = parseEntries(data)
1570
+ const total = entries.length
1571
+ const graph = buildGraph(entries)
1572
+ const edgeCount = [...graph.adjacency.values()].reduce((sum, n) => sum + n.length, 0) / 2
1573
+
1574
+ let msg = `🧠 Memory Graph Viewer — ${total} entries, ${edgeCount} edges`
1575
+ if (query) msg += `\n🔍 Focus: "${query}"`
1576
+
1577
+ return {
1578
+ content: [{ type: "text" as const, text: msg }],
1579
+ }
1580
+ }
1581
+ )
1582
+
1553
1583
  } // end registerTools
1554
1584
 
1555
1585
  /** Parse relative time string to milliseconds. */