iter(g154): MCP 搜索补组件级命中

原 search_components 只搜包级字段,命中后返回包,Agent 还得再猜组件 id。
改为返回 { packages, components } 两级,组件按 id / 标题 / props 名命中并带 package。
This commit is contained in:
HIsheR
2026-10-26 15:54:05 +08:00
parent c423d9cb2d
commit ab758ab9fc
2 changed files with 19 additions and 3 deletions
+11 -3
View File
@@ -566,7 +566,7 @@ function cmdMcp() {
},
{
name: 'search_components',
description: 'Search packages by keyword across name/description/tags/api',
description: 'Search by keyword: returns matched packages plus matched components (id/title/props)',
inputSchema: {
type: 'object',
properties: { query: { type: 'string' } },
@@ -619,8 +619,9 @@ function cmdMcp() {
return { package: hit.pkg.name, ...hit.comp, recipes: recipesFor(hit.comp.id) };
}
if (name === 'search_components') {
const q = String(args.query ?? '').toLowerCase();
return packages
const q = String(args.query ?? '').toLowerCase().trim();
if (!q) throw new Error('query 不能为空');
const pkgs = packages
.filter((p) =>
[p.name, p.description, p.type, ...(p.tags ?? []), ...(p.api?.exports ?? [])]
.join(' ')
@@ -628,6 +629,13 @@ function cmdMcp() {
.includes(q),
)
.map((p) => ({ name: p.name, version: p.version, type: p.type, description: p.description }));
const comps = collectComponents(packages) // 组件级命中:包级 exports 只给出包名,Agent 还得再查一次
.filter(({ comp }) =>
[comp.id, comp.title, ...(comp.props ?? []).map((p) => p.n)].join(' ').toLowerCase().includes(q),
)
.map(({ pkg, comp }) => ({ package: pkg.name, id: comp.id, title: comp.title }));
if (!pkgs.length && !comps.length) throw new Error(`no match: ${args.query}`);
return { packages: pkgs, components: comps };
}
if (name === 'get_tokens') {
const list = loadTokenList();