Compare commits

..

2 Commits

Author SHA1 Message Date
bbd31883e8 Merge pull request 'fix(mcplocal): wire-form tool names in gate and favourite-index prose' (#125) from fix/wire-safe-prose into main
Some checks failed
CI/CD / typecheck (push) Successful in 1m25s
CI/CD / lint (push) Successful in 2m40s
CI/CD / test (push) Successful in 1m30s
CI/CD / smoke (push) Has been cancelled
CI/CD / build (push) Has been cancelled
CI/CD / publish (push) Has been cancelled
2026-08-25 20:59:00 +00:00
Michal
c014fcdd82 fix(mcplocal): name tools in wire form in gate and favourite-index prose
Some checks failed
CI/CD / typecheck (pull_request) Successful in 1m24s
CI/CD / lint (pull_request) Successful in 2m34s
CI/CD / test (pull_request) Successful in 1m44s
CI/CD / smoke (pull_request) Failing after 3m18s
CI/CD / build (pull_request) Successful in 2m30s
CI/CD / publish (pull_request) Has been skipped
Follow-up to #124: the boundary WireNameCodec serves underscore-joined
names, but the gate plugin's tool inventories (initialize instructions and
begin_session response) still listed canonical `server/tool`, and the
favourite-index instruction told the model to prefer `favourite/<tool>` —
prose naming functions the model cannot call. Inventories now run through
sanitizeWireName and the instruction describes the favourite_/all_ prefixes.

Cosmetic for routing (slash names still pass through the codec) but
load-bearing for tool selection: models copy names out of prose.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JaFvfHrQyUKCGv6o3N2Wir
2026-08-25 21:58:52 +01:00
3 changed files with 30 additions and 12 deletions

View File

@@ -26,12 +26,21 @@ import type { ToolDefinition } from '../types.js';
/** Per-session state key holding the presented-name → canonical-name map. */
const RESOLVER_KEY = 'favourite-index:resolver';
/** The load-bearing "prefer favourite/" instruction (see module doc). */
/**
* The load-bearing "prefer favourite" instruction (see module doc).
*
* Phrased in the WIRE form (underscore-joined): the HTTP boundary's
* WireNameCodec rewrites the presented `favourite/<tool>` and
* `all/<server>/<tool>` names to `favourite_<tool>` / `all_<server>_<tool>`
* before any client sees them, so prose naming the slash form would tell the
* model to call names that are not in its function list.
*/
export const FAVOURITE_INDEX_INSTRUCTION =
'Tools are indexed in two namespaces. PREFER favourite/<tool> — a short ' +
'curated list of the common tools that covers most tasks; reach for these ' +
'first. Use the full catalog under all/<server>/<tool> only if nothing in ' +
"favourites fits. (read_prompts gives this project's own guidance.)";
'Tools are indexed in two namespaces. PREFER the favourite_-prefixed tools ' +
'— a short curated list of the common tools that covers most tasks; reach ' +
'for these first. Use the full catalog under the all_-prefixed names only ' +
"if nothing in favourites fits. (read_prompts gives this project's own " +
'guidance.)';
export interface FavouriteIndexConfig {
/** Canonical `server/tool` names to surface as favourites, in display order. */

View File

@@ -16,6 +16,7 @@ import type { TagMatchResult } from '../../gate/tag-matcher.js';
import { LlmPromptSelector, pickCompletionText, type ServerInfer } from '../../gate/llm-selector.js';
import type { ProviderRegistry } from '../../providers/registry.js';
import { withTimeout, TimeoutError } from '../../util/with-timeout.js';
import { sanitizeWireName } from '../../util/wire-names.js';
/** Cap on the gate's LLM prompt-selection. A slow/thinking LLM must never block
* begin_session — on timeout we fall back to deterministic tag matching. */
@@ -115,13 +116,15 @@ export function createGatePlugin(config: GatePluginConfig = {}): ProxyModelPlugi
);
parts.push(`\n${gateInstructions}`);
// Append tool inventory (names only)
// Append tool inventory (names only). Sanitized to the wire charset:
// the boundary WireNameCodec serves `server_tool`, so prose listing the
// canonical `server/tool` would name functions the model cannot call.
try {
const tools = await ctx.discoverTools();
if (tools.length > 0) {
parts.push('\nAvailable MCP server tools (accessible after begin_session):');
for (const t of tools) {
parts.push(` ${t.name}`);
parts.push(` ${sanitizeWireName(t.name)}`);
}
}
} catch {
@@ -424,13 +427,14 @@ async function handleBeginSession(
);
responseParts.push(encouragement);
// Append tool inventory (names only)
// Append tool inventory (names only) — wire charset, see the initialize
// inventory note.
try {
const tools = await ctx.discoverTools();
if (tools.length > 0) {
responseParts.push('\nAvailable MCP server tools:');
for (const t of tools) {
responseParts.push(` ${t.name}`);
responseParts.push(` ${sanitizeWireName(t.name)}`);
}
}
} catch {

View File

@@ -525,8 +525,11 @@ describe('McpRouter gating', () => {
);
const result = res.result as { instructions: string };
expect(result.instructions).toContain('ha/get_entities');
expect(result.instructions).toContain('node-red/get_flows');
// Wire form: prose must name what the client can actually call — the
// boundary WireNameCodec serves underscore-joined names.
expect(result.instructions).toContain('ha_get_entities');
expect(result.instructions).toContain('node-red_get_flows');
expect(result.instructions).not.toContain('ha/get_entities');
expect(result.instructions).toContain('after begin_session');
// Descriptions should NOT be in init instructions (names only)
expect(result.instructions).not.toContain('Get all entities');
@@ -544,7 +547,9 @@ describe('McpRouter gating', () => {
);
const text = (res.result as { content: Array<{ text: string }> }).content[0]!.text;
expect(text).toContain('ha/get_entities');
// Wire form in the inventory (see the initialize-instructions test).
expect(text).toContain('ha_get_entities');
expect(text).not.toContain('ha/get_entities');
expect(text).not.toContain('Get all entities');
});