Repository navigation
[Proposal] Support user-scoped files generated by MCP tools #14366
geodanchev
started this conversation in
Feature Requests & Suggestions
Replies: 2 comments 10 replies
|
@geodanchev That looks great. Hopefully this will be acceptable and implemented on LibreChat side and I wouůd very much welcome a PR to the mcp server. |
3 replies
|
Hello ! I am interested by this feature, but not for the same scope : i would like to send those generated files to the sandbox, so analysis may continue with dedicated tools. It seems to me that currently any data sent to the codeapi sandbox needs to be first loaded in context window. This prevent real data analysis. Thank you for your work. |
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
I would like to propose native support for files generated by MCP tools.
The goal is to allow an MCP server to create a file on behalf of the current LibreChat user and return it as a native downloadable attachment in the conversation, similar to how generated files are presented in ChatGPT.
This would support files such as:
I already have a working prototype for this flow, but I would first like to confirm the preferred architecture and scope with the LibreChat maintainers before opening a pull request.
Current limitation
MCP tools can generate files, but there is currently no standardized way for an external MCP server to:
As a result, MCP integrations currently need to use workarounds such as:
These approaches do not provide consistent user isolation, storage, auditing, or attachment handling.
Proposed user experience
A user asks an MCP tool to create a document:
The MCP server generates the file and returns it to LibreChat.
LibreChat then displays:
The file should behave like any other LibreChat attachment:
Proposed flow
Generic MCP file artifact format
The MCP tool could return normalized file metadata after the file has been accepted by LibreChat.
Example:
{ "result": { "message": "Document created successfully.", "file": { "file_id": "uuid-string", "filename": "Report.xlsx", "mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "bytes": 12345, "source": "local" } } }Multiple files could be supported later:
{ "result": { "message": "Files created successfully.", "files": [ { "file_id": "uuid-1", "filename": "Report.docx", "mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "bytes": 12345 }, { "file_id": "uuid-2", "filename": "Data.xlsx", "mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "bytes": 45678 } ] } }The exact response format should follow the architecture preferred by the LibreChat maintainers.
User identity and ownership
LibreChat already supports passing user context to MCP servers through dynamic headers.
For example:
The generated file must be associated with the authenticated LibreChat user.
The implementation should not rely only on a user ID supplied as a normal MCP tool argument.
LibreChat should validate ownership when a file is:
Knowing a file ID should never be sufficient to access another user’s file.
Possible implementation approaches
I see several possible approaches.
Option A: Authenticated LibreChat upload endpoint
LibreChat exposes an internal service endpoint for trusted MCP servers.
Example:
The MCP server authenticates with LibreChat and uploads the generated file.
LibreChat then:
Option B: Short-lived scoped upload capability
When LibreChat invokes an MCP tool, it provides a short-lived upload URL or token.
The token could be scoped to:
This would avoid giving the MCP server a long-lived credential and would prevent it from selecting an arbitrary user.
Option C: MCP resource or artifact content
The MCP server returns the file as an MCP resource or binary content block, and LibreChat persists it through the existing artifact pipeline.
This may provide a more MCP-native implementation, but large binary payloads could make it less suitable for some files.
I would appreciate guidance on which approach best fits LibreChat’s architecture.
Message association
One implementation detail is that an MCP tool may finish before the corresponding assistant message has been saved.
LibreChat may therefore need a temporary attachment registry based on a message ID, tool-call ID, or request ID.
Possible lifecycle:
For multi-instance deployments, this may need a shared store rather than only an in-memory map.
Security requirements
The feature should include:
Storage compatibility
The feature should use LibreChat’s existing file-storage abstraction.
The MCP server should not need to know whether LibreChat stores files using:
The MCP server should transfer the file to LibreChat, and LibreChat should manage the final storage and authorization.
Relationship to existing requests
This proposal is related to existing discussions about generated Excel files and MCP file handling, but it addresses a specific missing flow:
For example:
Issue #8060 primarily covers:
This proposal covers the reverse direction:
Together, they would enable complete bidirectional file exchange:
Existing prototype
I already have a working prototype covering this use case for an MCP server that generates:
The prototype includes:
However, I do not want to open a large pull request before confirming whether the architecture is acceptable to the LibreChat maintainers.
The goal is to contribute a generic MCP file-artifact capability, not an integration tied to one specific document server.
Suggested initial scope
To keep the first implementation small and reviewable, the initial version could support:
Multiple files and additional response formats could be added later.
Questions for the maintainers
Could a maintainer confirm:
Is support for files generated by MCP tools acceptable in principle?
Should generated files be persisted as standard LibreChat file records?
Which transfer mechanism is preferred?
Would you prefer this as one complete pull request or as several smaller pull requests?
Is there an existing artifact or attachment abstraction that should be extended rather than introducing a new MCP-specific path?
Once the preferred architecture and initial scope are confirmed, I can adapt the existing implementation and prepare the pull request accordingly.
All reactions