Skip to content

Commit 5e07f3a

Browse files
committed
fix(mcp): ask for a selector when inspect-component or highlight gets none
Called without selector while a page reports, both tools threw a TypeError that reached the agent as a raw tool error. They now answer with what to pass.
1 parent 4968ed9 commit 5e07f3a

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎packages/devtools/src/__tests__/tool-metadata.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,21 @@ describe('agent tool output schemas', () => {
259259
}
260260
});
261261

262+
it('asks for a selector instead of failing when it is missing', async () => {
263+
const { invoke, push } = await bootMcp();
264+
await push('push-component-tree', {
265+
pageId: 'p1',
266+
roots: [{ id: 'c1', name: 'App', tag: 'app-root', children: [] }],
267+
count: 1,
268+
detail: null,
269+
});
270+
for (const name of ['pangular_inspect-component', 'pangular_highlight']) {
271+
const result = await invoke(name, {});
272+
expect(result.isError, name).toBeFalsy();
273+
expect(result.content[0]!.text, name).toContain('Pass `selector`');
274+
}
275+
});
276+
262277
it('keeps the markdown schema to one string field', () => {
263278
expect(MARKDOWN_OUTPUT_SCHEMA).toMatchObject({
264279
type: 'object',

‎packages/devtools/src/devframe.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,6 +2723,9 @@ const pangular = defineDevframe({
27232723
markdown: noComponentTree(', so nothing was highlighted'),
27242724
};
27252725
}
2726+
if (typeof args.selector !== 'string' || !args.selector.trim()) {
2727+
return { markdown: 'Pass `selector`: an instance id, class name or host tag.' };
2728+
}
27262729
const hits = componentHits(args.selector, page);
27272730
const [hit] = hits;
27282731
const target = hit
@@ -2810,6 +2813,9 @@ const pangular = defineDevframe({
28102813
if (![...componentPages.values()].some((entry) => entry.roots.length)) {
28112814
return { markdown: noComponentTree('') };
28122815
}
2816+
if (typeof args.selector !== 'string' || !args.selector.trim()) {
2817+
return { markdown: 'Pass `selector`: an instance id, class name or host tag.' };
2818+
}
28132819
const hits = componentHits(args.selector, page);
28142820
const [hit] = hits;
28152821
if (!hit) {

0 commit comments

Comments
 (0)