DEV Community

Daisuke Mino
Daisuke Mino

Posted on Originally published at minodisk.dev

Passing Files Between MCP Servers by Handle

A neatly wrapped parcel tied with string, a small paper tag hanging from the bow

Connecting AI to all kinds of services through MCP and having it do real work has become ordinary. Some of that work moves a file from one service to another: a PDF attached to an email goes into a cloud drive, a spreadsheet from the drive is attached to an email draft, a generated image goes into a chat channel.

MCP has no way to do that without the file passing through the model's context, and that causes three problems: the model can alter the file, the model sees the file's content, and the file costs tokens. This post describes what I built instead. The file goes into shared storage, the context carries only a short-lived handle (an opaque ID that points to the file), and the design handles each of the three problems.

Files ride in the context

In the MCP spec I designed against (2026-07-28), there is no interface for transferring files:

  • The content a tool returns is text, image, audio, a resource link or an embedded resource. There is no generic file type, and images and audio are base64.
  • Tool arguments are plain JSON. There is no binary type on the input side.
  • A resource link can return a URI, but the only way to resolve it is resources/read, which returns binary content as base64 again. There is no contract for the client to fetch the URI over HTTP.

So moving a file from one server to another means a tool on server A returns it as base64, the model reads it, and the model writes it back out as an argument to a tool on server B.

The MCP maintainers know this is a problem. An open issue says base64 in JSON-RPC will not scale for file content, and a File Uploads working group was started in April 2026. When I started in August, the leading proposal was SEP-2631 "File Objects and Transfer" (a SEP is a Specification Enhancement Proposal), which added files/authorizeUpload / files/authorizeDownload and mcp-file: URIs. It was still a draft, and it did not cover handing a file from one server to another: the host relays the bytes. SEP-2532 describes exactly this use case in its motivation, a client reading a PDF from one server and uploading it to another without the bytes entering the model's context, but it was open too. Nothing usable existed, so I built it.

Since then, SEP-2631 was closed in October in favor of an experimental extension maintained by the working group. It is not part of the spec and expects breaking changes. It reuses SEP-2631's file URIs and digests, lets a client upload a file's bytes out of band, and lets a tool return a file as a download target. Passing a file from one server's tool directly to another server is proposed but not merged as of November 2026, and the spec itself, still at 2026-07-28, has no file transfer.

Three problems

Integrity: the model can change the file

The bytes that reach server B are not a copy made by a program. They are text the model generated, character by character, from what it read. A model reproducing tens of thousands of characters of base64 can drop, repeat or alter some of them, and nothing in the path checks that the output matches the input. Worse, a common decoder doesn't notice. When I tried Node's Buffer.from(s, "base64"), it silently skipped characters that aren't valid base64 and returned a shorter result for a string cut short, without an error either way. A damaged string still decodes into a file, just not the same one.

This is not hypothetical. A user of redmine-mcp-server reported an agent base64-encoding a 3,232-byte PNG: the tool output showed the correct 4,312 characters, but the tool call carried 4,280. The string was still valid base64 and under the size limit, so every layer reported success and a corrupted file was stored.

For a contract someone will sign, or a spreadsheet full of numbers, a file that is almost the same is not good enough.

Security: the model sees the content

Contracts, bank statements, scanned IDs, private photos: much of what moves between these services is sensitive, and none of the tasks above require the model to read it. Once a file is in the context, it is in the transcript and in whatever the client logs, and its text becomes input the model acts on, including any instructions someone hid in it. The safest content is content the model never receives.

Cost: the file is paid for in tokens

A 100 KB PDF is about 34,000 tokens of base64, and it is paid twice, about 68,000 in total: once when the model reads it and once when the model writes it out. Large files don't fit at all, and even small ones make the conversation slow and crowd out the context the model needs for the actual task.

All three have the same cause, the bytes passing through the model, so they share one fix: the file moves between servers; the model only moves a reference to it.

Before: a parcel travels from service A through an MCP server, the model and another MCP server to service B. After: the MCP servers put the parcel in storage, and only its tag passes through the model

The shape: a handle and four roles

mcp-file:v1:<UUIDv4>
Enter fullscreen mode Exit fullscreen mode

The format borrows the mcp-file: prefix from SEP-2631, but it is my own string, not one of that proposal's URIs. A tool that has a file puts the bytes in object storage and returns this string. A tool that needs the file takes the string as an argument called fileHandle and reads the bytes from storage itself. The object in storage is the only record: there is no table mapping handles to objects, so there is nothing to keep consistent and nothing to clean up besides the objects.

Building on this takes two things. One is the shared part: the storage, the handle format, and a small library with put and get that every server uses. The other is, for each service, an MCP server whose tools move files in and out of that service. The official MCP servers I use have no such tools, so I run my own server for each of about a dozen services, alongside the official ones where they exist.

The tools that touch handles fall into four roles:

Role Name Does
stager <svc>_stage_<x> Fetches a file from a service, returns a handle
generator <svc>_generate_<x> Builds a file (an image, a CSV), returns a handle
deliverer <svc>_deliver_<x> Takes a handle, sends the file to a service
presenter <svc>_read_<x> Takes a handle, shows the content

One server can have tools in several roles: a cloud drive's server has both a stager that takes files out of the drive and a deliverer that saves files into it. Any stager or generator can feed any deliverer, because the handle looks the same no matter who made it.

The v1 is there so that I can move to whatever the file uploads extension becomes without breaking old handles.

The handle alone removes the bytes from the context. Each problem still needs more than that, because the model can still route around the handle, and the handle itself is a string the model holds. The next three sections go through them in order.

Integrity: the model never writes the bytes

For a file that comes from a service, every copy is made by a program: from the source service to storage by the stager, from storage to the destination by the deliverer. What the model writes is the handle, and it has to write that exactly. So the handle is kept opaque and the model is given no reason to touch it:

  • File name, MIME type and size are not encoded in the handle. The stager returns them next to it, so the model can read them without parsing the handle.
  • Every fileHandle argument carries the same short description: pass the value the stager or generator returned as it is, never build or edit one, and if it has expired, call that tool again.
  • A handle that doesn't match the strict UUIDv4 pattern is refused as invalid_handle, so a handle the model got wrong fails instead of resolving to something else.

Deliverers accept only fileHandle. They have no contentBase64 argument. I tried keeping one as a fallback, and the model uses it: given a base64 input and a handle input, it picks the one it already knows how to fill. Keeping base64 behind one tool, described below, also lets one description carry the "don't do this unless you must" warning.

The harder case is a file the model made itself, like a PDF it converted or a CSV it wrote. Exactly one server takes those in, a server of its own that isn't tied to any service. It has three tools, in order of preference:

  1. Execution environment that can make HTTP requests: the tool returns a handle and a signed URL, and the model PUTs the file there with curl. The bytes go from a file on disk to storage, never through the context. The handle is not valid until the PUT returns 200, and the signed URL carries a precondition that the object must not exist yet, so once the upload succeeds, nobody holding the URL can replace the file behind the handle.
  2. No execution environment, text content: pass the text as an argument.
  3. No execution environment, binary content: pass base64. Discouraged, and the description says why: the content goes through the context, and long base64 breaks while it is being generated.

The third route is where integrity is most at risk, so it checks the string's shape before decoding: only the standard alphabet, at most two = at the end, and a length that can't come from a string cut off midway. That catches stray characters and some truncation (a cut that leaves a length one past a multiple of four). It can't catch a dropped run of four characters, as in the redmine example, or a character swapped for another valid one, which is why this route comes last.

Files on the person's own machine have a fourth way in, one the model takes no part in: a web page on that same server where the person signs in and picks a file. As with a stager, the handle lasts an hour. The browser PUTs it to a signed URL, so the bytes go from their disk to storage without passing through the model or my servers. The model then calls a tool that lists the files the person has staged, newest first, and takes the handle from there; that is what "the file I just uploaded" resolves to. The page signs in with the same account as the MCP session, so the file lands under the same per-user prefix and only that person's session can see it. Attaching the file to the chat would put its content in the context; this way the model sees only a file name and a handle.

When I staged and delivered a 57,799-byte PDF attached to an email, the object in storage was 57,799 bytes, the same as the attachment, and the model wrote none of those bytes on the way.

Security: the model never sees the content

Stagers, generators and deliverers never put the content in the context. The presenter is the only role that does, for the times the model actually needs to read the file: extracting text, reading an image or a PDF. The presenter tools live on the same server that takes in the model's own files. That server also has a viewer, a web page that shows the file to the person rather than to the model. Because reading is its own tool, the model reads a file only when it calls one for that purpose, and the call shows up in the transcript and the server logs.

Keeping the content out of the context moves the question to the handle, which is in the transcript. So the handle has to be useless to anyone but its owner, and only for a short time.

Only the owner can use it

The object lives at:

u/<hash of the user's ID>/<uuid>
Enter fullscreen mode Exit fullscreen mode

The handle carries only the UUID. The server that resolves it rebuilds the u/<user>/ prefix from the authenticated user of the current request, never from anything the model passed in. That ID is not a value the user claims; it is the identifier the identity provider vouched for when the user signed in. If someone passes another person's handle, the prefix is built from the caller's ID, so the owner's object isn't found. The strict UUIDv4 pattern means ../ or a full path can't even be expressed. The UUID is v4, not a time-sortable ID, so the handle doesn't leak when it was made or in what order.

Only for a short time

Layer Value Role
Expiry check on read Set by the creating tool Refuse with expired
Storage lifecycle rule 1 day Actually delete the object

Fetch-then-deliver usually completes within minutes in one conversation, so stagers set one hour. Generated images set 24 hours, because people come back to them. The tool that consumes a handle may shorten that limit but never extend it. The lifecycle rule only works at day granularity, so the read-time check is what enforces the hour; I confirmed that an expired handle is refused while its object still exists. Soft delete (keeping deleted objects recoverable for a week) is turned off, since that would defeat the point for short-lived data.

Nothing leaks through errors

Raw error bodies from upstream APIs go into the server logs only. The model gets a fixed message, so an error can't carry part of a file or an internal path into the context.

Cost: the context carries a few dozen characters

The same 57,799-byte PDF, in tokens:

Tokens in the context
base64 through the model about 20,000 each way
Stage, return value about 30
Stage + deliver, total about 100

The handle is the same size whether the file is 50 KB or 50 MB, so the gap only grows with larger files.

The remaining cost is turns: a model that takes a wrong path, or doesn't know how to recover, spends tokens on calls that go nowhere. Two things keep that down:

  • Errors say what to do next. Resolving a handle fails with one of invalid_handle, expired, not_found, forbidden or too_large, and each message tells the model its next step: call the stager again, or give up. Expiry and size are checked from the object's metadata before the body is read, so an oversized or stale file isn't transferred on the server side either.
  • The descriptions lead to the handle path. Nothing in the protocol says "this output becomes that input"; the only thing connecting a stager to a deliverer is the text of their descriptions. The stager doesn't list deliverers; it only says "pass this to a tool with a fileHandle argument", since a list would go stale every time a deliverer is added. The deliverer may name the stager, since it knows its own use case: a deliverer that saves to a drive says where an email attachment comes from, and what to tell the user if the server that stages it isn't connected, instead of falling back to base64.

Until the protocol catches up

In November 2026, Anthropic announced that Claude and Claude Code support this extension, and file transfers with connectors are rolling out in beta. A file now goes between Claude and a connector without entering the context. It covers only connectors listed in Claude's directory, though, not servers you add yourself, and it does not pass a file from one server to another.

When the file uploads extension, or whatever comes after it, can pass a file from one server to another, the storage and the handle can move to it. Until then, keeping the file's bytes away from the model was worth a bit of object storage and a string format.

Top comments (0)