Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): keep Codex asking before it reads a note

Elian Dorancdb316f33d54
diff --git a/apps/server/src/services/llm/providers/acp_mcp_endpoint.spec.ts b/apps/server/src/services/llm/providers/acp_mcp_endpoint.spec.ts
index af6602bd7f..ce837388e1 100644
--- a/apps/server/src/services/llm/providers/acp_mcp_endpoint.spec.ts
+++ b/apps/server/src/services/llm/providers/acp_mcp_endpoint.spec.ts
@@ -185,6 +185,8 @@ describe("ACP MCP endpoint", () => {
expect(res.status).toBe(200);
expect(res.body).toContain("trilium-notes-spec");
+ // Codex runs a tool marked read-only without asking, which would skip the chat's approvals.
+ expect(createMcpServerMock).toHaveBeenCalledWith({ toolHints: false });
const mcpServer = mcpServers.at(-1);
await vi.waitFor(() => {
diff --git a/apps/server/src/services/llm/providers/acp_mcp_endpoint.ts b/apps/server/src/services/llm/providers/acp_mcp_endpoint.ts
index 09f59e834e..fd50049963 100644
--- a/apps/server/src/services/llm/providers/acp_mcp_endpoint.ts
+++ b/apps/server/src/services/llm/providers/acp_mcp_endpoint.ts
@@ -164,7 +164,7 @@ async function handleRequest(
}
// Stateless per-request server+transport, mirroring the public /mcp route.
- const mcpServer = await createMcpServer();
+ const mcpServer = await createMcpServer({ toolHints: false });
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: undefined,
enableDnsRebindingProtection: true,
diff --git a/apps/server/src/services/mcp/mcp_server.spec.ts b/apps/server/src/services/mcp/mcp_server.spec.ts
index 9d4960c134..d08d68246f 100644
--- a/apps/server/src/services/mcp/mcp_server.spec.ts
+++ b/apps/server/src/services/mcp/mcp_server.spec.ts
@@ -128,4 +128,11 @@ describe("tool annotations", () => {
expect(annotationsOf("add_tool")).toEqual({ readOnlyHint: false, destructiveHint: false, openWorldHint: false });
expect(annotationsOf("mutate_tool")).toEqual({ readOnlyHint: false, destructiveHint: true, openWorldHint: false });
});
+
+ it("leaves the hints out when asked to", async () => {
+ await createMcpServer({ toolHints: false });
+
+ expect(registered.map((r) => r.name)).toContain("read_tool");
+ expect(registered.map((r) => r.config.annotations)).toEqual(registered.map(() => undefined));
+ });
});
diff --git a/apps/server/src/services/mcp/mcp_server.ts b/apps/server/src/services/mcp/mcp_server.ts
index cf4eca73ab..07d28736c4 100644
--- a/apps/server/src/services/mcp/mcp_server.ts
+++ b/apps/server/src/services/mcp/mcp_server.ts
@@ -20,17 +20,18 @@ import sql from "../sql.js";
* Register a tool definition on the MCP server.
*
* Write operations are wrapped in CLS + transaction context so that
- * Becca entity tracking works correctly. The annotations tell the client which
- * tools only read and which overwrite or remove, so it can decide what to ask
- * the user about.
+ * Becca entity tracking works correctly. With `toolHints`, the annotations tell
+ * the client which tools only read and which overwrite or remove, so it can
+ * decide what to ask the user about.
*/
-function registerTool(server: McpServer, name: string, def: ToolDefinition) {
+function registerTool(server: McpServer, name: string, def: ToolDefinition, toolHints: boolean) {
+ const annotations = def.mutates
+ ? { readOnlyHint: false, destructiveHint: def.additive !== true, openWorldHint: false }
+ : { readOnlyHint: true, openWorldHint: false };
server.registerTool(name, {
description: def.description,
inputSchema: def.inputSchema,
- annotations: def.mutates
- ? { readOnlyHint: false, destructiveHint: def.additive !== true, openWorldHint: false }
- : { readOnlyHint: true, openWorldHint: false }
+ annotations: toolHints ? annotations : undefined
}, (args: any): CallToolResult => {
const result = cls.init(() => {
cls.set("componentId", "mcp");
@@ -46,7 +47,11 @@ function registerTool(server: McpServer, name: string, def: ToolDefinition) {
});
}
-export async function createMcpServer(): Promise<McpServer> {
+/**
+ * Build Trilium's MCP server. An in-chat agent's server sets `toolHints: false`: the chat's
+ * approvals decide its calls, and Codex runs a tool marked read-only without asking.
+ */
+export async function createMcpServer({ toolHints = true }: { toolHints?: boolean } = {}): Promise<McpServer> {
// Host-registered registries (the User Guide tools) load lazily; the array
// is complete only after this resolves.
await resolveToolRegistries();
@@ -58,7 +63,7 @@ export async function createMcpServer(): Promise<McpServer> {
for (const registry of allToolRegistries) {
for (const [name, def] of registry) {
- registerTool(server, name, def);
+ registerTool(server, name, def, toolHints);
}
}