Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Read the text an MCP server returns as an embedded resource (#597)
kevin06fb1160c441
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9e6988fa..9122c45f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,15 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### A Bot reads the text an MCP server returns as an embedded resource++A tool result can carry an embedded resource, and a text resource holds content, such as a file the+server read. The MCP connector passed text parts to the Bot and named every other part, so a text+resource reached the model as `[resource]` and its contents were dropped. GitHub's MCP server answers+`get_file_contents` for a text file this way: the Bot was told the download worked and never saw the+file. The text of an embedded resource is now passed on like a text part. A resource that carries+bytes is still named.+### The Google Drive connector reaches files in shared drivesDrive leaves shared drive items out of any `files.get` or `files.list` request that does not say itdiff --git a/server/src/plugins/mcp.ts b/server/src/plugins/mcp.tsindex b7f860fa..76da2e9c 100644--- a/server/src/plugins/mcp.ts+++ b/server/src/plugins/mcp.ts@@ -52,10 +52,20 @@ export function resultText(content: unknown): {const joined = parts.map((part) => {if (!part || typeof part !== "object") return "[unknown]";- const item = part as { type?: string; text?: string };+ const item = part as {+ type?: string;+ text?: string;+ resource?: { text?: unknown } | null;+ };if (item.type === "text" && typeof item.text === "string") {return item.text;}+ // An embedded resource with text in it is text, and often the answer itself: GitHub's MCP+ // server returns a file it read as one, beside a line saying the download worked. A resource+ // carrying bytes (`blob`) has no text to read and is named below like any other part.+ if (item.type === "resource" && typeof item.resource?.text === "string") {+ return item.resource.text;+ }// A non-text part is named rather than dropped. A model told "[image]" can say the tool// returned an image; a model handed nothing concludes the tool returned nothing.return `[${item.type ?? "unknown"}]`;diff --git a/server/tests/mcp-result.test.ts b/server/tests/mcp-result.test.tsindex 60467486..e18f494f 100644--- a/server/tests/mcp-result.test.ts+++ b/server/tests/mcp-result.test.ts@@ -63,6 +63,45 @@ describe("a result with something in it", () => {expect(resultText([{}]).text).toBe("[unknown]");});+ test("reads the text of an embedded resource, as a server returns a file it read", () => {+ // The shape GitHub's MCP server answers `get_file_contents` with for a text file: a line saying+ // the download worked, then the file itself as an embedded resource. Named as "[resource]", the+ // model was told the file arrived and never shown what was in it.+ expect(+ resultText([+ { type: "text", text: "successfully downloaded text file (SHA: abc)" },+ {+ type: "resource",+ resource: {+ uri: "repo://octo/docs/contents/README.md",+ mimeType: "text/markdown",+ text: "# Expense policy\n\nMeals under $75 need no receipt.",+ },+ },+ ]).text,+ ).toBe(+ "successfully downloaded text file (SHA: abc)\n# Expense policy\n\nMeals under $75 need no receipt.",+ );+ });++ test("still names an embedded resource that carries bytes rather than text", () => {+ expect(+ resultText([+ {+ type: "resource",+ resource: {+ uri: "file:///logo.png",+ mimeType: "image/png",+ blob: "iVBORw0KGgo=",+ },+ },+ ]).text,+ ).toBe("[resource]");+ expect(resultText([{ type: "resource", resource: null }]).text).toBe(+ "[resource]",+ );+ });+test("names a null or non-object part rather than throwing", () => {// Content arrives from a vendor's server; a null entry must not throw.expect(resultText([null]).text).toBe("[unknown]");