Skip to content

Commit bed696a

Browse files
erkamyamanKaap10
andauthored
feat(mcp): trim tool and resource descriptions under 600 characters (#403)
Every agent tool and resource description now fits in 40 to 600 characters, and a test keeps it that way. Refs #372. Co-authored-by: Kaap10 <[email protected]>
1 parent 5494e80 commit bed696a

22 files changed

Lines changed: 104 additions & 60 deletions

‎apps/docs/src/content/agents/mcp-server.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Your client can ask you before it runs them. To drop them from the server, set `
276276

277277
### Pages and tabs
278278

279-
Each browser tab reports on its own and gets a page id, and so does an [Angular Native](../getting-started/angular-native.md) or [NativeScript](../getting-started/nativescript.md) app. `list-pages` lists them with their platform. Tools that read live data use the most recent page by default. Pass `page` to pick another tab (`inspect-providers`, `highlight`, `inspect-component` and `defer-blocks` also accept `pageId`). An id that no tab reports gets an answer that lists the tabs that do, instead of data from another tab. The server drops pages that stop reporting after a short time.
279+
Each browser tab reports on its own and gets a page id, and so does an [Angular Native](../getting-started/angular-native.md) or [NativeScript](../getting-started/nativescript.md) app. `list-pages` lists them with their platform. Most tools that read live data use the most recent page by default, and [Agent tools](./tools.md) names the ones that don't. Pass `page` to pick another tab (`inspect-providers`, `highlight`, `inspect-component` and `defer-blocks` also accept `pageId`). An id that no tab reports gets an answer that lists the tabs that do, instead of data from another tab. The server drops pages that stop reporting after a short time.
280280

281281
## Where to next
282282

‎apps/docs/src/content/agents/tools.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,11 @@ While on, the overlay wraps `Observable.prototype.subscribe` and records which c
289289

290290
An image of one component's host element as the page renders it now. The answer is an MCP image content block (PNG, or JPEG when the PNG is large) with a short note: the size in CSS pixels, what was masked and what could not be drawn. Reads: page.
291291

292-
| Argument | Required | Value |
293-
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------- |
294-
| `selector` | yes | An instance id from the `component-tree` resource (like `c12`), a class name, a host tag or any CSS selector. |
295-
| `page` | no | The page id, from `list-pages`. Defaults to the most recent page. |
296-
| `pageId` | no | Same as `page`. |
292+
| Argument | Required | Value |
293+
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
294+
| `selector` | yes | An instance id from the `component-tree` resource (like `c12`), a class name, a host tag or any CSS selector. |
295+
| `page` | no | The page id, from `list-pages`. Without it, ids, class names and tags are searched on every page, newest first, and a CSS selector uses the most recent page. |
296+
| `pageId` | no | Same as `page`. |
297297

298298
The page draws a copy of the element, not the screen: it copies the element's DOM with every computed style written inline into an SVG, and draws that on a canvas that is never added to the page. Nothing in the app changes, no app code runs, and a component scrolled out of view or behind a dialog is drawn all the same. A class name or tag that matches several instances captures the first and lists the ids of all of them. A CSS selector captures the first element it matches on the most recent page, or on `page`.
299299

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { createHostContext } from 'devframe/node';
2+
import { expect, it } from 'vitest';
3+
import pangular from '../devframe.ts';
4+
5+
it('keeps all agent tool and resource descriptions under 600 characters', async () => {
6+
const host = {
7+
mountStatic: () => {},
8+
resolveOrigin: () => 'http://localhost',
9+
getStorageDir: () => '',
10+
};
11+
const ctx = await createHostContext({ cwd: process.cwd(), mode: 'dev', host: host as never });
12+
await pangular.setup(ctx as never);
13+
const { tools, resources } = ctx.agent.list();
14+
15+
const oversizedTools: { id: string; len: number }[] = [];
16+
for (const tool of tools) {
17+
if (tool.description.length > 600) {
18+
oversizedTools.push({ id: tool.id, len: tool.description.length });
19+
}
20+
expect(
21+
tool.description.length,
22+
`Tool "${tool.id}" description is too short (${tool.description.length} chars)`,
23+
).toBeGreaterThanOrEqual(40);
24+
}
25+
26+
const oversizedResources: { id: string; len: number }[] = [];
27+
for (const resource of resources) {
28+
const desc = resource.description ?? '';
29+
if (desc.length > 600) {
30+
oversizedResources.push({ id: resource.id, len: desc.length });
31+
}
32+
expect(
33+
desc.length,
34+
`Resource "${resource.id}" description is too short (${desc.length} chars)`,
35+
).toBeGreaterThanOrEqual(40);
36+
}
37+
38+
expect(
39+
oversizedTools,
40+
`Found tools with description > 600 chars: ${JSON.stringify(oversizedTools)}`,
41+
).toEqual([]);
42+
43+
expect(
44+
oversizedResources,
45+
`Found resources with description > 600 chars: ${JSON.stringify(oversizedResources)}`,
46+
).toEqual([]);
47+
});

0 commit comments

Comments
 (0)