Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(request-tools): do not report out-of-surface tools as listed on stdio

garrytan2d1824d5a257
diff --git a/src/core/ops/request-tools.ts b/src/core/ops/request-tools.ts
index 1b6fa71b7a..8af112d2a2 100644
--- a/src/core/ops/request-tools.ts
+++ b/src/core/ops/request-tools.ts
@@ -346,8 +346,16 @@ const request_tools: Operation = {
const { resolveStrictParamsMode } = await import('../../mcp/validate-params.ts');
const strictParams = (await resolveStrictParamsMode(ctx.engine, ctx.config)) === 'reject';
if (ctx.revealTools) {
- ctx.revealTools(picked.map(o => o.name));
- return { tools: buildToolDefs(picked, { strictParams }), listed: true, note: 'These tools are now in your tool list (tools/list_changed was sent); call them directly.' };
+ // A widenable session's catalog reaches past what it serves; only tools it can call now are listed.
+ const callable = catalogCeiling === ceiling ? visibleSet : new Set((await visibleOpsForCaller(ctx, ceiling)).map(o => o.name));
+ const reachable = picked.filter(o => callable.has(o.name)).map(o => o.name);
+ const outside = picked.filter(o => !callable.has(o.name)).map(o => `\`${o.name}\``);
+ if (reachable.length) ctx.revealTools(reachable);
+ if (!outside.length) return { tools: buildToolDefs(picked, { strictParams }), listed: true, note: 'These tools are now in your tool list (tools/list_changed was sent); call them directly.' };
+ return {
+ tools: buildToolDefs(picked, { strictParams }), listed: false,
+ note: `${reachable.length ? `${reachable.map(n => `\`${n}\``).join(', ')} are now in your tool list (tools/list_changed was sent). ` : ''}${outside.join(', ')} are outside this session's '${ceiling}' surface, so they are not listed and cannot be called yet: call request_tools {"surface":"full"} to add them to this session, then call them by name.`,
+ };
}
return { tools: buildToolDefs(picked, { strictParams }) };
}
diff --git a/test/hidden-tool-hint.test.ts b/test/hidden-tool-hint.test.ts
index 182ecd1d77..ef1cf062b7 100644
--- a/test/hidden-tool-hint.test.ts
+++ b/test/hidden-tool-hint.test.ts
@@ -177,6 +177,30 @@ describe('D2 hidden-takes scenario, installed configurations', () => {
expect(await takesVisibleBy(widen.dispatchOpts)).toEqual([fenceTranscriptText('Renewal ARR forecast 1.2M', SLUG)]); // #8377: a stdio reader gets a claim below the owner's tier quoted
});
+ test('request_tools {tools} on a widenable starter session never claims a tool outside the surface is listed (#8733)', async () => {
+ const c = stdioConnection({ surface: 'starter' });
+ expect(c.session.allowedOps!.has('takes_list')).toBe(false);
+ const call = async (tools: string[]) => {
+ const r = await dispatchToolCall(engine, 'request_tools', { tools }, c.dispatchOpts());
+ expect(r.isError, r.content[0]?.text).toBeFalsy();
+ return JSON.parse(r.content[0].text) as { tools: Array<{ name: string }>; listed?: boolean; note: string };
+ };
+ const outside = await call(['takes_list']);
+ expect(outside.tools.map(t => t.name)).toEqual(['takes_list']);
+ expect(outside.listed).toBe(false);
+ expect(outside.note).toContain('request_tools {"surface":"full"}');
+ expect(c.reveals).toEqual([]);
+ const listedNames = async () => (await c.listing.listed(c.session.surfacedOps)).map(o => o.name);
+ expect(await listedNames()).not.toContain('takes_list');
+ const mixed = await call(['search', 'takes_list']);
+ expect(mixed.listed).toBe(false);
+ expect(mixed.note).toContain('`search`');
+ expect(mixed.note).toContain('`takes_list`');
+ expect(c.reveals).toEqual([['search']]);
+ const inside = await call(['search']);
+ expect(inside.listed).toBe(true);
+ });
+
test('full (callable and advertised): takes_list is listed, so no notice', async () => {
const c = stdioConnection({ surface: 'full' });
expect(hiddenNotice(await dispatchToolCall(engine, 'get_page', { slug: SLUG }, c.dispatchOpts()))).toBeUndefined();