What features would you like to see added?
Summary:
Introduce a new MCP integration mode in LibreChat that represents MCP servers as a filesystem of TypeScript code modules, enabling the agent to dynamically explore available servers and selectively load only the specific tool modules needed for each task. This approach will drastically reduce token usage, improve scalability, and unlock more efficient and flexible agent workflows by leveraging the agent's native code generation strengths.
Background:
Anthropic and Cloudflare have introduced a novel "code execution with MCP" approach where each MCP server is exposed as a folder of TypeScript files (one per tool). The AI agent writes executable code to import and invoke these modules directly within a sandboxed environment. This design minimizes context token bloat by loading only necessary tools and pushing control flow operations (loops, conditionals) into native code rather than context. It also enhances data privacy by keeping intermediate results in the execution environment.
Goals:
Generate a virtual filesystem that mirrors all configured MCP servers and exposes each tool as an isolated TypeScript file.
Enable the agent to browse this filesystem dynamically during execution to discover and import only required tool wrappers.
Provide a secure, sandboxed TypeScript runtime within LibreChat to run agent-generated code that orchestrates MCP tool calls.
Support advanced control flow patterns (loops, conditionals, error handling) in the execution environment to reduce back-and-forth interactions with the LLM.
Implement privacy-preserving mechanisms to keep sensitive data confined to the sandbox, exposing only essential summaries or results to the model context.
Allow users to persist reusable skills or helper functions as separate scripts that agents can import and reuse in subsequent workflows.
Implementation Considerations:
Extending librechat.yaml or configuration UI to define MCP servers in terms of their filesystem representation.
Developing a filesystem abstraction layer that maps registered MCP servers and tools to local TypeScript files and directories.
Building or integrating a secure TypeScript sandbox environment supporting async imports, execution monitoring, and output capturing.
Enhancing the MCP client code to support thin TypeScript wrapper functions calling MCP tools with typed parameters.
Optimizing the agent’s runtime environment and prompting to use this code execution pattern for efficient MCP interaction.
Providing fallback logic for legacy modes where the classic MCP interaction (loading all tool definitions in context) remains available.
Extensive testing for multi-user environments ensuring secure credential handling and sandbox isolation.
Benefits:
Dramatic reduction in token usage and API latency due to on-demand tool loading and localized execution.
Improved scalability for multi-server, multi-tool use cases common in advanced automation workflows.
Stronger privacy and data protection by limiting exposure of sensitive details within model context.
Enhanced developer ergonomics by leveraging TypeScript’s type system and modular code structure for MCP tools.
References:
Anthropic’s blog: "Code execution with MCP: building more efficient AI agents" (Nov 2025)
Cloudflare’s "Code Mode" implementation and Workers platform integration
Existing LibreChat MCP support, emphasizing evolution from broad loading to fine-grained code execution
This proposal sets the roadmap for LibreChat to adopt the modern, efficient MCP usage pattern demonstrated by Anthropic and Cloudflare, driving the platform's next leap in scalability and developer efficiency.
More details
https://www.anthropic.com/engineering/code-execution-with-mcp
Which components are impacted by your request?
No response
Pictures
No response
Code of Conduct
What features would you like to see added?
Summary:
Introduce a new MCP integration mode in LibreChat that represents MCP servers as a filesystem of TypeScript code modules, enabling the agent to dynamically explore available servers and selectively load only the specific tool modules needed for each task. This approach will drastically reduce token usage, improve scalability, and unlock more efficient and flexible agent workflows by leveraging the agent's native code generation strengths.
Background:
Anthropic and Cloudflare have introduced a novel "code execution with MCP" approach where each MCP server is exposed as a folder of TypeScript files (one per tool). The AI agent writes executable code to import and invoke these modules directly within a sandboxed environment. This design minimizes context token bloat by loading only necessary tools and pushing control flow operations (loops, conditionals) into native code rather than context. It also enhances data privacy by keeping intermediate results in the execution environment.
Goals:
Generate a virtual filesystem that mirrors all configured MCP servers and exposes each tool as an isolated TypeScript file.
Enable the agent to browse this filesystem dynamically during execution to discover and import only required tool wrappers.
Provide a secure, sandboxed TypeScript runtime within LibreChat to run agent-generated code that orchestrates MCP tool calls.
Support advanced control flow patterns (loops, conditionals, error handling) in the execution environment to reduce back-and-forth interactions with the LLM.
Implement privacy-preserving mechanisms to keep sensitive data confined to the sandbox, exposing only essential summaries or results to the model context.
Allow users to persist reusable skills or helper functions as separate scripts that agents can import and reuse in subsequent workflows.
Implementation Considerations:
Extending librechat.yaml or configuration UI to define MCP servers in terms of their filesystem representation.
Developing a filesystem abstraction layer that maps registered MCP servers and tools to local TypeScript files and directories.
Building or integrating a secure TypeScript sandbox environment supporting async imports, execution monitoring, and output capturing.
Enhancing the MCP client code to support thin TypeScript wrapper functions calling MCP tools with typed parameters.
Optimizing the agent’s runtime environment and prompting to use this code execution pattern for efficient MCP interaction.
Providing fallback logic for legacy modes where the classic MCP interaction (loading all tool definitions in context) remains available.
Extensive testing for multi-user environments ensuring secure credential handling and sandbox isolation.
Benefits:
Dramatic reduction in token usage and API latency due to on-demand tool loading and localized execution.
Improved scalability for multi-server, multi-tool use cases common in advanced automation workflows.
Stronger privacy and data protection by limiting exposure of sensitive details within model context.
Enhanced developer ergonomics by leveraging TypeScript’s type system and modular code structure for MCP tools.
References:
Anthropic’s blog: "Code execution with MCP: building more efficient AI agents" (Nov 2025)
Cloudflare’s "Code Mode" implementation and Workers platform integration
Existing LibreChat MCP support, emphasizing evolution from broad loading to fine-grained code execution
This proposal sets the roadmap for LibreChat to adopt the modern, efficient MCP usage pattern demonstrated by Anthropic and Cloudflare, driving the platform's next leap in scalability and developer efficiency.
More details
https://www.anthropic.com/engineering/code-execution-with-mcp
Which components are impacted by your request?
No response
Pictures
No response
Code of Conduct