Repository navigation
Add approved image attachment inputs for MCP tools - #10871
Merged
danielhanchen merged 73 commits intoOct 1, 2026
Merged
danielhanchen merged 73 commits into
danielhanchen merged 73 commits into
Conversation
…-encoded echoes, refuse durable runs, show the destination
# Conflicts: # studio/frontend/src/features/chat/chat-mcp-servers-dialog.tsx
# Conflicts: # studio/backend/core/inference/tools.py
…the account matrix
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.
Summary
Lets an MCP tool receive the image a user attaches in chat, without the image bytes ever entering the model's context. Typical use: a reverse image search server (for example trace.moe) driven by a text-only model.
How it works:
image_input_mappingson the server row (new nullable column, nothing to migrate).mcp_imageon the request.{"type": "string", "enum": ["attached_image"]}. A mapping whose field is no longer a top-level string after a server update is ignored, so the tool keeps its own schema."attached_image"in the mapped field always shows an approval card ("Share image once" / "Deny") in all three tool loops (GGUF, safetensors and external providers), whatever the permission mode, bypass included. The card names the server, tool, size and destination (host, or "local command " for stdio; never URL credentials or arguments). "Always allow" and the keyboard shortcut are not offered on that card.execute_toolswap the encoded image into a copy of the arguments, and only for the server configuration the card named: the row is re-read right before sending, and a server edited while the card was open (URL, headers, OAuth, mapping, or a dropped tool cache) gets an error instead. The fingerprint of that configuration never leaves the backend. An exact base64 or data URL echo of the image in the server's reply is replaced with[attached image]; a re-encoded copy (url-safe, hex, line-wrapped, JSON-escaped, percent-encoded, partial) withholds the whole reply from the model. Other results pass on as usual. Without an approved image the call returns an error asking the user to attach one.Calls without the placeholder, servers without mappings, and requests without
mcp_imagetake the existing paths unchanged.mcp_imageneedsstream=trueplusX-Unsloth-Events: 1, because the user has to be able to answer the approval card. Durable chat runs refuse it like other media, so the image is never persisted in a run's request. If the browser cannot read the MCP server list, the image is refused rather than sent to the model.Changes
core/inference/mcp_image.py: data URL validation (type, size, Pillow decode, format match), mapping lookup, schema rewrite, echo redaction.tools.py: rewritten schemas in the MCP listing and schema lookups,mcp_image_share()for the loops, insertion and redaction inexecute_tool.mcp_imagethrough and force the approval card.image_input_mappingson create/update/response, plusGET /api/mcp/servers/{id}/tools(cached tool schemas) for the field picker.modelVisibleMessagefiltering wherever request messages are built,mcp_imageon the request, approval card copy.Tests
tests/test_mcp_image.py: parsing, schema rewrite, insertion only with an approved image, redaction, ordinary path unchanged, safetensors loop asks even under bypass (allow and deny), route rejects non-interactive requests, mapping round trip, GGUF loop wiring.tests/test_studio_tool_loop.py: provider loop asks even under bypass and passes the image only for that call.frontend/tests/mcp-image.test.ts: tool-only filtering,mcp_imageextraction, mapping candidates.UI
MCP server edit form, merge base vs this PR. The same server is created on both sides with an
image_input_mappingsentry; the base drops the field, this PR stores it and shows the switch with the mapping row.Live run
Real Studio with
unsloth/Qwen3-8B-GGUF(Q4_K_M) and a local MCP server whoselookup(image)tool records what it receives. Permission mode was "Approve for me", and the card still asked. Nothing reached the server before the click; afterwards it received the exact attached bytes (sha256 match), and the model answered from the tool result.Same setup over the API: Deny sends nothing; an echoing tool returns
you sent [attached image]; editing the server while the card is open returns "the MCP server changed after the image was approved" and sends nothing; a call withoutmcp_imagegets "no approved image to send".