Suggested way to pass files from the client #1197
Replies: 8 comments 16 replies
-
|
Hey @nickwinder - thanks for reaching out, I'm on the anthropic team and this is something that I've been looking into recently, and want to figure out a good way to implement this sort of thing at the protocol level. I don't think you're overlooking anything, your use-case is currently finicky in the current state of the protocol. My initial thoughts/work have been about allowing MCP server tools to return "files" - basically a tool result content type that is not intended for the LLM's context window, but more for use in an conversation's workspace. For an example scenario, this is what I'd like to enable:
This effectively allows bespoke ETL style workflows to be done by the LLM using MCP (along with many other use cases). My thinking so far is to extend the tool result format to have a Some things that are top of mind here for me are:
|
Beta Was this translation helpful? Give feedback.
-
|
I started a related discussion in the Specification area here: #90 I think this is what the "Audience" annotation is for - But this doesn't quite answer how best to deal with the specific implementation (which could be Roots, Resource Templates, or custom handling). At the moment, the Client doesn't expose Resource Templates to the server; having a symmetrical approach might make sense for this case where the client can offer Metadata and Resource Identifiers that are made available to the server (and potentially scoped to a session). This feels cleaner than a shared file system via Roots. Another thing I'm finding is that I'm enjoying playing with MCP Servers and having Claude orchestrate them - but in a lot of cases once I've seen 2 clients working together, I don't necessarily need inference between them - some way of chaining them might be good. |
Beta Was this translation helpful? Give feedback.
-
|
@evalstate Any progress here? |
Beta Was this translation helpful? Give feedback.
-
|
I ran across the same challenge when implementing a PDF text extractor tool as an MCP tool. While this can all be done by having an external file location and passing file references to and from the tool, it is much more preferable from a security perspective to pass files to and from the tool directly. This is where I arrived at the same approach as @jerome3o-anthropic is suggesting, introducing a file return type: result = [types.FileContent(type="file", data=data, name='myresult.txt (optional)', mimeType='text/markdown)] The client then stores that file locally (in my case in a virtual file system inside the client's session). It then only loads the VFS file-id into LLM context. The LLM can now access the file or split it into chunks (depending on size) using additional client side tools. P.S: When initiating the tool call, I upload the file to the tool based on annotations in the tool description, which indicate which tool parameters are file-ids. My generic MCP client, upon detcting a tool invocation, first POSTs all the referenced files from its VFS to the MCP server (which has its own VFS, aka a session dictionary ;-). This post operation lives outside the MCP spec, so for my proprietary use case, no real protocol change is required in the upstream direction. Having an official upstream mechanism as well, however, would allow for cross-vendor tool compatibility, of course. I think a FileContent return type would make a great addition to the protocol. We are currently left either sequeezing multipart-mime into a text response or abusing the image response to pass non-image binary data, both of which is a hack. |
Beta Was this translation helpful? Give feedback.
-
|
That would be great, but won't most MCP clients reject the mimeType |
Beta Was this translation helpful? Give feedback.
-
|
Hi, this PR is related : #223 as a way to have Server's intelligently adapt content types based on what is tokenizable. I assume that everything which is text is "good" (although the Anthropic Messages API doesn't for example accept text/markdown as a document type - so juts send as text/plain). One other point on file transfer (not recommending this...) would be to have your Client respond to Sampling requests (e.g. parse the request and look for a resource name) and use the SamplingMessage to respond with your data. |
Beta Was this translation helpful? Give feedback.
-
|
I guess I have a similar issue of huge responses from an API and context size. https://github.com/orgs/modelcontextprotocol/discussions/272 |
Beta Was this translation helpful? Give feedback.
-
|
How can I handle large file transfers between an MCP server and client without exceeding token limits in LLM calls? I'm using the Model Context Protocol (MCP) for a file processing pipeline where: The process: I instruct the agent by providing a filename and URL.The agent invokes an MCP server tool that downloads and reads a large Excel file from the provided URL. The issue: Due to the file’s size, the JSON content is massive. The LLM (Azure OpenAI) throws a 400 Bad Request error stating: Content length is more than 128,000 tokens, but got around 1.95 million tokens. I’ve already tried:
But I still hit the token limit after processing 1–2 chunks, with Base64 still reaching around 1.12M tokens. What I need help with: Are there alternative strategies like:
What is the best approach to transfer large file content (like Excel data) using MCP, in a way that avoids hitting the token limit? |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Pre-submission Checklist
Question Category
Your Question
👋
I’m exploring ways to enable LLMs to process files using MCP servers. As a first step, the client needs to pass or report the file to the server for processing.
From the specification, I see two potential approaches:
Does anyone have suggestions for better ways to pass files from the client to the server for processing? Am I overlooking something fundamental in the protocol?
Beta Was this translation helpful? Give feedback.
All reactions