feat: Display images from MCP tool call results in chat#5273
Closed
angelplusultra wants to merge 4 commits intomasterfrom
Closed
feat: Display images from MCP tool call results in chat#5273angelplusultra wants to merge 4 commits intomasterfrom
angelplusultra wants to merge 4 commits intomasterfrom
Conversation
shatfield4
requested changes
Mar 27, 2026
Collaborator
shatfield4
left a comment
There was a problem hiding this comment.
Functional and works as it should, small refactor suggestion to image logic.
db2cf91 to
2252c37
Compare
Member
|
Closing this because:
Can be done with the framework and events from #5280 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Relevant Issues
resolves #4990
Description
MCP tools (Grafana, Tableau, etc.) can return images in their tool call results following the MCP spec. Previously, these images were either lost, displayed as raw base64 text, or shown as broken image icons because
returnMCPResult()would JSON-stringify the entire result including image data.This PR adds support for rendering images from MCP tool results inline in the chat. It handles all three MCP content types that can carry images:
type: "image"— inline base64-encoded image withdata+mimeTypetype: "resource_link"— URI pointing to a remotely hosted imagetype: "resource"— embedded resource with ablob(base64) oruriHow it works:
extractImageContent()checks thecontentarray for image items[1 image(s) returned by this tool and displayed to the user]_replySpecialAttributespattern asrechartVisualize, so they survive page reloadsMCPImageContentcomponent renders the images inline with a download buttonFiles changed:
server/utils/MCP/index.jsfrontend/src/utils/chat/agent.jsmcpImageContentwebsocket eventfrontend/src/components/.../ChatHistory/index.jsxmcpImageContenttype to new componentfrontend/src/components/.../ChatHistory/MCPImageContent/index.jsxVisuals (if applicable)
Testing
To test this feature, create a test MCP server file (e.g.
server/mcp-test.js) with three tools covering all image content types:mcp-test.js (click to expand)
Then add it to
server/storage/plugins/anythingllm_mcp_servers.json:{ "mcpServers": { "test-image": { "command": "node", "args": ["/absolute/path/to/mcp-test.js"] } } }Open an agent-enabled workspace and test each tool:
Also verify:
Additional Information
This follows the same architectural pattern as
rechartVisualize— non-text content is sent directly to the frontend via websocket and persisted using_replySpecialAttributes, keeping large payloads out of the LLM context window.Developer Validations
yarn lintfrom the root of the repo & committed changes