@adia-ai/a2ui-mcp 0.6.4 → 0.6.6
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/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/server.js +110 -547
- package/tools/corpus.js +103 -0
- package/tools/corpus.ts +112 -0
- package/tools/feedback.js +63 -0
- package/tools/feedback.ts +73 -0
- package/tools/synthesis.js +143 -174
- package/tools/validation.js +131 -0
- package/tools/validation.ts +153 -0
- package/tools/zettel.js +87 -0
- package/tools/zettel.ts +98 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { validateSchema } from "../../validator/validator.js";
|
|
3
|
+
import { validateMessages as validateCatalogMessages } from "../../validator/catalog-validator.js";
|
|
4
|
+
import {
|
|
5
|
+
getCatalog,
|
|
6
|
+
getComponent,
|
|
7
|
+
getTraits,
|
|
8
|
+
getTraitsByCategory
|
|
9
|
+
} from "../../retrieval/catalog.js";
|
|
10
|
+
import { serializeEntry } from "../../retrieval/component-entry.js";
|
|
11
|
+
import { getAntiPatterns, checkAllAntiPatterns } from "../../retrieval/anti-patterns.js";
|
|
12
|
+
import { assembleContext } from "../../retrieval/context-assembler.js";
|
|
13
|
+
import { transpileHTML } from "../../compose/transpiler/transpiler.js";
|
|
14
|
+
import { getWiringCatalog } from "../../retrieval/wiring-catalog.js";
|
|
15
|
+
function registerValidationTools(server) {
|
|
16
|
+
server.tool(
|
|
17
|
+
"validate_schema",
|
|
18
|
+
"Validate A2UI messages against schema rules.",
|
|
19
|
+
{
|
|
20
|
+
messages: z.string().describe("JSON array of A2UI messages")
|
|
21
|
+
},
|
|
22
|
+
async ({ messages }) => {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(messages);
|
|
25
|
+
const msgs = Array.isArray(parsed) ? parsed : [parsed];
|
|
26
|
+
const scored = validateSchema(msgs);
|
|
27
|
+
const catalog = await validateCatalogMessages(msgs);
|
|
28
|
+
const result = { ...scored, catalog };
|
|
29
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
30
|
+
} catch (err) {
|
|
31
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
32
|
+
return { content: [{ type: "text", text: `Parse error: ${e.message}` }], isError: true };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
server.tool(
|
|
37
|
+
"lookup_component",
|
|
38
|
+
"Look up a AdiaUI component by type name.",
|
|
39
|
+
{
|
|
40
|
+
type: z.string().describe('Component type (e.g., "Card", "Button")'),
|
|
41
|
+
level: z.enum(["index", "summary", "reference"]).optional().describe("Detail level (default: reference)")
|
|
42
|
+
},
|
|
43
|
+
async ({ type, level }) => {
|
|
44
|
+
const entry = await getComponent(type);
|
|
45
|
+
if (!entry) return { content: [{ type: "text", text: `Not found: ${type}` }], isError: true };
|
|
46
|
+
const serialized = serializeEntry(entry, level ?? "reference");
|
|
47
|
+
return { content: [{ type: "text", text: JSON.stringify(serialized, null, 2) }] };
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
server.tool(
|
|
51
|
+
"get_component_map",
|
|
52
|
+
"Get the full AdiaUI component catalog.",
|
|
53
|
+
{},
|
|
54
|
+
async () => {
|
|
55
|
+
const catalog = await getCatalog();
|
|
56
|
+
const summary = [...catalog.entries.values()].map((e) => {
|
|
57
|
+
const entry = e;
|
|
58
|
+
const desc = typeof entry["description"] === "string" ? entry["description"].slice(0, 80) : "";
|
|
59
|
+
return `${entry["type"]} -> <${entry["tag"]}>: ${desc}`;
|
|
60
|
+
}).join("\n");
|
|
61
|
+
return { content: [{ type: "text", text: summary }] };
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
server.tool(
|
|
65
|
+
"check_anti_patterns",
|
|
66
|
+
"Check HTML against all anti-patterns. Returns only violations.",
|
|
67
|
+
{
|
|
68
|
+
html: z.string().describe("HTML string to check")
|
|
69
|
+
},
|
|
70
|
+
async ({ html }) => {
|
|
71
|
+
const violations = checkAllAntiPatterns(html);
|
|
72
|
+
return { content: [{ type: "text", text: JSON.stringify(violations, null, 2) }] };
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
server.tool(
|
|
76
|
+
"get_traits",
|
|
77
|
+
"Get the trait catalog, optionally filtered by category.",
|
|
78
|
+
{
|
|
79
|
+
category: z.string().optional().describe('Trait category filter (e.g., "input-interaction", "motion-positioning")')
|
|
80
|
+
},
|
|
81
|
+
async ({ category }) => {
|
|
82
|
+
const traits = category ? getTraitsByCategory(category) : getTraits();
|
|
83
|
+
return { content: [{ type: "text", text: JSON.stringify(traits, null, 2) }] };
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
server.tool(
|
|
87
|
+
"assemble_context",
|
|
88
|
+
`Assemble progressive-disclosure context for a given intent and budget tier. Returns domain-relevant components, matching patterns, and anti-patterns.
|
|
89
|
+
|
|
90
|
+
Tier 0: domain only. Tier 1: components. Tier 2: +patterns. Tier 3: +anti-patterns. Tier 4: full catalog.
|
|
91
|
+
|
|
92
|
+
Use this when you want to manually compose A2UI output rather than using generate_ui. The returned context gives you the building blocks.`,
|
|
93
|
+
{
|
|
94
|
+
intent: z.string().describe("Natural language intent"),
|
|
95
|
+
tier: z.number().min(0).max(4).optional().describe("Budget tier 0-4 (default: 1)")
|
|
96
|
+
},
|
|
97
|
+
async ({ intent, tier }) => {
|
|
98
|
+
const result = assembleContext({ intent, tier: tier ?? 1 });
|
|
99
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
server.tool(
|
|
103
|
+
"convert_html",
|
|
104
|
+
"Convert HTML markup to A2UI flat adjacency component messages. Maps HTML tags to AdiaUI components, infers layout from styles, enforces Card content model.",
|
|
105
|
+
{
|
|
106
|
+
html: z.string().describe("HTML markup to convert"),
|
|
107
|
+
mode: z.enum(["instant", "reasoning"]).optional().describe("instant = rules only, reasoning = LLM for complex layouts")
|
|
108
|
+
},
|
|
109
|
+
async ({ html, mode }) => {
|
|
110
|
+
try {
|
|
111
|
+
const result = await transpileHTML(html, { mode: mode ?? "instant" });
|
|
112
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
113
|
+
} catch (err) {
|
|
114
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
115
|
+
return { content: [{ type: "text", text: `Transpile error: ${e.message}` }], isError: true };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
server.tool(
|
|
120
|
+
"get_wiring_catalog",
|
|
121
|
+
"Get the AdiaUI wiring catalog: available controllers, action handlers, refresh strategies, value sources, and association types.",
|
|
122
|
+
{},
|
|
123
|
+
async () => {
|
|
124
|
+
const catalog = getWiringCatalog();
|
|
125
|
+
return { content: [{ type: "text", text: JSON.stringify(catalog, null, 2) }] };
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
registerValidationTools
|
|
131
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation tools — schema validation, component lookup, catalog, anti-patterns,
|
|
3
|
+
* traits, context assembly, HTML transpilation, and wiring catalog.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from server.ts. Registers:
|
|
6
|
+
* validate_schema, lookup_component, get_component_map, check_anti_patterns,
|
|
7
|
+
* get_traits, assemble_context, convert_html, get_wiring_catalog
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
12
|
+
|
|
13
|
+
import { validateSchema } from '../../validator/validator.js';
|
|
14
|
+
import { validateMessages as validateCatalogMessages } from '../../validator/catalog-validator.js';
|
|
15
|
+
import {
|
|
16
|
+
getCatalog,
|
|
17
|
+
getComponent,
|
|
18
|
+
getTraits,
|
|
19
|
+
getTraitsByCategory,
|
|
20
|
+
} from '../../retrieval/catalog.js';
|
|
21
|
+
import { serializeEntry } from '../../retrieval/component-entry.js';
|
|
22
|
+
import { getAntiPatterns, checkAllAntiPatterns } from '../../retrieval/anti-patterns.js';
|
|
23
|
+
import { assembleContext } from '../../retrieval/context-assembler.js';
|
|
24
|
+
import { transpileHTML } from '../../compose/transpiler/transpiler.js';
|
|
25
|
+
import { getWiringCatalog } from '../../retrieval/wiring-catalog.js';
|
|
26
|
+
|
|
27
|
+
export function registerValidationTools(server: McpServer): void {
|
|
28
|
+
server.tool(
|
|
29
|
+
'validate_schema',
|
|
30
|
+
'Validate A2UI messages against schema rules.',
|
|
31
|
+
{
|
|
32
|
+
messages: z.string().describe('JSON array of A2UI messages'),
|
|
33
|
+
},
|
|
34
|
+
async ({ messages }) => {
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(messages) as unknown;
|
|
37
|
+
const msgs = Array.isArray(parsed) ? parsed : [parsed];
|
|
38
|
+
// Two orthogonal checks:
|
|
39
|
+
// 1. scored — weighted heuristic validator (intent alignment, card model, etc.)
|
|
40
|
+
// 2. catalog — AJV against v0.9 catalog schema (type-level structural correctness)
|
|
41
|
+
// Both run; results returned together so callers see structural + quality signal.
|
|
42
|
+
const scored = validateSchema(msgs);
|
|
43
|
+
const catalog = await validateCatalogMessages(msgs);
|
|
44
|
+
const result = { ...scored, catalog };
|
|
45
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
46
|
+
} catch (err) {
|
|
47
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
48
|
+
return { content: [{ type: 'text', text: `Parse error: ${e.message}` }], isError: true };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
server.tool(
|
|
54
|
+
'lookup_component',
|
|
55
|
+
'Look up a AdiaUI component by type name.',
|
|
56
|
+
{
|
|
57
|
+
type: z.string().describe('Component type (e.g., "Card", "Button")'),
|
|
58
|
+
level: z.enum(['index', 'summary', 'reference']).optional().describe('Detail level (default: reference)'),
|
|
59
|
+
},
|
|
60
|
+
async ({ type, level }) => {
|
|
61
|
+
const entry = await getComponent(type);
|
|
62
|
+
if (!entry) return { content: [{ type: 'text', text: `Not found: ${type}` }], isError: true };
|
|
63
|
+
const serialized = serializeEntry(entry, level ?? 'reference');
|
|
64
|
+
return { content: [{ type: 'text', text: JSON.stringify(serialized, null, 2) }] };
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
server.tool(
|
|
69
|
+
'get_component_map',
|
|
70
|
+
'Get the full AdiaUI component catalog.',
|
|
71
|
+
{},
|
|
72
|
+
async () => {
|
|
73
|
+
const catalog = await getCatalog();
|
|
74
|
+
const summary = [...catalog.entries.values()]
|
|
75
|
+
.map(e => {
|
|
76
|
+
const entry = e as Record<string, unknown>;
|
|
77
|
+
const desc = typeof entry['description'] === 'string' ? entry['description'].slice(0, 80) : '';
|
|
78
|
+
return `${entry['type']} -> <${entry['tag']}>: ${desc}`;
|
|
79
|
+
})
|
|
80
|
+
.join('\n');
|
|
81
|
+
return { content: [{ type: 'text', text: summary }] };
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
server.tool(
|
|
86
|
+
'check_anti_patterns',
|
|
87
|
+
'Check HTML against all anti-patterns. Returns only violations.',
|
|
88
|
+
{
|
|
89
|
+
html: z.string().describe('HTML string to check'),
|
|
90
|
+
},
|
|
91
|
+
async ({ html }) => {
|
|
92
|
+
const violations = checkAllAntiPatterns(html);
|
|
93
|
+
return { content: [{ type: 'text', text: JSON.stringify(violations, null, 2) }] };
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
server.tool(
|
|
98
|
+
'get_traits',
|
|
99
|
+
'Get the trait catalog, optionally filtered by category.',
|
|
100
|
+
{
|
|
101
|
+
category: z.string().optional().describe('Trait category filter (e.g., "input-interaction", "motion-positioning")'),
|
|
102
|
+
},
|
|
103
|
+
async ({ category }) => {
|
|
104
|
+
const traits = category ? getTraitsByCategory(category) : getTraits();
|
|
105
|
+
return { content: [{ type: 'text', text: JSON.stringify(traits, null, 2) }] };
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
server.tool(
|
|
110
|
+
'assemble_context',
|
|
111
|
+
`Assemble progressive-disclosure context for a given intent and budget tier. Returns domain-relevant components, matching patterns, and anti-patterns.
|
|
112
|
+
|
|
113
|
+
Tier 0: domain only. Tier 1: components. Tier 2: +patterns. Tier 3: +anti-patterns. Tier 4: full catalog.
|
|
114
|
+
|
|
115
|
+
Use this when you want to manually compose A2UI output rather than using generate_ui. The returned context gives you the building blocks.`,
|
|
116
|
+
{
|
|
117
|
+
intent: z.string().describe('Natural language intent'),
|
|
118
|
+
tier: z.number().min(0).max(4).optional().describe('Budget tier 0-4 (default: 1)'),
|
|
119
|
+
},
|
|
120
|
+
async ({ intent, tier }) => {
|
|
121
|
+
const result = assembleContext({ intent, tier: tier ?? 1 });
|
|
122
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
server.tool(
|
|
127
|
+
'convert_html',
|
|
128
|
+
'Convert HTML markup to A2UI flat adjacency component messages. Maps HTML tags to AdiaUI components, infers layout from styles, enforces Card content model.',
|
|
129
|
+
{
|
|
130
|
+
html: z.string().describe('HTML markup to convert'),
|
|
131
|
+
mode: z.enum(['instant', 'reasoning']).optional().describe('instant = rules only, reasoning = LLM for complex layouts'),
|
|
132
|
+
},
|
|
133
|
+
async ({ html, mode }) => {
|
|
134
|
+
try {
|
|
135
|
+
const result = await transpileHTML(html, { mode: mode ?? 'instant' });
|
|
136
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
137
|
+
} catch (err) {
|
|
138
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
139
|
+
return { content: [{ type: 'text', text: `Transpile error: ${e.message}` }], isError: true };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
server.tool(
|
|
145
|
+
'get_wiring_catalog',
|
|
146
|
+
'Get the AdiaUI wiring catalog: available controllers, action handlers, refresh strategies, value sources, and association types.',
|
|
147
|
+
{},
|
|
148
|
+
async () => {
|
|
149
|
+
const catalog = getWiringCatalog();
|
|
150
|
+
return { content: [{ type: 'text', text: JSON.stringify(catalog, null, 2) }] };
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
package/tools/zettel.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
getComposition as getZettelComposition,
|
|
4
|
+
getAllCompositions as getAllZettelCompositions,
|
|
5
|
+
getGraph as getZettelGraph,
|
|
6
|
+
searchAll as searchCompositions
|
|
7
|
+
} from "../../compose/strategies/zettel/composition-library.js";
|
|
8
|
+
import {
|
|
9
|
+
resolveComposition as resolveZettelComposition,
|
|
10
|
+
templateToMessages as zettelTemplateToMessages
|
|
11
|
+
} from "../../compose/strategies/zettel/composer.js";
|
|
12
|
+
function registerZettelTools(server) {
|
|
13
|
+
server.tool(
|
|
14
|
+
"search_patterns",
|
|
15
|
+
`Search the composition library for reusable UI templates. Returns matching compositions with full A2UI component trees that can be used directly or adapted.
|
|
16
|
+
|
|
17
|
+
Use this to find a starting point before generating from scratch. If a good composition exists, pass it to generate_ui with instant mode. If no composition matches, use generate_ui with thinking mode.
|
|
18
|
+
|
|
19
|
+
Keyword search (\xA764 v0.4.6 migration: now backed by composition-library; the historical "pattern" library is retired).`,
|
|
20
|
+
{
|
|
21
|
+
query: z.string().describe("Search query (natural language)")
|
|
22
|
+
},
|
|
23
|
+
async ({ query }) => {
|
|
24
|
+
const results = searchCompositions(query);
|
|
25
|
+
return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] };
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
server.tool(
|
|
29
|
+
"get_composition",
|
|
30
|
+
"Fetch a composition by name. Returns the flat A2UI template (compositions are pre-inlined; no $fragment refs). Zettel-only.",
|
|
31
|
+
{ name: z.string() },
|
|
32
|
+
async ({ name }) => {
|
|
33
|
+
const c = getZettelComposition(name);
|
|
34
|
+
if (!c) return { content: [{ type: "text", text: `Composition not found: ${name}` }], isError: true };
|
|
35
|
+
return { content: [{ type: "text", text: JSON.stringify(c, null, 2) }] };
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
server.tool(
|
|
39
|
+
"resolve_composition",
|
|
40
|
+
"Return the flat A2UI template + updateComponents messages for a composition. Zettel-only. (Pre-inlined since \xA737 \u2014 `resolve` is now a defensive copy + strip pass.)",
|
|
41
|
+
{ name: z.string() },
|
|
42
|
+
async ({ name }) => {
|
|
43
|
+
const c = getZettelComposition(name);
|
|
44
|
+
if (!c) return { content: [{ type: "text", text: `Composition not found: ${name}` }], isError: true };
|
|
45
|
+
const template = resolveZettelComposition(c);
|
|
46
|
+
const messages = zettelTemplateToMessages(template);
|
|
47
|
+
return {
|
|
48
|
+
content: [{
|
|
49
|
+
type: "text",
|
|
50
|
+
text: JSON.stringify({ template, messages }, null, 2)
|
|
51
|
+
}]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
server.tool(
|
|
56
|
+
"get_graph",
|
|
57
|
+
"Return the composition catalog. Zettel-only. (Backlinks to fragments retired in \xA737; only composition nodes remain.)",
|
|
58
|
+
{},
|
|
59
|
+
async () => ({ content: [{ type: "text", text: JSON.stringify(getZettelGraph(), null, 2) }] })
|
|
60
|
+
);
|
|
61
|
+
server.tool(
|
|
62
|
+
"zettel_stats",
|
|
63
|
+
"Zettel corpus stats \u2014 composition count + average node count. (Fragment stats retired in \xA737.)",
|
|
64
|
+
{},
|
|
65
|
+
async () => {
|
|
66
|
+
const comps = getAllZettelCompositions();
|
|
67
|
+
const totalNodes = comps.reduce((s, c) => {
|
|
68
|
+
const comp = c;
|
|
69
|
+
const tpl = comp["template"];
|
|
70
|
+
return s + (Array.isArray(tpl) ? tpl.length : 0);
|
|
71
|
+
}, 0);
|
|
72
|
+
return {
|
|
73
|
+
content: [{
|
|
74
|
+
type: "text",
|
|
75
|
+
text: JSON.stringify({
|
|
76
|
+
compositions: comps.length,
|
|
77
|
+
avg_nodes_per_composition: comps.length ? Math.round(totalNodes / comps.length) : 0,
|
|
78
|
+
total_nodes: totalNodes
|
|
79
|
+
}, null, 2)
|
|
80
|
+
}]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
registerZettelTools
|
|
87
|
+
};
|
package/tools/zettel.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zettel composition-inspection tools.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from server.ts. Registers:
|
|
5
|
+
* get_composition, resolve_composition, get_graph, zettel_stats, search_patterns
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
getComposition as getZettelComposition,
|
|
13
|
+
getAllCompositions as getAllZettelCompositions,
|
|
14
|
+
getGraph as getZettelGraph,
|
|
15
|
+
searchAll as searchCompositions,
|
|
16
|
+
} from '../../compose/strategies/zettel/composition-library.js';
|
|
17
|
+
import {
|
|
18
|
+
resolveComposition as resolveZettelComposition,
|
|
19
|
+
templateToMessages as zettelTemplateToMessages,
|
|
20
|
+
} from '../../compose/strategies/zettel/composer.js';
|
|
21
|
+
|
|
22
|
+
export function registerZettelTools(server: McpServer): void {
|
|
23
|
+
server.tool(
|
|
24
|
+
'search_patterns',
|
|
25
|
+
`Search the composition library for reusable UI templates. Returns matching compositions with full A2UI component trees that can be used directly or adapted.
|
|
26
|
+
|
|
27
|
+
Use this to find a starting point before generating from scratch. If a good composition exists, pass it to generate_ui with instant mode. If no composition matches, use generate_ui with thinking mode.
|
|
28
|
+
|
|
29
|
+
Keyword search (§64 v0.4.6 migration: now backed by composition-library; the historical "pattern" library is retired).`,
|
|
30
|
+
{
|
|
31
|
+
query: z.string().describe('Search query (natural language)'),
|
|
32
|
+
},
|
|
33
|
+
async ({ query }) => {
|
|
34
|
+
const results = searchCompositions(query);
|
|
35
|
+
return { content: [{ type: 'text', text: JSON.stringify(results, null, 2) }] };
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
server.tool(
|
|
40
|
+
'get_composition',
|
|
41
|
+
'Fetch a composition by name. Returns the flat A2UI template (compositions are pre-inlined; no $fragment refs). Zettel-only.',
|
|
42
|
+
{ name: z.string() },
|
|
43
|
+
async ({ name }) => {
|
|
44
|
+
const c = getZettelComposition(name);
|
|
45
|
+
if (!c) return { content: [{ type: 'text', text: `Composition not found: ${name}` }], isError: true };
|
|
46
|
+
return { content: [{ type: 'text', text: JSON.stringify(c, null, 2) }] };
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
server.tool(
|
|
51
|
+
'resolve_composition',
|
|
52
|
+
'Return the flat A2UI template + updateComponents messages for a composition. Zettel-only. (Pre-inlined since §37 — `resolve` is now a defensive copy + strip pass.)',
|
|
53
|
+
{ name: z.string() },
|
|
54
|
+
async ({ name }) => {
|
|
55
|
+
const c = getZettelComposition(name);
|
|
56
|
+
if (!c) return { content: [{ type: 'text', text: `Composition not found: ${name}` }], isError: true };
|
|
57
|
+
const template = resolveZettelComposition(c);
|
|
58
|
+
const messages = zettelTemplateToMessages(template);
|
|
59
|
+
return {
|
|
60
|
+
content: [{
|
|
61
|
+
type: 'text',
|
|
62
|
+
text: JSON.stringify({ template, messages }, null, 2),
|
|
63
|
+
}],
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
server.tool(
|
|
69
|
+
'get_graph',
|
|
70
|
+
'Return the composition catalog. Zettel-only. (Backlinks to fragments retired in §37; only composition nodes remain.)',
|
|
71
|
+
{},
|
|
72
|
+
async () => ({ content: [{ type: 'text', text: JSON.stringify(getZettelGraph(), null, 2) }] }),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
server.tool(
|
|
76
|
+
'zettel_stats',
|
|
77
|
+
'Zettel corpus stats — composition count + average node count. (Fragment stats retired in §37.)',
|
|
78
|
+
{},
|
|
79
|
+
async () => {
|
|
80
|
+
const comps = getAllZettelCompositions();
|
|
81
|
+
const totalNodes = comps.reduce((s, c) => {
|
|
82
|
+
const comp = c as Record<string, unknown>;
|
|
83
|
+
const tpl = comp['template'];
|
|
84
|
+
return s + (Array.isArray(tpl) ? tpl.length : 0);
|
|
85
|
+
}, 0);
|
|
86
|
+
return {
|
|
87
|
+
content: [{
|
|
88
|
+
type: 'text',
|
|
89
|
+
text: JSON.stringify({
|
|
90
|
+
compositions: comps.length,
|
|
91
|
+
avg_nodes_per_composition: comps.length ? Math.round(totalNodes / comps.length) : 0,
|
|
92
|
+
total_nodes: totalNodes,
|
|
93
|
+
}, null, 2),
|
|
94
|
+
}],
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
}
|