Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Trim intent/locale and retrySafe boilerplate from tool schemas (#2508)

Regan Bellbc88a79838da
diff --git a/src/harness/agent-tools.ts b/src/harness/agent-tools.ts
index bfd921f9f..21ea81a89 100644
--- a/src/harness/agent-tools.ts
+++ b/src/harness/agent-tools.ts
@@ -4433,7 +4433,7 @@ const RETRY_SAFE_FIELD = "retrySafe";
const RETRY_SAFE_SCHEMA = Type.Optional(
Type.Boolean({
description:
- "true if re-running this exact call is harmless (reads, searches, idempotent writes) so the platform may re-run it after an interruption; false if it would duplicate a side effect (sending a message, charging, creating a record).",
+ "true if re-running this call is harmless (read or idempotent); false if it repeats a side effect like sending, charging or creating.",
}),
);
const RERUN_INPUT_MAX_CHARS = 4_000;
diff --git a/src/mcp/mcp-tool-service.ts b/src/mcp/mcp-tool-service.ts
index 1bb913db6..4b97e289c 100644
--- a/src/mcp/mcp-tool-service.ts
+++ b/src/mcp/mcp-tool-service.ts
@@ -15,6 +15,18 @@ import type { McpServer, McpServerStore } from "./mcp-server-store.ts";
const REFRESH_INTERVAL_MS = 5 * 60_000;
const MAX_RESULT_CHARS = 60_000;
+const DROPPED_OPTIONAL_PARAMS = ["intent", "locale"];
+
+function modelInputSchema(schema: Record<string, unknown>): Record<string, unknown> {
+ const properties = schema.properties;
+ if (!properties || typeof properties !== "object" || Array.isArray(properties)) return schema;
+ const required = new Set(Array.isArray(schema.required) ? schema.required : []);
+ const dropped = DROPPED_OPTIONAL_PARAMS.filter((name) => Object.hasOwn(properties, name) && !required.has(name));
+ if (!dropped.length) return schema;
+ const kept = { ...(properties as Record<string, unknown>) };
+ for (const name of dropped) delete kept[name];
+ return { ...schema, properties: kept };
+}
export function mcpPublicOAuthClients(servers: McpServer[]): PublicOAuthClient[] {
return servers.flatMap((s) =>
@@ -155,7 +167,7 @@ export function createMcpToolService(opts: {
serverId: server.id,
remoteName: tool.name,
description: tool.description || `${tool.name} on ${server.name}`,
- inputSchema: tool.inputSchema,
+ inputSchema: modelInputSchema(tool.inputSchema),
readOnly: server.readOnly,
});
}
diff --git a/test/mcp-connectors.test.ts b/test/mcp-connectors.test.ts
index 86f11b865..c92cb79fc 100644
--- a/test/mcp-connectors.test.ts
+++ b/test/mcp-connectors.test.ts
@@ -337,3 +337,48 @@ test("background MCP refresh contains registry failures at startup, on change, a
);
assert.equal(await service.call("crm_query", {}), "ran query");
});
+
+test("optional intent and locale parameters are left out of the schema the model sees, required ones are kept", async (t) => {
+ const store = createMcpServerStore(createMemoryMap<McpServer>());
+ const sent: Array<Record<string, unknown>> = [];
+ const mcp = await startMcpTestServer(t, {
+ tools: [
+ {
+ name: "search",
+ description: "Search",
+ inputSchema: {
+ type: "object",
+ properties: {
+ query: { type: "string" },
+ intent: { type: "string", description: "Why this call is made; logged for analytics." },
+ locale: { type: "string", description: "Language tag." },
+ },
+ required: ["query"],
+ },
+ },
+ {
+ name: "translate",
+ description: "Translate",
+ inputSchema: {
+ type: "object",
+ properties: { text: { type: "string" }, locale: { type: "string" } },
+ required: ["text", "locale"],
+ },
+ },
+ ],
+ call: (_name, args) => {
+ sent.push(args);
+ return { content: [{ type: "text", text: "ok" }] };
+ },
+ });
+ const service = createMcpToolService({ servers: store });
+ t.after(() => service.close());
+ await store.put(server({ url: `${mcp.url}/mcp` }));
+ await service.refresh();
+ const schemas = Object.fromEntries(service.toolDefs().map((d) => [d.name, d.inputSchema]));
+ assert.deepEqual(Object.keys(schemas.crm_search!.properties as object), ["query"]);
+ assert.deepEqual(schemas.crm_search!.required, ["query"]);
+ assert.deepEqual(Object.keys(schemas.crm_translate!.properties as object), ["text", "locale"]);
+ assert.equal(await service.call("crm_search", { query: "tacos" }), "ok");
+ assert.deepEqual(sent, [{ query: "tacos" }]);
+});