iter(g252): MCP get_component 增加 format=md 直出 Markdown

This commit is contained in:
HIsheR
2026-10-26 22:09:56 +08:00
parent eb9c606e08
commit 80ffee54d7
6 changed files with 26 additions and 13 deletions
+16 -3
View File
@@ -729,10 +729,13 @@ function cmdMcp() {
},
{
name: 'get_component',
description: 'Get one package by name, or one component by its id (returns props/steps/example)',
description: 'Get one package by name, or one component by its id; format=md returns a paste-ready Markdown block instead of raw JSON',
inputSchema: {
type: 'object',
properties: { name: { type: 'string', description: 'package name, e.g. @ui-arch/table-core or table-core' } },
properties: {
name: { type: 'string', description: 'component id (e.g. inputTag) or package name (e.g. @ui-arch/table-core)' },
format: { type: 'string', enum: ['json', 'md'], description: 'json (default) returns the manifest entry; md returns a paste-ready Markdown block (title + props table + usage + example)' },
},
required: ['name'],
},
},
@@ -786,6 +789,14 @@ function cmdMcp() {
if (p) return p;
const hit = collectComponents(packages).find((x) => x.comp.id === args.name); // 退化到组件级查询
if (!hit) throw new Error(`not found: ${args.name}`);
if (args.format === 'md') {
// 与 ua info --md 共用同一渲染:Agent 拿到就能直接贴进回复 / 文档,不必自己排参数表
const related = recipesFor(hit.comp.id);
const tail = related.length ? `
出现在配方:${related.map((r) => `${r.id}(${r.title})`).join('、')}` : '';
return formatComponentMd(hit.pkg, hit.comp) + tail; // 直接给字符串:上层原样作为 text 返回
}
return { package: hit.pkg.name, ...hit.comp, recipes: recipesFor(hit.comp.id) };
}
if (name === 'search_components') {
@@ -850,7 +861,9 @@ function cmdMcp() {
send({
jsonrpc: '2.0',
id,
result: { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] },
// 字符串结果原样返回:format=md 拿到的应是可读 Markdown,而不是被 JSON 转义成一行的
result: { content: [{ type: 'text', text: typeof result === 'string' ? result : JSON.stringify(result, null, 2) }] },
});
} catch (err) {
send({
+2 -2
View File
@@ -24,7 +24,7 @@
"ua audit:visual [--json|--baseline]:视觉漂移门禁,统计皮肤包里各类硬编码视觉字面量(字号/动效时长/阴影/圆角/焦点环/内距/控件高度/字重/行高/层级/边框色)并与 .ua/visual-baseline.json 棘轮比对,超基线退出码 1;--baseline 重写基线,--json 出机器可读计数与每类命中行号(line / prop / value / hint,Agent 可直接定位)",
"ua audit:contrast [--json|--list]:对比度门禁,把令牌里 16 组「文字色 × 底色」配对按 WCAG 公式算成对比度(求值支持 var() 与 color-mix,半透明底先压到页面底色),亮/暗 × 常规/高对比四套分算,低于阈值(正文 7 / 常规 4.5 / 禁用 2.6)退出码 1;--json 出逐对明细,--list 只列配对表",
"ua audit:motion [--json]:动效兜底门禁,扫描皮肤样式表里带 infinite 的动画,逐个核对是否在 prefers-reduced-motion 块里 animation: none,缺兜底退出码 1(--json 出逐条明细)",
"ua mcp:零依赖 stdio MCP server,暴露 list_components / get_component / search_components / get_tokens / list_recipes / get_recipe"
"ua mcp:零依赖 stdio MCP server,暴露 list_components / get_component / search_components / get_tokens / list_recipes / get_recipe;get_component 支持 format: md 直接取可粘贴的 Markdown 片段"
],
"keyTypes": [
"ua.manifest.json 清单结构",
@@ -49,7 +49,7 @@
"改完样式跑 npm run audit:visual:各类硬编码计数不得高于 .ua/visual-baseline.json(棘轮只减不增);字面量可用 npm run visual:migrate 幂等改写成令牌",
"改完颜色令牌跑 npm run audit:contrast:16 组文字/底色配对在亮/暗 × 常规/高对比四套主题下都必须达标(正文 7 / 常规 4.5 / 禁用 2.6),跌破即退出码 1——调一个色值就能让全站辅助文字掉到 4.4,人眼看不出但门禁看得出",
"改完动效跑 npm run audit:motion:带 infinite 的动画必须在 prefers-reduced-motion 块里被关掉,缺一条即退出码 1——循环动画漏兜底会把「减少动效」用户整页交给抖动",
"在 ~/.workbuddy/mcp.json 注册 ua mcp 后,Agent 可直接调 list_components / get_component / search_components / get_tokens / list_recipes / get_recipe"
"在 ~/.workbuddy/mcp.json 注册 ua mcp 后,Agent 可直接调 list_components / get_component / search_components / get_tokens / list_recipes / get_recipe;get_component 传 format: md 拿到与 ua info --md 同款的 Markdown 片段"
],
"components": []
}