iter(g252): MCP get_component 增加 format=md 直出 Markdown
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user