Dynamic MCP Server and Tool Discovery #9837
Replies: 5 comments 21 replies
-
|
Related: the "official" MCP registry was launched a couple weeks ago. I feel like it is still very early days for that project. But: having dynamic MCP server registration in LibreChat would be the first step in aligning with that direction, and eventually being able to support it.
In the image above, LibreChat of course would be one of the clients, e.g. Cursor |
Beta Was this translation helpful? Give feedback.
-
|
Excellent write-up @nhtruong! This aligns with a lot of discussions I've had on this topic across all the LibreChat channels.
This is the main item already in the works. It will be possible to add/edit "pre-defined" MCP servers, first on a role basis and eventually also include user groups, to determine what MCP servers are available to what users from an admin perspective. What I'm working on applies to all configuration (
I think this is a great opportunity to apply the new ACL/permissions system when allowing users to add MCP servers from the UI, so they can share who else gets access in a granular way.
This is awesome and looking forward to that! |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @danny-avila ! The dynamic MCP servers lists will have to rely on Redis a lot to keep things consistent across sessions and across multiple LC backend servers. As you and I have discussed, moving the the cache logic into I'm going to work on expanding the
|
Beta Was this translation helpful? Give feedback.
-
|
Excellent work guys! From a use-case perspective, here are the main items we can deliver progressively as releasable packages. Package 1 (High priority)
Package 2 (Medium priority)
Future packages (early ideas)
Open questions: Stateless vs. stateful MCP serversI’m still wrapping my head around stateless vs. stateful MCP server designs. A few questions for the group:
@danny & @nhtruong any updates on this? Maybe we can sync on a technical approach and split the work to move it forward together. I’m also happy to hop on a quick chat whenever works for you. (I’m based in Munich, though I can be flexible with meeting time.) Atef Bellaaj [email protected] on behalf of Daimler Truck AG. |
Beta Was this translation helpful? Give feedback.
-
|
This feature sounds great! Thank you for planning it. Maybe this is not the right place to raise this topic, I'm sorry if it's misplaced. In my organization we use Backstage, https://github.com/backstage/backstage, as a service catalog and we would like to going forward turn internal API:s into MCP tools. As an experiment we extended Backstage with MCP server support, so that developers in their individual repositories can define MCP servers in their This information is periodically indexed by Backstage. What we then did was to fetch this information from our internal Backstage and included the results in LibreChat. The lookup-service is a proxy in front of Backstage to fetch all MCP types. This is just an example of how a registry could live outside of LibreChat. What would be interesting is to have some kind of plugin system where you can add code to load your list of MCPs in whatever way you want, and then convert it to a format LibreChat understands so it includes it in it's internal cache and in the UI. Thank you. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
Currently, MCP servers are determined by a static list within
librechat.yaml, this works fine for small scale deployments, but a much larger audience, we need a way to dynamically discover MCP servers without having to update thelibrechat.yamlfile. There are 3 major use cases that I can think of:1. Allowing admins to add MCP servers without having to update the
librechat.yamlfileOn top of having a static list of MCP servers, we can allow admins to add MCP servers via the admin interface. This way, admins can add MCP servers as needed without having to update the
librechat.yamlfile and redeploy the application. The MCP server metadata can be stored in the database and can be retrieved by the application at runtime.Expanding this further, MCP server entries stored in the database with the same names as those in the
librechat.yamlfile can override the static entries, allowing admins to modify the MCP server metadata without having to update thelibrechat.yamlfile. This will allow for a smooth transition from a static list to a dynamic list of MCP servers.2. Allowing each user to specify their own MCP servers
Users can be given the option to specify their own MCP servers in the application settings. This way, users can connect to any MCP server they trust or prefer without having to ask their LibreChat admins to add it to the static list. The application can provide a UI for users to add, remove, or modify their MCP server metadata. The user-specified MCP servers can be stored in the database associated with the user's account.
This can also be expanded to allow the owner of a user group to specify the MCP servers for that group, allowing for more control over the MCP servers used by a specific group of users.
3. Local MCP Server Discovery
A team at Shopify is working on a local MCP server discovery mechanism that allows LibreChat, which runs on the cloud, to discover MCP servers running on the user's local machine. This feature creates a tunnel running on the user's machine and dynamically registering MCP servers on LibreChat. This allows users to connect to their local MCP servers without having to expose them to the internet or ask their LibreChat admins to add them to the static list.
Top-level Design
This is a complex problem, and we need a strong foundation to be able to seamlessly support different discovery methods. The previous work on refactoring the MCPManager set the first building blocks for this vision. This is how I envision how the components of MCPManagers should behave to support Dynamic MCP Server Discovery:
I. MCP Servers Registry
This will be the authoritative source of truth for all MCP servers provided by LibreChat. No matter how a server is discovered, it must be registered in this registry. Other than having the ability to ingest new MCP servers, this registry will also provide a way to query the list of available MCP servers and answer questions like "What are the available MCP servers for a specific user?" or "What form of authentication does a server require?".
Since the list of servers and their details can change dynamically, this registry should hold the server configs in a cache so that all LibreChat backend servers can see the same list of MCP servers. This cache must be updated anytime a new MCP server is added or an existing one is modified.
At startup, this registry loads up the MCP servers from the
librechat.yamlfile, from the database, and/or from a local MCP tunnel. It then builds a set of caches to hold different tiers of MCP servers from scratch (e.g. app-level, group-level, user-level). This process, if run by all backend servers will lead to a race condition, so it should be run by a single backend server called the leader. The leader also periodically refreshes the cache by re-querying the MCP Server Discovery API.II. MCP ToolBox
Each user (or user group) should have their own set of MCP tools that are available to them. The tools should be dynamically loaded based on the MCP servers available to the users, and the tools each server provides for that user.
To find out which tools are available to a user, the application must first query the MCP Servers Registry to get the list of available MCP servers for that user, then query each server to get the list of tools it provides for that user. This process is expensive, so it should be cached for a reasonable amount of time.
The list of tools per user will be populated on-demand, instead of at startup.
III. MCP Connections Repository
While modern Streamable HTTP MCP servers are perfect for ephemeral connections, LibreChat also supports HTTP+SSE and STDIO MCP servers, which are either stateful or expensive to create and destroy. Therefore, we need a way to manage these connections in a way that allows us to reuse them across multiple requests or shared between multiple users.
There should be a connections repo for all app-level connections (shared between all users), a connections repo for each user group, and a connections repo for each user. There can be different life-cycle rules for each of these repositories (e.g., app-level connections can be long-lived, while user-level connections can be short-lived or idle for a shorter period of time).
Each connection should be lazy-loaded and cached for a reasonable amount of time (Note that STDIO connections can be quite a memory hog, so we need to be careful about how we manage them). These connections should always try to reconnect if they are disconnected, and the repository must gracefully garbage collect any connections that are no longer needed or have been idle for too long to avoid memory leaks.
Implementation
Here's a laundry list of tasks that need to be done to implement the above:
6 Consolidate all MCP logic outside the MCP package into the MCP package.
Beta Was this translation helpful? Give feedback.
All reactions