Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): name Antigravity's note-tool calls after the tool

Elian Doran85a2f4880418
diff --git a/apps/server/src/services/llm/providers/acp_agent.ts b/apps/server/src/services/llm/providers/acp_agent.ts
index 01561aa023..9825445fe2 100644
--- a/apps/server/src/services/llm/providers/acp_agent.ts
+++ b/apps/server/src/services/llm/providers/acp_agent.ts
@@ -614,13 +614,14 @@ export function createUpdateCollector(emit: (chunk: LlmStreamChunk) => void) {
if (!update.toolCallId || toolNamesById.has(update.toolCallId)) {
break; // malformed or a re-announcement of a known call
}
- const toolName = update.title || "tool";
+ const mcpTool = mcpToolName(update._meta);
+ const toolName = mcpTool ?? (update.title || "tool");
toolNamesById.set(update.toolCallId, toolName);
emit({
type: "tool_use",
toolCallId: update.toolCallId,
toolName,
- toolInput: (update.rawInput ?? {}) as Record<string, unknown>
+ toolInput: (mcpTool ? unwrapMcpArguments(update.rawInput) : update.rawInput ?? {}) as Record<string, unknown>
});
break;
}
@@ -751,6 +752,22 @@ function wrapSystemInstructions(systemPrompt: string): string | null {
return `<system_instructions>\n${systemPrompt}\n</system_instructions>`;
}
+/**
+ * The MCP tool behind a tool call, from the `_meta` that `agy_acp_server` sets on
+ * calls to a client-provided MCP server. The call's title is `<server>_<tool>`,
+ * which matches none of the tool labels the chat has.
+ */
+function mcpToolName(meta: unknown): string | undefined {
+ const typed = meta as { is_mcp_tool_call?: unknown; mcp?: { tool?: unknown } } | undefined;
+ return typed?.is_mcp_tool_call === true && typeof typed.mcp?.tool === "string" ? typed.mcp.tool : undefined;
+}
+
+/** An MCP call's arguments, which `agy_acp_server` reports wrapped as `{ arguments: … }`. */
+function unwrapMcpArguments(rawInput: unknown): unknown {
+ const wrapped = rawInput as { arguments?: unknown } | undefined;
+ return wrapped && typeof wrapped.arguments === "object" && wrapped.arguments !== null ? wrapped.arguments : rawInput ?? {};
+}
+
/** Pull the text out of an update's content block (nested for tool contents). */
function extractText(content: unknown): string {
if (!content || typeof content !== "object") {
diff --git a/apps/server/src/services/llm/providers/antigravity_agent.spec.ts b/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
index e6fca4353d..98539443cf 100644
--- a/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
+++ b/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
@@ -70,7 +70,7 @@ class FakeAcpClient {
vi.mock("./acp_client.js", () => ({ AcpClient: FakeAcpClient, AcpError: FakeAcpError }));
-const { resetAcpAgentStateForTests } = await import("./acp_agent.js");
+const { createUpdateCollector, resetAcpAgentStateForTests } = await import("./acp_agent.js");
const { AntigravityAgentProvider, buildAntigravityEnv, buildAntigravityModelList, decideAntigravityPermission } = await import("./antigravity_agent.js");
const { parseBuildLabel } = await vi.importActual<typeof import("./antigravity_binary.js")>("./antigravity_binary.js");
@@ -189,6 +189,33 @@ describe("AntigravityAgentProvider", () => {
});
});
+describe("tool call updates from agy_acp_server", () => {
+ it("names an MCP tool call after the tool and unwraps its arguments", () => {
+ const chunks: LlmStreamChunk[] = [];
+ const collector = createUpdateCollector(chunk => chunks.push(chunk));
+ const meta = { mcp: { tool: "search_icons", server: "trilium" }, is_mcp_tool_call: true };
+ collector.onNotification("session/update", {
+ sessionId: "sess-1",
+ update: {
+ sessionUpdate: "tool_call", toolCallId: "f6b5", title: "trilium_search_icons", kind: "other", status: "pending",
+ content: [], rawInput: { arguments: { query: "font" } }, _meta: meta
+ }
+ });
+ collector.onNotification("session/update", {
+ sessionId: "sess-1",
+ update: {
+ sessionUpdate: "tool_call_update", toolCallId: "f6b5", status: "completed",
+ content: [{ content: { text: "Search for icons", type: "text" }, type: "content" }], rawOutput: "Search for icons"
+ }
+ });
+
+ expect(chunks).toEqual([
+ { type: "tool_use", toolCallId: "f6b5", toolName: "search_icons", toolInput: { query: "font" } },
+ { type: "tool_result", toolCallId: "f6b5", toolName: "search_icons", result: "Search for icons", isError: false }
+ ]);
+ });
+});
+
describe("buildAntigravityModelList", () => {
it("leads with the server's own default and keeps the server's order and names", () => {
expect(buildAntigravityModelList({ availableModels: [{ modelId: "gemini-x" }, { modelId: "default" }, { modelId: "" }] })).toEqual([