From a7287fc7e90e421510ec23215532c6fd412e99df Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 23 Oct 2026 08:44:18 -0400 Subject: [PATCH] fix: Set every MCP tool annotation hint explicitly (#14263) * fix: Set every MCP tool annotation hint explicitly * fix: Mark create_document as open-world --- server/mcp/tools/attachments.ts | 2 ++ server/mcp/tools/collections.ts | 8 +++++++ server/mcp/tools/comments.ts | 8 +++++++ server/mcp/tools/documents.ts | 16 +++++++++++++ server/mcp/tools/fetch.ts | 2 ++ server/mcp/tools/revisions.ts | 2 ++ server/mcp/tools/templates.ts | 2 ++ server/mcp/tools/users.ts | 2 ++ server/routes/mcp/index.test.ts | 42 +++++++++++++++++++++++++++++++++ 9 files changed, 84 insertions(+) diff --git a/server/mcp/tools/attachments.ts b/server/mcp/tools/attachments.ts index d4ec992faa..5925563bb0 100644 --- a/server/mcp/tools/attachments.ts +++ b/server/mcp/tools/attachments.ts @@ -35,7 +35,9 @@ export function attachmentTools(server: McpServer, scopes: string[]) { description: "Requests a pre-signed upload URL. Use the returned uploadUrl and form fields to upload a file directly via a multipart POST request (e.g. with curl). The returned attachment URL is returned for use in documents.", annotations: { + destructiveHint: false, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ diff --git a/server/mcp/tools/collections.ts b/server/mcp/tools/collections.ts index 6b0c403046..c70ce382d3 100644 --- a/server/mcp/tools/collections.ts +++ b/server/mcp/tools/collections.ts @@ -54,7 +54,9 @@ export function collectionTools(server: McpServer, scopes: string[]) { description: "Lists all collections the authenticated user has access to. Returns a summary of each collection.", annotations: { + destructiveHint: false, idempotentHint: true, + openWorldHint: false, readOnlyHint: true, }, inputSchema: z.object({ @@ -175,7 +177,9 @@ export function collectionTools(server: McpServer, scopes: string[]) { description: "Creates a new collection. Collections are used to organize documents.", annotations: { + destructiveHint: false, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ @@ -236,7 +240,9 @@ export function collectionTools(server: McpServer, scopes: string[]) { description: "Updates an existing collection by its ID. Only the fields provided will be updated.", annotations: { + destructiveHint: true, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ @@ -323,7 +329,9 @@ export function collectionTools(server: McpServer, scopes: string[]) { description: "Deletes a collection by its ID. Non-archived documents within the collection will also be deleted. Set archive to true to archive the collection instead of deleting it.", annotations: { + destructiveHint: true, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ diff --git a/server/mcp/tools/comments.ts b/server/mcp/tools/comments.ts index 7cf41e30f2..8ac3d2ca56 100644 --- a/server/mcp/tools/comments.ts +++ b/server/mcp/tools/comments.ts @@ -55,7 +55,9 @@ export function commentTools(server: McpServer, scopes: string[]) { description: "Lists comments the user has access to. Requires at least one of documentId or collectionId. Optionally filter by parent comment or resolution status.", annotations: { + destructiveHint: false, idempotentHint: true, + openWorldHint: false, readOnlyHint: true, }, inputSchema: z.object({ @@ -150,7 +152,9 @@ export function commentTools(server: McpServer, scopes: string[]) { description: "Creates a new comment on a document. Provide the comment content as markdown text. Optionally nest it as a reply under an existing comment.", annotations: { + destructiveHint: false, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ @@ -268,7 +272,9 @@ export function commentTools(server: McpServer, scopes: string[]) { description: "Updates an existing comment by its ID. Can update the text content, resolve or unresolve the comment thread, or both. Only top-level comments (not replies) can be resolved or unresolved.", annotations: { + destructiveHint: true, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ @@ -352,7 +358,9 @@ export function commentTools(server: McpServer, scopes: string[]) { description: "Deletes a comment by its ID. The user must be the comment author or a team admin.", annotations: { + destructiveHint: true, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ diff --git a/server/mcp/tools/documents.ts b/server/mcp/tools/documents.ts index 8305c3220f..48b9a6f76f 100644 --- a/server/mcp/tools/documents.ts +++ b/server/mcp/tools/documents.ts @@ -77,7 +77,9 @@ export function documentTools(server: McpServer, scopes: string[]) { description: "Searches documents the user has access to. Performs full-text search across document content when a query is provided, or lists recent documents when no query is given. Archived documents are excluded unless includeArchived is set. Optionally filter by collection. To retrieve the full contents or hierarchy of a specific collection, use list_collection_documents instead.", annotations: { + destructiveHint: false, idempotentHint: true, + openWorldHint: false, readOnlyHint: true, }, inputSchema: z.object({ @@ -326,7 +328,9 @@ export function documentTools(server: McpServer, scopes: string[]) { description: "Returns the complete hierarchical tree of published documents in a collection, including nested sub-documents. Use this to enumerate every document in a collection or to understand parent/child relationships. Drafts and archived documents are not included.", annotations: { + destructiveHint: false, idempotentHint: true, + openWorldHint: false, readOnlyHint: true, }, inputSchema: z.object({ @@ -371,7 +375,11 @@ export function documentTools(server: McpServer, scopes: string[]) { title: "Create document", description: `Creates a new document from markdown or HTML content. Requires a collectionId to place the document in a collection, or parentDocumentId to nest it under an existing document. Use the collectionId "${PersonalCollectionId}" to place the document in the user's personal collection, which only they can see and which is created if it does not exist yet. Pass a templateId (from list_templates) to pre-fill the document from a template; the template's content is used unless text is also provided.`, annotations: { + destructiveHint: false, idempotentHint: false, + + // HTML imports download remote images and videos. + openWorldHint: true, readOnlyHint: false, }, inputSchema: z.object({ @@ -512,7 +520,9 @@ export function documentTools(server: McpServer, scopes: string[]) { description: "Moves a document to a different location or reorders it within its current parent. Provide a collectionId to move to the root of a collection, a parentDocumentId to nest under another document, and/or an index to control position among siblings.", annotations: { + destructiveHint: false, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ @@ -624,7 +634,9 @@ export function documentTools(server: McpServer, scopes: string[]) { description: 'Updates an existing document by its ID. Only the fields provided will be updated. IMPORTANT: When editing an existing document\'s content, always prefer editMode "patch" with findText and text — this surgically replaces only the matched section and preserves all rich formatting (highlights, comments, table widths, etc) in the rest of the document. Using "replace" will overwrite the entire document and lose any formatting that cannot be represented in markdown.', annotations: { + destructiveHint: true, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ @@ -790,7 +802,9 @@ export function documentTools(server: McpServer, scopes: string[]) { description: "Deletes a document by its ID. The document is moved to the trash and can be restored later. Set archive to true to archive the document instead of deleting it.", annotations: { + destructiveHint: true, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ @@ -860,7 +874,9 @@ export function documentTools(server: McpServer, scopes: string[]) { description: "Restores an archived or trashed document, making it active again. Optionally provide a collectionId to restore the document into a different collection; otherwise it returns to its original collection.", annotations: { + destructiveHint: false, idempotentHint: false, + openWorldHint: false, readOnlyHint: false, }, inputSchema: z.object({ diff --git a/server/mcp/tools/fetch.ts b/server/mcp/tools/fetch.ts index e62af5fc97..6f0897e3c9 100644 --- a/server/mcp/tools/fetch.ts +++ b/server/mcp/tools/fetch.ts @@ -103,7 +103,9 @@ export function fetchTool(server: McpServer, scopes: string[]) { description: 'Fetches a document, collection, user, attachment, or template by type and ID. When fetching a collection the response includes the full hierarchical document tree. For users, "current_user" can be used as the ID to get the authenticated user. For attachments, the response includes a short-lived signed URL that can be used to download the file contents directly. For templates, the response includes the template body as markdown.', annotations: { + destructiveHint: false, idempotentHint: true, + openWorldHint: false, readOnlyHint: true, }, inputSchema: z.object({ diff --git a/server/mcp/tools/revisions.ts b/server/mcp/tools/revisions.ts index 4a3af4cc95..7a2be245b1 100644 --- a/server/mcp/tools/revisions.ts +++ b/server/mcp/tools/revisions.ts @@ -37,7 +37,9 @@ export function revisionTools(server: McpServer, scopes: string[]) { title: "Get document changes", description: `Shows what changed in a document between two points in its history, and who changed it. Returns the revisions in the range with their authors, followed by a unified diff of the document markdown. Lines starting with "-" were removed and lines starting with "+" were added. Added and unchanged lines are verbatim markdown of the newer version, so when the range ends at the current document they can be used as findText with update_document in "patch" mode. Use this before editing a document that others may have changed, to review and merge their changes.`, annotations: { + destructiveHint: false, idempotentHint: true, + openWorldHint: false, readOnlyHint: true, }, inputSchema: { diff --git a/server/mcp/tools/templates.ts b/server/mcp/tools/templates.ts index 9a3c6feeec..148f66a886 100644 --- a/server/mcp/tools/templates.ts +++ b/server/mcp/tools/templates.ts @@ -54,7 +54,9 @@ export function templateTools(server: McpServer, scopes: string[]) { description: "Lists document templates the user has access to, including workspace-wide templates and templates within accessible collections. Each result includes the template body as markdown. To create a document from a template unchanged, pass its ID as templateId to create_document. To adapt it first, modify the returned text and pass it as the text parameter to create_document — no separate fetch is needed.", annotations: { + destructiveHint: false, idempotentHint: true, + openWorldHint: false, readOnlyHint: true, }, inputSchema: z.object({ diff --git a/server/mcp/tools/users.ts b/server/mcp/tools/users.ts index e270c57e0d..46a0954dd8 100644 --- a/server/mcp/tools/users.ts +++ b/server/mcp/tools/users.ts @@ -31,7 +31,9 @@ export function userTools(server: McpServer, scopes: string[]) { title: "List users", description: "Lists users in the workspace.", annotations: { + destructiveHint: false, idempotentHint: true, + openWorldHint: false, readOnlyHint: true, }, inputSchema: z.object({ diff --git a/server/routes/mcp/index.test.ts b/server/routes/mcp/index.test.ts index ec55bce762..6b79ab353e 100644 --- a/server/routes/mcp/index.test.ts +++ b/server/routes/mcp/index.test.ts @@ -235,6 +235,48 @@ describe("POST /mcp/", () => { expect(user.getFlag(UserFlag.MCP)).toEqual(1); }); + it("should set every annotation hint explicitly on every tool", async () => { + const { accessToken } = await buildOAuthUser(); + const { body } = mcpRequest("tools/list"); + const res = await server.post("/mcp/", { + headers: mcpHeaders(accessToken), + body, + }); + expect(res.status).toEqual(200); + + const parsed = await parseMcpResponse(res); + const result = parsed?.result as + | { + tools: { + name: string; + title?: string; + annotations?: Record; + }[]; + } + | undefined; + const tools = result?.tools ?? []; + const names = tools.map((tool) => tool.name); + expect(names).toContain("delete_collection"); + expect(names).toContain("delete_document"); + + for (const tool of tools) { + expect(tool.title, tool.name).toBeTruthy(); + expect(tool.annotations, tool.name).toEqual({ + destructiveHint: expect.any(Boolean), + idempotentHint: expect.any(Boolean), + openWorldHint: tool.name === "create_document", + readOnlyHint: expect.any(Boolean), + }); + + if (tool.annotations?.readOnlyHint) { + expect(tool.annotations.destructiveHint, tool.name).toBe(false); + } + if (/^(delete|update)_/.test(tool.name)) { + expect(tool.annotations?.destructiveHint, tool.name).toBe(true); + } + } + }); + it("should reject tool arguments with too many elements", async () => { const { accessToken } = await buildOAuthUser();