···5959});
60606161const nodeMetadataSchema = z.object({
6262- title: z.string().describe("Display name for the node"),
6363- description: z
6464- .string()
6565- .describe("Detailed markdown explanation of this component"),
6262+ title: z.string(),
6363+ description: z.string(),
6664 links: z
6767- .array(
6868- z.object({
6969- label: z.string().describe("Display text, e.g. src/auth.ts"),
7070- url: z.string().describe("File path or URL"),
7171- }),
7272- )
7373- .optional()
7474- .describe("Related files or documentation"),
7575- codeSnippet: z.string().optional().describe("Optional code example"),
7676- threadID: z
7777- .string()
7878- .optional()
7979- .describe("Optional link to deeper exploration thread"),
6565+ .array(z.object({ label: z.string(), url: z.string() }))
6666+ .optional(),
6767+ codeSnippet: z.string().optional(),
8068});
81698270server.registerTool("walkthrough_diagram", {
8371 title: "Walkthrough Diagram",
8484- description:
8585- "Render an interactive Mermaid diagram where users can click nodes to see detailed information about each component. Use plain text labels in Mermaid code, no HTML tags or custom styling.",
7272+ description: `Render an interactive Mermaid diagram where users can click nodes to see details.
7373+7474+BEFORE calling this tool, deeply explore the codebase:
7575+1. Use search/read tools to find key files, entry points, and architecture patterns
7676+2. Trace execution paths and data flow between components
7777+3. Read source files — don't guess from filenames
7878+7979+Then build the diagram:
8080+- Use \`flowchart TB\` with plain text labels, no HTML or custom styling
8181+- 5-12 nodes at the right abstraction level (not too granular, not too high-level)
8282+- Node keys must match Mermaid node IDs exactly
8383+- Descriptions: 2-3 paragraphs of markdown per node. Write for someone who has never seen this codebase — explain what the component does, how it works, and why it matters. Use \`code spans\` for identifiers and markdown headers to organize longer explanations
8484+- Links: include file:line references from your exploration
8585+- Code snippets: key excerpts (under 15 lines) showing the most important or representative code`,
8686 inputSchema: z.object({
8787- code: z
8888- .string()
8989- .describe(
9090- "Mermaid diagram code. Use plain text labels, no HTML tags. No custom styling/colors.",
9191- ),
9292- summary: z
9393- .string()
9494- .describe("One-sentence summary of what the diagram illustrates"),
9595- nodes: z
9696- .record(z.string(), nodeMetadataSchema)
9797- .describe(
9898- "Metadata for clickable nodes, keyed by node ID from mermaid code",
9999- ),
8787+ code: z.string(),
8888+ summary: z.string(),
8989+ nodes: z.record(z.string(), nodeMetadataSchema),
10090 }),
10191}, async ({ code, summary, nodes }) => {
10292 const id = String(++diagramCounter);