@adia-ai/a2ui-mcp 0.6.5 → 0.6.7
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 +32 -0
- package/README.md +29 -5
- package/package.json +9 -3
- package/scripts/smoke-extended.mjs +274 -0
- package/server.js +97 -364
- package/tools/corpus.js +103 -0
- package/tools/discovery.js +89 -0
- package/tools/feedback.js +63 -0
- package/tools/refine.js +151 -0
- package/tools/validation.js +131 -0
- package/tools/zettel.js +87 -0
- package/tools/synthesis.ts +0 -449
package/server.js
CHANGED
|
@@ -2,48 +2,29 @@
|
|
|
2
2
|
import "../../../scripts/load-env.mjs";
|
|
3
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
6
|
+
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
|
7
|
+
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
5
9
|
import { z } from "zod";
|
|
6
10
|
import { generateUI } from "../compose/core/generator.js";
|
|
7
|
-
import { validateSchema } from "../validator/validator.js";
|
|
8
|
-
import { validateMessages as validateCatalogMessages } from "../validator/catalog-validator.js";
|
|
9
11
|
import {
|
|
10
12
|
getCatalog,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
getTraits,
|
|
14
|
-
getTraitsByCategory,
|
|
15
|
-
getFullCatalog
|
|
13
|
+
getFullCatalog,
|
|
14
|
+
getTraits
|
|
16
15
|
} from "../retrieval/catalog.js";
|
|
17
16
|
import { serializeEntry } from "../retrieval/component-entry.js";
|
|
18
17
|
import { classifyIntent, getDomain, getAllDomains } from "../retrieval/domain-router.js";
|
|
19
|
-
import { getAntiPatterns
|
|
20
|
-
import { assembleContext } from "../retrieval/context-assembler.js";
|
|
18
|
+
import { getAntiPatterns } from "../retrieval/anti-patterns.js";
|
|
21
19
|
import {
|
|
22
20
|
loadAll as loadZettelCorpus,
|
|
23
|
-
|
|
24
|
-
getAllCompositions as getAllZettelCompositions,
|
|
25
|
-
getGraph as getZettelGraph,
|
|
26
|
-
searchAll as searchCompositions
|
|
21
|
+
getAllCompositions as getAllZettelCompositions
|
|
27
22
|
} from "../compose/strategies/zettel/composition-library.js";
|
|
28
|
-
import {
|
|
29
|
-
resolveComposition as resolveZettelComposition,
|
|
30
|
-
templateToMessages as zettelTemplateToMessages
|
|
31
|
-
} from "../compose/strategies/zettel/composer.js";
|
|
32
23
|
const _zettelBoot = loadZettelCorpus();
|
|
33
24
|
console.error(
|
|
34
25
|
`[adiaui-mcp] zettel corpus: ${_zettelBoot.compositionCount} compositions`
|
|
35
26
|
);
|
|
36
|
-
import {
|
|
37
|
-
getChunk as getGenUIChunk,
|
|
38
|
-
getChunkIndex,
|
|
39
|
-
lookupChunksByPrimary,
|
|
40
|
-
searchChunks as searchGenUIChunks
|
|
41
|
-
} from "../corpus/scripts/chunk-library.js";
|
|
42
|
-
import { transpileHTML } from "../compose/transpiler/transpiler.js";
|
|
43
|
-
import { getWiringCatalog } from "../retrieval/wiring-catalog.js";
|
|
44
|
-
import { FeedbackCollector } from "../retrieval/feedback/feedback.js";
|
|
45
|
-
import { feedbackStore } from "../retrieval/feedback/feedback-store.js";
|
|
46
|
-
import { registerSynthesisTools } from "./tools/synthesis.js";
|
|
27
|
+
import { getChunkIndex } from "../corpus/scripts/chunk-library.js";
|
|
47
28
|
const _chunkIndex = getChunkIndex();
|
|
48
29
|
if (_chunkIndex) {
|
|
49
30
|
const idx = _chunkIndex;
|
|
@@ -54,10 +35,45 @@ if (_chunkIndex) {
|
|
|
54
35
|
} else {
|
|
55
36
|
console.error("[adiaui-mcp] gen-ui chunks: index not found \u2014 run `npm run harvest:chunks`");
|
|
56
37
|
}
|
|
38
|
+
import { registerSynthesisTools } from "./tools/synthesis.js";
|
|
39
|
+
import { registerValidationTools } from "./tools/validation.js";
|
|
40
|
+
import { registerFeedbackTools } from "./tools/feedback.js";
|
|
41
|
+
import { registerCorpusTools } from "./tools/corpus.js";
|
|
42
|
+
import { registerZettelTools } from "./tools/zettel.js";
|
|
43
|
+
import { registerDiscoveryTools } from "./tools/discovery.js";
|
|
44
|
+
import { registerRefineTools } from "./tools/refine.js";
|
|
57
45
|
const server = new McpServer({
|
|
58
46
|
name: "adia-ui",
|
|
59
|
-
version: "0.1.0"
|
|
47
|
+
version: "0.1.0",
|
|
48
|
+
capabilities: {
|
|
49
|
+
sampling: {}
|
|
50
|
+
// allows server to request LLM inference from the host (IDE/client)
|
|
51
|
+
}
|
|
60
52
|
});
|
|
53
|
+
async function resolveAdapter() {
|
|
54
|
+
const hasSampling = server.server?._clientCapabilities?.sampling;
|
|
55
|
+
if (hasSampling) {
|
|
56
|
+
return {
|
|
57
|
+
async complete({ messages, systemPrompt }) {
|
|
58
|
+
const result = await server.server.createMessage({
|
|
59
|
+
messages: messages.map((m) => ({
|
|
60
|
+
role: m.role,
|
|
61
|
+
content: { type: "text", text: m.content }
|
|
62
|
+
})),
|
|
63
|
+
...systemPrompt ? { systemPrompt } : {},
|
|
64
|
+
maxTokens: 32768
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
content: typeof result.content === "string" ? result.content : result.content?.text ?? "",
|
|
68
|
+
stopReason: result.stopReason ?? "end",
|
|
69
|
+
usage: { inputTokens: 0, outputTokens: 0, cacheCreationTokens: 0, cacheReadTokens: 0 }
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const { createAdapter } = await import("../../llm/llm-bridge.js");
|
|
75
|
+
return createAdapter();
|
|
76
|
+
}
|
|
61
77
|
server.tool(
|
|
62
78
|
"plan_app_state",
|
|
63
79
|
`Analyze a natural language prompt and extract the top-level Generative UI Ontology structures (Intent, Domain, Tasks, Experience).
|
|
@@ -67,8 +83,7 @@ Use this tool BEFORE generating UI to ensure you have walked the Reasoning Ladde
|
|
|
67
83
|
prompt: z.string().describe('The natural language request (e.g., "Build a dashboard for incoming sales leads")')
|
|
68
84
|
},
|
|
69
85
|
async ({ prompt }) => {
|
|
70
|
-
const
|
|
71
|
-
const llm = await createAdapter();
|
|
86
|
+
const llm = await resolveAdapter();
|
|
72
87
|
const systemPrompt = `You are the A2UI Ontology Planner.
|
|
73
88
|
Given a user prompt, you must extract the Core App State using the 5-Gate Reasoning Ladder.
|
|
74
89
|
|
|
@@ -155,13 +170,15 @@ The generator knows 96+ UI patterns across 5 domains: forms, data, layout, agent
|
|
|
155
170
|
try {
|
|
156
171
|
const selectedEngine = engine ?? "monolithic";
|
|
157
172
|
const effectiveMode = selectedEngine === "zettel" ? "instant" : mode ?? "pro";
|
|
173
|
+
const llmAdapter = effectiveMode !== "instant" ? await resolveAdapter() : void 0;
|
|
158
174
|
const result = await generateUI({
|
|
159
175
|
intent,
|
|
160
176
|
engine: selectedEngine,
|
|
161
177
|
mode: effectiveMode,
|
|
162
178
|
sessionId,
|
|
163
|
-
context
|
|
179
|
+
context,
|
|
164
180
|
// Pass the ontology context down to the composer
|
|
181
|
+
...llmAdapter ? { llmAdapter } : {}
|
|
165
182
|
});
|
|
166
183
|
return {
|
|
167
184
|
content: [{
|
|
@@ -185,69 +202,6 @@ The generator knows 96+ UI patterns across 5 domains: forms, data, layout, agent
|
|
|
185
202
|
}
|
|
186
203
|
}
|
|
187
204
|
);
|
|
188
|
-
server.tool(
|
|
189
|
-
"validate_schema",
|
|
190
|
-
"Validate A2UI messages against schema rules.",
|
|
191
|
-
{
|
|
192
|
-
messages: z.string().describe("JSON array of A2UI messages")
|
|
193
|
-
},
|
|
194
|
-
async ({ messages }) => {
|
|
195
|
-
try {
|
|
196
|
-
const parsed = JSON.parse(messages);
|
|
197
|
-
const msgs = Array.isArray(parsed) ? parsed : [parsed];
|
|
198
|
-
const scored = validateSchema(msgs);
|
|
199
|
-
const catalog = await validateCatalogMessages(msgs);
|
|
200
|
-
const result = { ...scored, catalog };
|
|
201
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
202
|
-
} catch (err) {
|
|
203
|
-
const e = err instanceof Error ? err : new Error(String(err));
|
|
204
|
-
return { content: [{ type: "text", text: `Parse error: ${e.message}` }], isError: true };
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
);
|
|
208
|
-
server.tool(
|
|
209
|
-
"lookup_component",
|
|
210
|
-
"Look up a AdiaUI component by type name.",
|
|
211
|
-
{
|
|
212
|
-
type: z.string().describe('Component type (e.g., "Card", "Button")'),
|
|
213
|
-
level: z.enum(["index", "summary", "reference"]).optional().describe("Detail level (default: reference)")
|
|
214
|
-
},
|
|
215
|
-
async ({ type, level }) => {
|
|
216
|
-
const entry = await getComponent(type);
|
|
217
|
-
if (!entry) return { content: [{ type: "text", text: `Not found: ${type}` }], isError: true };
|
|
218
|
-
const serialized = serializeEntry(entry, level ?? "reference");
|
|
219
|
-
return { content: [{ type: "text", text: JSON.stringify(serialized, null, 2) }] };
|
|
220
|
-
}
|
|
221
|
-
);
|
|
222
|
-
server.tool(
|
|
223
|
-
"get_component_map",
|
|
224
|
-
"Get the full AdiaUI component catalog.",
|
|
225
|
-
{},
|
|
226
|
-
async () => {
|
|
227
|
-
const catalog = await getCatalog();
|
|
228
|
-
const summary = [...catalog.entries.values()].map((e) => {
|
|
229
|
-
const entry = e;
|
|
230
|
-
const desc = typeof entry["description"] === "string" ? entry["description"].slice(0, 80) : "";
|
|
231
|
-
return `${entry["type"]} -> <${entry["tag"]}>: ${desc}`;
|
|
232
|
-
}).join("\n");
|
|
233
|
-
return { content: [{ type: "text", text: summary }] };
|
|
234
|
-
}
|
|
235
|
-
);
|
|
236
|
-
server.tool(
|
|
237
|
-
"search_patterns",
|
|
238
|
-
`Search the composition library for reusable UI templates. Returns matching compositions with full A2UI component trees that can be used directly or adapted.
|
|
239
|
-
|
|
240
|
-
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.
|
|
241
|
-
|
|
242
|
-
Keyword search (\xA764 v0.4.6 migration: now backed by composition-library; the historical "pattern" library is retired).`,
|
|
243
|
-
{
|
|
244
|
-
query: z.string().describe("Search query (natural language)")
|
|
245
|
-
},
|
|
246
|
-
async ({ query }) => {
|
|
247
|
-
const results = searchCompositions(query);
|
|
248
|
-
return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] };
|
|
249
|
-
}
|
|
250
|
-
);
|
|
251
205
|
server.tool(
|
|
252
206
|
"classify_intent",
|
|
253
207
|
"Classify intent into a UI domain.",
|
|
@@ -258,125 +212,6 @@ server.tool(
|
|
|
258
212
|
return { content: [{ type: "text", text: JSON.stringify(classifyIntent(text), null, 2) }] };
|
|
259
213
|
}
|
|
260
214
|
);
|
|
261
|
-
server.tool(
|
|
262
|
-
"assemble_context",
|
|
263
|
-
`Assemble progressive-disclosure context for a given intent and budget tier. Returns domain-relevant components, matching patterns, and anti-patterns.
|
|
264
|
-
|
|
265
|
-
Tier 0: domain only. Tier 1: components. Tier 2: +patterns. Tier 3: +anti-patterns. Tier 4: full catalog.
|
|
266
|
-
|
|
267
|
-
Use this when you want to manually compose A2UI output rather than using generate_ui. The returned context gives you the building blocks.`,
|
|
268
|
-
{
|
|
269
|
-
intent: z.string().describe("Natural language intent"),
|
|
270
|
-
tier: z.number().min(0).max(4).optional().describe("Budget tier 0-4 (default: 1)")
|
|
271
|
-
},
|
|
272
|
-
async ({ intent, tier }) => {
|
|
273
|
-
const result = assembleContext({ intent, tier: tier ?? 1 });
|
|
274
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
275
|
-
}
|
|
276
|
-
);
|
|
277
|
-
server.tool(
|
|
278
|
-
"check_anti_patterns",
|
|
279
|
-
"Check HTML against all anti-patterns. Returns only violations.",
|
|
280
|
-
{
|
|
281
|
-
html: z.string().describe("HTML string to check")
|
|
282
|
-
},
|
|
283
|
-
async ({ html }) => {
|
|
284
|
-
const violations = checkAllAntiPatterns(html);
|
|
285
|
-
return { content: [{ type: "text", text: JSON.stringify(violations, null, 2) }] };
|
|
286
|
-
}
|
|
287
|
-
);
|
|
288
|
-
server.tool(
|
|
289
|
-
"get_traits",
|
|
290
|
-
"Get the trait catalog, optionally filtered by category.",
|
|
291
|
-
{
|
|
292
|
-
category: z.string().optional().describe('Trait category filter (e.g., "input-interaction", "motion-positioning")')
|
|
293
|
-
},
|
|
294
|
-
async ({ category }) => {
|
|
295
|
-
const traits = category ? getTraitsByCategory(category) : getTraits();
|
|
296
|
-
return { content: [{ type: "text", text: JSON.stringify(traits, null, 2) }] };
|
|
297
|
-
}
|
|
298
|
-
);
|
|
299
|
-
server.tool(
|
|
300
|
-
"convert_html",
|
|
301
|
-
"Convert HTML markup to A2UI flat adjacency component messages. Maps HTML tags to AdiaUI components, infers layout from styles, enforces Card content model.",
|
|
302
|
-
{
|
|
303
|
-
html: z.string().describe("HTML markup to convert"),
|
|
304
|
-
mode: z.enum(["instant", "reasoning"]).optional().describe("instant = rules only, reasoning = LLM for complex layouts")
|
|
305
|
-
},
|
|
306
|
-
async ({ html, mode }) => {
|
|
307
|
-
try {
|
|
308
|
-
const result = await transpileHTML(html, { mode: mode ?? "instant" });
|
|
309
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
310
|
-
} catch (err) {
|
|
311
|
-
const e = err instanceof Error ? err : new Error(String(err));
|
|
312
|
-
return { content: [{ type: "text", text: `Transpile error: ${e.message}` }], isError: true };
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
);
|
|
316
|
-
server.tool(
|
|
317
|
-
"get_wiring_catalog",
|
|
318
|
-
"Get the AdiaUI wiring catalog: available controllers, action handlers, refresh strategies, value sources, and association types.",
|
|
319
|
-
{},
|
|
320
|
-
async () => {
|
|
321
|
-
const catalog = getWiringCatalog();
|
|
322
|
-
return { content: [{ type: "text", text: JSON.stringify(catalog, null, 2) }] };
|
|
323
|
-
}
|
|
324
|
-
);
|
|
325
|
-
const feedbackCollector = new FeedbackCollector();
|
|
326
|
-
server.tool(
|
|
327
|
-
"submit_feedback",
|
|
328
|
-
"Submit structured feedback for a generation execution. Used by the evolution engine to learn from each generation.",
|
|
329
|
-
{
|
|
330
|
-
executionId: z.string().describe("Execution ID from generate_ui"),
|
|
331
|
-
rating: z.number().min(1).max(5).describe("Overall quality 1-5"),
|
|
332
|
-
intent: z.string().optional(),
|
|
333
|
-
domain: z.string().optional(),
|
|
334
|
-
intentAlignment: z.number().min(1).max(5).optional(),
|
|
335
|
-
visualQuality: z.number().min(1).max(5).optional(),
|
|
336
|
-
componentChoice: z.number().min(1).max(5).optional(),
|
|
337
|
-
userEdited: z.boolean().optional(),
|
|
338
|
-
editSummary: z.string().optional(),
|
|
339
|
-
notes: z.string().optional(),
|
|
340
|
-
shouldBePattern: z.boolean().optional(),
|
|
341
|
-
suggestedName: z.string().optional()
|
|
342
|
-
},
|
|
343
|
-
async (args) => {
|
|
344
|
-
feedbackCollector.collectFeedback(args.executionId, {
|
|
345
|
-
rating: args.rating,
|
|
346
|
-
intentAlignment: args.intentAlignment,
|
|
347
|
-
visualQuality: args.visualQuality,
|
|
348
|
-
componentChoice: args.componentChoice,
|
|
349
|
-
userEdited: args.userEdited,
|
|
350
|
-
editSummary: args.editSummary,
|
|
351
|
-
notes: args.notes
|
|
352
|
-
});
|
|
353
|
-
if (args.shouldBePattern != null) {
|
|
354
|
-
feedbackCollector.collectPatternFeedback(args.executionId, {
|
|
355
|
-
shouldBePattern: args.shouldBePattern,
|
|
356
|
-
suggestedName: args.suggestedName
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
return { content: [{ type: "text", text: JSON.stringify({ recorded: true, executionId: args.executionId, totalEntries: feedbackCollector.size }) }] };
|
|
360
|
-
}
|
|
361
|
-
);
|
|
362
|
-
server.tool(
|
|
363
|
-
"get_quality_metrics",
|
|
364
|
-
"Get aggregated quality metrics from the feedback store: avg score, thumb-up rate, per-domain breakdown, training gaps.",
|
|
365
|
-
{},
|
|
366
|
-
async () => {
|
|
367
|
-
const metrics = await feedbackStore.getQualityMetrics();
|
|
368
|
-
return { content: [{ type: "text", text: JSON.stringify(metrics, null, 2) }] };
|
|
369
|
-
}
|
|
370
|
-
);
|
|
371
|
-
server.tool(
|
|
372
|
-
"get_training_gaps",
|
|
373
|
-
"Get training gap signals from LLM self-critique: missing patterns, weak domain keywords, component gaps.",
|
|
374
|
-
{},
|
|
375
|
-
async () => {
|
|
376
|
-
const gaps = await feedbackStore.getGapSummary();
|
|
377
|
-
return { content: [{ type: "text", text: JSON.stringify(gaps, null, 2) }] };
|
|
378
|
-
}
|
|
379
|
-
);
|
|
380
215
|
server.tool(
|
|
381
216
|
"run_eval",
|
|
382
217
|
"Run the offline eval harness against the held-out intent set. Returns aggregate scores and per-intent results.",
|
|
@@ -460,160 +295,58 @@ server.resource(
|
|
|
460
295
|
};
|
|
461
296
|
}
|
|
462
297
|
);
|
|
463
|
-
server
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
async ({ name }) => {
|
|
468
|
-
const c = getZettelComposition(name);
|
|
469
|
-
if (!c) return { content: [{ type: "text", text: `Composition not found: ${name}` }], isError: true };
|
|
470
|
-
return { content: [{ type: "text", text: JSON.stringify(c, null, 2) }] };
|
|
471
|
-
}
|
|
472
|
-
);
|
|
473
|
-
server.tool(
|
|
474
|
-
"resolve_composition",
|
|
475
|
-
"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.)",
|
|
476
|
-
{ name: z.string() },
|
|
477
|
-
async ({ name }) => {
|
|
478
|
-
const c = getZettelComposition(name);
|
|
479
|
-
if (!c) return { content: [{ type: "text", text: `Composition not found: ${name}` }], isError: true };
|
|
480
|
-
const template = resolveZettelComposition(c);
|
|
481
|
-
const messages = zettelTemplateToMessages(template);
|
|
482
|
-
return {
|
|
483
|
-
content: [{
|
|
484
|
-
type: "text",
|
|
485
|
-
text: JSON.stringify({ template, messages }, null, 2)
|
|
486
|
-
}]
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
);
|
|
490
|
-
server.tool(
|
|
491
|
-
"get_graph",
|
|
492
|
-
"Return the composition catalog. Zettel-only. (Backlinks to fragments retired in \xA737; only composition nodes remain.)",
|
|
493
|
-
{},
|
|
494
|
-
async () => ({ content: [{ type: "text", text: JSON.stringify(getZettelGraph(), null, 2) }] })
|
|
495
|
-
);
|
|
496
|
-
server.tool(
|
|
497
|
-
"zettel_stats",
|
|
498
|
-
"Zettel corpus stats \u2014 composition count + average node count. (Fragment stats retired in \xA737.)",
|
|
499
|
-
{},
|
|
500
|
-
async () => {
|
|
501
|
-
const comps = getAllZettelCompositions();
|
|
502
|
-
const totalNodes = comps.reduce((s, c) => {
|
|
503
|
-
const comp = c;
|
|
504
|
-
const tpl = comp["template"];
|
|
505
|
-
return s + (Array.isArray(tpl) ? tpl.length : 0);
|
|
506
|
-
}, 0);
|
|
507
|
-
return {
|
|
508
|
-
content: [{
|
|
509
|
-
type: "text",
|
|
510
|
-
text: JSON.stringify({
|
|
511
|
-
compositions: comps.length,
|
|
512
|
-
avg_nodes_per_composition: comps.length ? Math.round(totalNodes / comps.length) : 0,
|
|
513
|
-
total_nodes: totalNodes
|
|
514
|
-
}, null, 2)
|
|
515
|
-
}]
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
);
|
|
519
|
-
server.tool(
|
|
520
|
-
"search_chunks",
|
|
521
|
-
`Search the gen-UI training-chunk corpus by keyword.
|
|
522
|
-
|
|
523
|
-
The chunk corpus comes from \`packages/a2ui/corpus/chunks/\` \u2014 JSON records
|
|
524
|
-
extracted from every \`[data-chunk]\` element in site/pages/* and the corpus
|
|
525
|
-
exemplars. There are three kinds:
|
|
526
|
-
- block (default): atomic UI fragment (KPI grid, sign-in form, table)
|
|
527
|
-
- panel: tab-panel fragment of a page (e.g. dashboard-overview-panel)
|
|
528
|
-
- page: full-page composition (e.g. dashboard-admin-page)
|
|
529
|
-
|
|
530
|
-
Returns ranked candidates with chunk name, kind, primary tag, and a relevance
|
|
531
|
-
score. Use \`get_chunk\` to fetch the full record (HTML + slot bindings + nested
|
|
532
|
-
chunks) for a specific name.`,
|
|
533
|
-
{
|
|
534
|
-
query: z.string().describe("Keyword query \u2014 chunk name fragment, intent words, primary-tag name"),
|
|
535
|
-
kind: z.enum(["block", "panel", "page"]).optional().describe("Filter by chunk kind"),
|
|
536
|
-
limit: z.number().int().min(1).max(50).default(20).describe("Max results")
|
|
537
|
-
},
|
|
538
|
-
async ({ query, kind, limit }) => {
|
|
539
|
-
const results = searchGenUIChunks(query, { kind, limit });
|
|
540
|
-
return {
|
|
541
|
-
content: [{
|
|
542
|
-
type: "text",
|
|
543
|
-
text: JSON.stringify({ query, kind: kind ?? "any", count: results.length, results }, null, 2)
|
|
544
|
-
}]
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
);
|
|
548
|
-
server.tool(
|
|
549
|
-
"get_chunk",
|
|
550
|
-
`Fetch the full record for a single gen-UI training chunk by name.
|
|
551
|
-
|
|
552
|
-
Returns the chunk's bounding HTML, slot annotations, nested chunk names, and
|
|
553
|
-
metadata (primary tag, kind, source page). For chunks that appear on multiple
|
|
554
|
-
pages (reusable slot chunks like \`auth-card-header\`, \`reg-step-header\`),
|
|
555
|
-
returns an \`instances\` array \u2014 one entry per page where the chunk appears.
|
|
556
|
-
|
|
557
|
-
The HTML is suitable for direct rendering / inclusion in an A2UI message
|
|
558
|
-
construction prompt.`,
|
|
559
|
-
{
|
|
560
|
-
name: z.string().describe('The chunk name, e.g. "dashboard-kpi-grid", "auth-signin-card-email", "code-language"')
|
|
561
|
-
},
|
|
562
|
-
async ({ name }) => {
|
|
563
|
-
const rec = getGenUIChunk(name);
|
|
564
|
-
if (!rec) {
|
|
565
|
-
return {
|
|
566
|
-
isError: true,
|
|
567
|
-
content: [{ type: "text", text: JSON.stringify({ error: "chunk not found", name }, null, 2) }]
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
return { content: [{ type: "text", text: JSON.stringify(rec, null, 2) }] };
|
|
571
|
-
}
|
|
572
|
-
);
|
|
573
|
-
server.tool(
|
|
574
|
-
"lookup_chunk",
|
|
575
|
-
`List every chunk whose primary element is \`<component_name>\`.
|
|
576
|
-
|
|
577
|
-
Useful for "show me every page that opens with a \`<card-ui raw>\`" or "every
|
|
578
|
-
chunk built around a \`<grid-ui>\` root." Returns chunk names + kinds + sources.
|
|
579
|
-
|
|
580
|
-
Pair with \`get_chunk\` to fetch full records for any of the returned names.`,
|
|
581
|
-
{
|
|
582
|
-
component_name: z.string().describe('Component tag name, e.g. "card-ui", "grid-ui", "drawer-ui"')
|
|
583
|
-
},
|
|
584
|
-
async ({ component_name }) => {
|
|
585
|
-
const recs = lookupChunksByPrimary(component_name);
|
|
586
|
-
return {
|
|
587
|
-
content: [{
|
|
588
|
-
type: "text",
|
|
589
|
-
text: JSON.stringify({
|
|
590
|
-
component: component_name,
|
|
591
|
-
count: recs.length,
|
|
592
|
-
chunks: recs.map((r) => {
|
|
593
|
-
const rec = r;
|
|
594
|
-
const instances = rec["instances"];
|
|
595
|
-
const firstInstance = instances?.[0];
|
|
596
|
-
const slots = rec["slots"] ?? firstInstance?.["slots"] ?? [];
|
|
597
|
-
const nested = rec["nested"] ?? firstInstance?.["nested"] ?? [];
|
|
598
|
-
return {
|
|
599
|
-
name: rec["name"],
|
|
600
|
-
kind: rec["kind"],
|
|
601
|
-
page: rec["page"] ?? firstInstance?.["page"],
|
|
602
|
-
slots: slots.map((s) => s.name),
|
|
603
|
-
nested
|
|
604
|
-
};
|
|
605
|
-
})
|
|
606
|
-
}, null, 2)
|
|
607
|
-
}]
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
);
|
|
298
|
+
registerValidationTools(server);
|
|
299
|
+
registerFeedbackTools(server);
|
|
300
|
+
registerCorpusTools(server);
|
|
301
|
+
registerZettelTools(server);
|
|
611
302
|
registerSynthesisTools(server);
|
|
612
|
-
|
|
303
|
+
registerDiscoveryTools(server);
|
|
304
|
+
registerRefineTools(server);
|
|
305
|
+
async function startStdio() {
|
|
613
306
|
const transport = new StdioServerTransport();
|
|
614
307
|
await server.connect(transport);
|
|
615
308
|
const catalog = await getCatalog();
|
|
616
309
|
const traits = getTraits();
|
|
617
|
-
console.error(`
|
|
310
|
+
console.error(`[adiaui-mcp] stdio transport ready (${catalog.totalTypes} components, ${traits.length} traits, ${_zettelBoot.compositionCount} compositions)`);
|
|
311
|
+
}
|
|
312
|
+
async function startHttp(port) {
|
|
313
|
+
const transports = /* @__PURE__ */ new Map();
|
|
314
|
+
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
|
315
|
+
app.all("/mcp", async (req, res) => {
|
|
316
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
317
|
+
if (sessionId && transports.has(sessionId)) {
|
|
318
|
+
const existing = transports.get(sessionId);
|
|
319
|
+
await existing.handleRequest(req, res, req.body);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (req.method === "POST" && isInitializeRequest(req.body)) {
|
|
323
|
+
const id = randomUUID();
|
|
324
|
+
const transport = new StreamableHTTPServerTransport({
|
|
325
|
+
sessionIdGenerator: () => id,
|
|
326
|
+
onsessioninitialized: (sid) => transports.set(sid, transport)
|
|
327
|
+
});
|
|
328
|
+
transport.onclose = () => transports.delete(id);
|
|
329
|
+
await server.connect(transport);
|
|
330
|
+
await transport.handleRequest(req, res, req.body);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
res.status(400).json({ error: "Invalid request \u2014 missing session or not an initialize request" });
|
|
334
|
+
});
|
|
335
|
+
app.listen(port, () => {
|
|
336
|
+
const catalog = getCatalog();
|
|
337
|
+
console.error(`[adiaui-mcp] HTTP transport ready on http://0.0.0.0:${port}/mcp`);
|
|
338
|
+
console.error(`[adiaui-mcp] API keys required for pro/thinking mode (no sampling in HTTP mode)`);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
async function main() {
|
|
342
|
+
const httpPort = typeof process !== "undefined" && process.env?.MCP_HTTP_PORT ? parseInt(process.env.MCP_HTTP_PORT, 10) : null;
|
|
343
|
+
if (httpPort) {
|
|
344
|
+
await startHttp(httpPort);
|
|
345
|
+
} else {
|
|
346
|
+
await startStdio();
|
|
347
|
+
}
|
|
618
348
|
}
|
|
619
349
|
main().catch(console.error);
|
|
350
|
+
export {
|
|
351
|
+
resolveAdapter
|
|
352
|
+
};
|
package/tools/corpus.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
getChunk as getGenUIChunk,
|
|
4
|
+
lookupChunksByPrimary,
|
|
5
|
+
searchChunks as searchGenUIChunks
|
|
6
|
+
} from "../../corpus/scripts/chunk-library.js";
|
|
7
|
+
function registerCorpusTools(server) {
|
|
8
|
+
server.tool(
|
|
9
|
+
"search_chunks",
|
|
10
|
+
`Search the gen-UI training-chunk corpus by keyword.
|
|
11
|
+
|
|
12
|
+
The chunk corpus comes from \`packages/a2ui/corpus/chunks/\` \u2014 JSON records
|
|
13
|
+
extracted from every \`[data-chunk]\` element in site/pages/* and the corpus
|
|
14
|
+
exemplars. There are three kinds:
|
|
15
|
+
- block (default): atomic UI fragment (KPI grid, sign-in form, table)
|
|
16
|
+
- panel: tab-panel fragment of a page (e.g. dashboard-overview-panel)
|
|
17
|
+
- page: full-page composition (e.g. dashboard-admin-page)
|
|
18
|
+
|
|
19
|
+
Returns ranked candidates with chunk name, kind, primary tag, and a relevance
|
|
20
|
+
score. Use \`get_chunk\` to fetch the full record (HTML + slot bindings + nested
|
|
21
|
+
chunks) for a specific name.`,
|
|
22
|
+
{
|
|
23
|
+
query: z.string().describe("Keyword query \u2014 chunk name fragment, intent words, primary-tag name"),
|
|
24
|
+
kind: z.enum(["block", "panel", "page"]).optional().describe("Filter by chunk kind"),
|
|
25
|
+
limit: z.number().int().min(1).max(50).default(20).describe("Max results")
|
|
26
|
+
},
|
|
27
|
+
async ({ query, kind, limit }) => {
|
|
28
|
+
const results = searchGenUIChunks(query, { kind, limit });
|
|
29
|
+
return {
|
|
30
|
+
content: [{
|
|
31
|
+
type: "text",
|
|
32
|
+
text: JSON.stringify({ query, kind: kind ?? "any", count: results.length, results }, null, 2)
|
|
33
|
+
}]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
server.tool(
|
|
38
|
+
"get_chunk",
|
|
39
|
+
`Fetch the full record for a single gen-UI training chunk by name.
|
|
40
|
+
|
|
41
|
+
Returns the chunk's bounding HTML, slot annotations, nested chunk names, and
|
|
42
|
+
metadata (primary tag, kind, source page). For chunks that appear on multiple
|
|
43
|
+
pages (reusable slot chunks like \`auth-card-header\`, \`reg-step-header\`),
|
|
44
|
+
returns an \`instances\` array \u2014 one entry per page where the chunk appears.
|
|
45
|
+
|
|
46
|
+
The HTML is suitable for direct rendering / inclusion in an A2UI message
|
|
47
|
+
construction prompt.`,
|
|
48
|
+
{
|
|
49
|
+
name: z.string().describe('The chunk name, e.g. "dashboard-kpi-grid", "auth-signin-card-email", "code-language"')
|
|
50
|
+
},
|
|
51
|
+
async ({ name }) => {
|
|
52
|
+
const rec = getGenUIChunk(name);
|
|
53
|
+
if (!rec) {
|
|
54
|
+
return {
|
|
55
|
+
isError: true,
|
|
56
|
+
content: [{ type: "text", text: JSON.stringify({ error: "chunk not found", name }, null, 2) }]
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return { content: [{ type: "text", text: JSON.stringify(rec, null, 2) }] };
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
server.tool(
|
|
63
|
+
"lookup_chunk",
|
|
64
|
+
`List every chunk whose primary element is \`<component_name>\`.
|
|
65
|
+
|
|
66
|
+
Useful for "show me every page that opens with a \`<card-ui raw>\`" or "every
|
|
67
|
+
chunk built around a \`<grid-ui>\` root." Returns chunk names + kinds + sources.
|
|
68
|
+
|
|
69
|
+
Pair with \`get_chunk\` to fetch full records for any of the returned names.`,
|
|
70
|
+
{
|
|
71
|
+
component_name: z.string().describe('Component tag name, e.g. "card-ui", "grid-ui", "drawer-ui"')
|
|
72
|
+
},
|
|
73
|
+
async ({ component_name }) => {
|
|
74
|
+
const recs = lookupChunksByPrimary(component_name);
|
|
75
|
+
return {
|
|
76
|
+
content: [{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: JSON.stringify({
|
|
79
|
+
component: component_name,
|
|
80
|
+
count: recs.length,
|
|
81
|
+
chunks: recs.map((r) => {
|
|
82
|
+
const rec = r;
|
|
83
|
+
const instances = rec["instances"];
|
|
84
|
+
const firstInstance = instances?.[0];
|
|
85
|
+
const slots = rec["slots"] ?? firstInstance?.["slots"] ?? [];
|
|
86
|
+
const nested = rec["nested"] ?? firstInstance?.["nested"] ?? [];
|
|
87
|
+
return {
|
|
88
|
+
name: rec["name"],
|
|
89
|
+
kind: rec["kind"],
|
|
90
|
+
page: rec["page"] ?? firstInstance?.["page"],
|
|
91
|
+
slots: slots.map((s) => s.name),
|
|
92
|
+
nested
|
|
93
|
+
};
|
|
94
|
+
})
|
|
95
|
+
}, null, 2)
|
|
96
|
+
}]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
registerCorpusTools
|
|
103
|
+
};
|