From ffc809c5be5e25ee5a85c5d10ff175f19ea7630a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 15:00:54 +0000 Subject: [PATCH] Remove text field from list_documents tool response Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> --- server/routes/mcp/index.test.ts | 32 ++++++++++++++++++++++++++++++++ server/tools/documents.ts | 26 +++++++++++++++----------- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/server/routes/mcp/index.test.ts b/server/routes/mcp/index.test.ts index 62db324cbc..9a1cc0b5b7 100644 --- a/server/routes/mcp/index.test.ts +++ b/server/routes/mcp/index.test.ts @@ -228,8 +228,10 @@ describe("POST /mcp/", () => { const match = data.find((d: { id: string }) => d.id === document.id) as { url: string; + text?: string; }; expect(match.url).toMatch(/^https?:\/\//); + expect(match.text).toBeUndefined(); }); it("list_documents filters by collection", async () => { @@ -267,6 +269,36 @@ describe("POST /mcp/", () => { (d: { collectionId: string }) => d.collectionId === collection1.id ) ).toBe(true); + expect(data.every((d: { text?: string }) => d.text === undefined)).toBe( + true + ); + }); + + it("list_documents with query does not include text", async () => { + const { user, accessToken } = await buildOAuthUser(); + const collection = await buildCollection({ + teamId: user.teamId, + userId: user.id, + }); + await buildDocument({ + teamId: user.teamId, + userId: user.id, + collectionId: collection.id, + title: "Search Test Document", + text: "This is searchable content", + }); + + const res = await callMcpTool(server, accessToken, "list_documents", { + query: "searchable", + }); + const data = (res?.result?.content ?? []).map((c: { text: string }) => + JSON.parse(c.text) + ); + + expect(data.length).toBeGreaterThan(0); + expect(data.every((d: { text?: string }) => d.text === undefined)).toBe( + true + ); }); it("create_document creates in a collection", async () => { diff --git a/server/tools/documents.ts b/server/tools/documents.ts index b592ac3e99..411b46ef47 100644 --- a/server/tools/documents.ts +++ b/server/tools/documents.ts @@ -153,13 +153,15 @@ export function documentTools(server: McpServer, scopes: string[]) { const presented = await Promise.all( results.map(async (result) => { - const doc = pathToUrl( - user.team, - await presentDocument(undefined, result.document, { + const { text, ...attributes } = await presentDocument( + undefined, + result.document, + { includeData: false, includeText: false, - }) + } ); + const doc = pathToUrl(user.team, attributes); return { ...doc, context: result.context }; }) ); @@ -183,15 +185,17 @@ export function documentTools(server: McpServer, scopes: string[]) { }); const presented = await Promise.all( - documents.map(async (document) => - pathToUrl( - user.team, - await presentDocument(undefined, document, { + documents.map(async (document) => { + const { text, ...attributes } = await presentDocument( + undefined, + document, + { includeData: false, includeText: false, - }) - ) - ) + } + ); + return pathToUrl(user.team, attributes); + }) ); return success(presented); } catch (message) {