Skip to content

Commit b4fb22f

Browse files
committed
feat(mcp): trim tool and resource descriptions under 600 characters
Trim oversized agent tool and resource descriptions across devframe.ts and RPC handlers to stay under 600 characters, reducing token usage in LLM conversation contexts when listing tools. Refs #372
1 parent 832a5a8 commit b4fb22f

6 files changed

Lines changed: 69 additions & 22 deletions

File tree

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)