Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(mcp): traverse_graph hops is full-surface-only, so the starter list stays under 26,000

garrytanad05f18beed0
diff --git a/docs/guides/multi-hop.md b/docs/guides/multi-hop.md
index 6ff5f50978..d9e63a790a 100644
--- a/docs/guides/multi-hop.md
+++ b/docs/guides/multi-hop.md
@@ -58,7 +58,8 @@ written in: `object` walks subject → object (investor → company, person →
employer), `subject` walks object → subject (company → founder). Chain link
types: `founded`, `invested_in` (with `led_round`), `advises`, `works_at`,
`attended`, `yc_partner`. `hops` cannot be combined with `depth`, `link_type`
-or `direction`; up to 3 hops.
+or `direction`; up to 3 hops. MCP advertises `hops` on the full surface (the
+default); the starter surface leaves it out to stay inside its size budget.
## Try it keyless (about a minute)
diff --git a/docs/mcp/TOOL_REFERENCE.md b/docs/mcp/TOOL_REFERENCE.md
index 5daddbbc69..310065fd84 100644
--- a/docs/mcp/TOOL_REFERENCE.md
+++ b/docs/mcp/TOOL_REFERENCE.md
@@ -422,7 +422,7 @@ Traverse link graph from a page. Remote callers default to bidirectional edges (
| `depth` | number | Max traversal depth (capped at 10). Default 5, except a remote call that lets direction default to 'both' uses 2 (bidirectional path enumeration is combinatorial on hubs); an explicit depth is always honored up to the cap. |
| `link_type` | string | Filter to one link type (per-edge filter, traversal only follows matching edges) |
| `direction` | string (`in`, `out`, `both`) | Traversal direction ('in', 'out', or 'both'). Remote callers default to 'both'; trusted local no-filter callers get the legacy outgoing-node output. |
-| `hops` | array of `{link_type, toward}` | Typed chain of 1-3 hops from the start page, e.g. `[{"link_type":"invested_in","toward":"object"},{"link_type":"founded","toward":"subject"}]` (companies the person invested in, then their founders). `toward` follows the relationship's meaning (`object`: subject → object; `subject`: object → subject), not stored link direction. Returns `{anchor, answers, paths, diagnostics}` with each answer's evidence edges; a chain that finds nothing carries a `relational_chain` notice with the next call. Not combinable with `depth`, `link_type` or `direction`; each hop walks live relationships. Chain link types: founded, invested_in, led_round, advises, works_at, attended, yc_partner. See docs/guides/multi-hop.md. |
+| `hops` | array of `{link_type, toward}` | Typed chain of 1-3 hops from the start page, e.g. `[{"link_type":"invested_in","toward":"object"},{"link_type":"founded","toward":"subject"}]` (companies the person invested in, then their founders). `toward` follows the relationship's meaning (`object`: subject → object; `subject`: object → subject), not stored link direction. Returns `{anchor, answers, paths, diagnostics}` with each answer's evidence edges; a chain that finds nothing carries a `relational_chain` notice with the next call. Not combinable with `depth`, `link_type` or `direction`; each hop walks live relationships. Advertised on the full surface only. Chain link types: founded, invested_in, led_round, advises, works_at, attended, yc_partner. See docs/guides/multi-hop.md. |
| `source_id` | string | Scope the read to one source (a multi-source brain can hold the same slug in several sources). Omitted: your granted sources remotely (a connection with no grant reads every federated source); locally, the resolved source, or every federated source when no --source / GBRAIN_SOURCE / .gbrain-source pinned it. '__all__' spans every source for trusted local callers and only your readable sources for remote callers. |
| `all_sources` | boolean | Span sources (equivalent to source_id=__all__): every source locally, only your readable sources remotely. |
diff --git a/src/core/ops/contract.ts b/src/core/ops/contract.ts
index 547a12f24a..f5f3a4c492 100644
--- a/src/core/ops/contract.ts
+++ b/src/core/ops/contract.ts
@@ -229,6 +229,8 @@ export interface ParamDef {
items?: ParamDef;
/** Object members (O-DX-3); a member with `required: true` lands in the schema's `required`. */
properties?: Record<string, ParamDef>;
+ /** Advertised on the full MCP surface only (keeps the starter tool list inside its size budget). */
+ fullSurfaceOnly?: boolean;
}
export interface Logger {
diff --git a/src/core/ops/links.ts b/src/core/ops/links.ts
index a1538afbb7..738662784b 100644
--- a/src/core/ops/links.ts
+++ b/src/core/ops/links.ts
@@ -519,6 +519,7 @@ const traverse_graph: Operation = {
type: 'array',
description: '≤3 typed hops, e.g. [{"link_type":"founded","toward":"subject"}]; toward: object|subject.',
items: { type: 'object', properties: { link_type: { type: 'string' }, toward: { type: 'string' } } },
+ fullSurfaceOnly: true,
},
source_id: LINK_SOURCE_ID_PARAM,
all_sources: LINK_ALL_SOURCES_PARAM,
diff --git a/src/mcp/surface.ts b/src/mcp/surface.ts
index ec921ece9e..01bb1465fa 100644
--- a/src/mcp/surface.ts
+++ b/src/mcp/surface.ts
@@ -184,7 +184,13 @@ export function filterOpsForSurface(ops: Operation[], surface: McpSurface): Oper
// FROZEN: 'verbs' is EXACTLY `op.verb === true` (MEMORY_VERBS v1) — starter
// extends the ladder above it and must never alter these semantics.
if (surface === 'verbs') return ops.filter(op => op.verb === true);
- return ops.filter(op => STARTER_OPS.has(op.name));
+ return ops.filter(op => STARTER_OPS.has(op.name)).map(starterParams);
+}
+
+/** Starter ops advertise every param except the full-surface-only ones. */
+function starterParams(op: Operation): Operation {
+ if (!Object.values(op.params).some(p => p.fullSurfaceOnly)) return op;
+ return { ...op, params: Object.fromEntries(Object.entries(op.params).filter(([, p]) => !p.fullSurfaceOnly)) };
}
/** The fail-closed allow-set handed to dispatchToolCall. */
diff --git a/test/fixtures/goldens/exports/types.json b/test/fixtures/goldens/exports/types.json
index ed7389d446..1edb4a6bf0 100644
--- a/test/fixtures/goldens/exports/types.json
+++ b/test/fixtures/goldens/exports/types.json
@@ -5731,6 +5731,7 @@
"default?: unknown",
"description?: string | undefined",
"enum?: string[] | undefined",
+ "fullSurfaceOnly?: boolean | undefined",
"items?: ParamDef | undefined",
"properties?: Record<string, ParamDef> | undefined",
"required?: boolean | undefined",
diff --git a/test/mcp-schema-budget.test.ts b/test/mcp-schema-budget.test.ts
index 30175682f6..f1b31d27e8 100644
--- a/test/mcp-schema-budget.test.ts
+++ b/test/mcp-schema-budget.test.ts
@@ -40,8 +40,8 @@ import { cl100kAvailable, estimateTokens } from '../src/core/chunkers/token-esti
const SERVED_STARTER_MAX_CHARS = 25_000;
const SERVED_STARTER_MAX_TOKENS = 5_700;
-/** The whole tools/list JSON, annotations included (25,735 measured at v0.60.46.0; +279 for traverse_graph's optional `hops` typed-chain parameter, 26,220 measured with the temporal params on get_links/get_backlinks). */
-const SERVED_STARTER_MAX_JSON_CHARS = 26_250;
+/** The whole tools/list JSON, annotations included (25,735 measured at v0.60.46.0; traverse_graph's `hops` is full-surface-only, 25,941 measured). */
+const SERVED_STARTER_MAX_JSON_CHARS = 26_000;
/** 4,042 at the cost wave + 586 for the operator contract's error protocol, notice prefix and memory loop (F1); no schema guidance moved here. */
const INSTRUCTIONS_MAX_CHARS = 4_628;
const DESCRIPTION_HARD_CAP = 1_200;
@@ -55,7 +55,7 @@ const TOOL_BUDGETS: Record<string, number> = {
get_skill_asset: 790, get_write_request: 330, join_brain: 560, leave_brain: 540, list_brain_skillpack: 230,
list_link_sources: 220, list_pages: 1090, list_skills: 670, list_write_requests: 450, put_page: 1320,
put_skill: 1420, query: 3250, recall: 1590, remember: 1370, request_tools: 560, resolve_slugs: 410, search: 1760,
- submit_agent: 750, sync_brain_skills: 770, synthesize: 550, traverse_graph: 960, whoami: 230,
+ submit_agent: 750, sync_brain_skills: 770, synthesize: 550, traverse_graph: 810, whoami: 230,
};
/** DX-14: phrases each tool's description must keep. */
@@ -138,7 +138,7 @@ describe('per-tool schema budgets', () => {
expect(starter.map(o => o.name).sort()).toEqual(Object.keys(TOOL_BUDGETS).sort());
});
- for (const op of operations.filter(o => STARTER_OPS.has(o.name))) {
+ for (const op of filterOpsForSurface(operations, 'starter')) {
test(`${op.name} fits its budget and the hard caps`, () => {
const [def] = buildToolDefs([op]);
expect(JSON.stringify(def).length).toBeLessThanOrEqual(TOOL_BUDGETS[op.name]);
diff --git a/test/traverse-graph-hops.test.ts b/test/traverse-graph-hops.test.ts
index d2c953a496..d921bd6a33 100644
--- a/test/traverse-graph-hops.test.ts
+++ b/test/traverse-graph-hops.test.ts
@@ -12,7 +12,8 @@
*/
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
-import { operationsByName, type AuthInfo, type OperationContext } from '../src/core/operations.ts';
+import { operations, operationsByName, type AuthInfo, type OperationContext } from '../src/core/operations.ts';
+import { filterOpsForSurface } from '../src/mcp/surface.ts';
import { dispatchToolCall, type DispatchOpts } from '../src/mcp/dispatch.ts';
import type { Notice } from '../src/core/agent-output.ts';
import { buildRelationalArm } from '../src/core/search/relational-recall.ts';
@@ -106,6 +107,13 @@ describe('traverse_graph hops', () => {
expect(notices.pop()).toMatchObject({ fix: { mcp: { tool: 'traverse_graph', arguments: { hops: [HOPS[0]] } } } });
});
+ test('hops is advertised on the full surface only; the starter list stays inside its budget', () => {
+ const on = (surface: 'full' | 'starter') => filterOpsForSurface(operations, surface).find(o => o.name === 'traverse_graph')!.params;
+ expect(on('full')).toHaveProperty('hops');
+ expect(on('starter')).not.toHaveProperty('hops');
+ expect(on('starter')).toHaveProperty('depth');
+ });
+
test('without hops the op keeps its existing shape', async () => {
const res = await runLocal({ slug: 'people/alice-example', link_type: 'invested_in', direction: 'out' });
expect(Array.isArray(res)).toBe(true);