Skip to content

🗝️ feat: User Provided Credentials for MCP Servers - #7980

Merged
danny-avila merged 15 commits into
devfrom
feat/mcp-user-provided-vars
Jun 19, 2025
Merged

🗝️ feat: User Provided Credentials for MCP Servers#7980
danny-avila merged 15 commits into
devfrom
feat/mcp-user-provided-vars

Conversation

@danny-avila

@danny-avila danny-avila commented Jun 19, 2025

Copy link
Copy Markdown
Owner

Originally #7824

Summary

This PR adds support for user-specific credentials for MCP servers. It allows LibreChat administrators to define custom user variables in the configuration that can be set individually by each user and then referenced in MCP server headers.

Currently, when teams use MCP servers that require authentication, they often use shared/generic credentials for the entire team, which is not ideal from a security and accountability perspective. While LibreChat does support passing the {{LIBRECHAT_USER_ID}} variable in headers, this only works for MCP servers specifically designed to handle LibreChat user IDs.

This enhancement allows users to provide their own credentials for third-party MCPs.

Change Type

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Testing

  • Edit MCP variables from Panel
  • Edit MCP variables from MCPSelect
  • Test revoke from side panel
  • Test revoke from MCPSelect
  • Header variables fill to SSE/streamable
  • Do not show MCP Settings in the right panel when no servers with custom variables are defined
  • Headers/connected are/is refreshed after editing the MCP settings
  • Retest web search install/uninstall of variables
  • Retest web search using assistant chat
  • Add new MCP tool to an agent with dialog (variables are not required for MCP in this case)
  • Add new non-MCP tool to an agent with dialog with API Key - tested with OpenWeather and API Key form popup

Test Configuration:

Any MCP server that supports SSE/Streamable HTTP and requires some headers.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • [] My changes do not introduce new warnings
  • I have tested the feature with multiple MCP server configurations
  • Local unit tests pass with my changes

Implementation Details

The implementation adds:

  1. A new customUserVars section in the MCP server configuration:
mcpServers:
  redmine:
    url: https://example.com/sse
    headers:
      REDMINE-URL: https://example.com
      REDMINE-API-KEY: "{{REDMINE_API_KEY}}"
    customUserVars:
      REDMINE_API_KEY:
        title: "Redmine API Key"
        description: "Go to https://example.com/my/api_key to get your API key"

Variables can be used in headers as shown in the example.

  1. UI components for configuring user variables:
    • Users can configure their specific values for these variables in two ways:
      • From Assistant Chat Input: A new settings icon appears next to MCP servers in the MCPSelect.tsx dropdown (used when selecting MCPs for an assistant). Clicking this icon opens the configuration modal.
      • From User Settings Panel: A dedicated "MCP Settings" section in the user settings side panel (client/src/components/SidePanel/MCP/MCPPanel.tsx) lists all MCP servers that have customUserVars defined by the admin. Clicking a server name here also opens the configuration modal.
    • Configuration Modal (MCPConfigDialog.tsx): Both access points trigger the same reusable modal dialog. This dialog dynamically renders input fields based on the customUserVars schema defined by the administrator for the selected MCP server. It allows users to input and save their specific values. Features include:
      • Displaying titles and descriptions for each variable as defined in librechat.yaml.
      • Secure input fields (e.g., password type) with an option to reveal/hide the value.
    • Secure Storage: User-provided variables are sent to the backend via an API call and stored securely (uses existing pluginauths), associated with the user and the specific MCP plugin key (e.g., mcp_serverName).
Screenshot 2025-06-10 at 21 00 24 Screenshot 2025-06-10 at 21 00 38 Screenshot 2025-06-10 at 21 00 31

twinity1 and others added 12 commits June 19, 2025 11:02
chore: add aider to gitignore

feat: fill custom variables to MCP server

feat: replace placeholders with custom user MCP variables

feat: handle MCP install/uninstall (uses pluginauths)

feat: add MCP custom variables dialog to MCPSelect

feat: add MCP custom variables dialog to the side panel

feat: do not require to fill MCP credentials for in tools dialog

feat: add translations keys (en+cs) for custom MCP variables

fix: handle LIBRECHAT_USER_ID correctly during MCP var replacement

style: remove unused MCP translation keys

style: fix eslint for MCP custom vars

chore: move aider gitignore to AI section
… for improved code organization and maintainability
…ganization and update pluginAuth schema to use the new import
…eamline PluginService.js; add new getPluginAuthMap function for improved plugin authentication handling
…age and improving server key collection logic
…ameter and enhancing user-specific authentication handling to avoid closure encapsulation
…onment variable processing and enhance readability
… and improving authentication handling for custom user variables
@danny-avila
danny-avila merged commit 3e4b01d into dev Jun 19, 2025
@danny-avila
danny-avila deleted the feat/mcp-user-provided-vars branch June 19, 2025 22:27
@ksg97031

Copy link
Copy Markdown

@danny-avila
You might already be aware, but I'm seeing the following error on the latest librechat-dev image when docker compose starts.
This appears to be caused by your recent PR, so I wanted to bring it to your attention.

{"level":"error","message":"Error in startup config Cannot read properties of null (reading 'mcpServers')",
"stack":"TypeError: Cannot read properties of null (reading 'mcpServers')\n    
at /app/api/server/routes/config.js:105:16\n    at process.processTicksAndRejections 
(node:internal/process/task_queues:95:5)"}

@danny-avila

Copy link
Copy Markdown
Owner Author

@danny-avila You might already be aware, but I'm seeing the following error on the latest librechat-dev image when docker compose starts. This appears to be caused by your recent PR, so I wanted to bring it to your attention.

{"level":"error","message":"Error in startup config Cannot read properties of null (reading 'mcpServers')",
"stack":"TypeError: Cannot read properties of null (reading 'mcpServers')\n    
at /app/api/server/routes/config.js:105:16\n    at process.processTicksAndRejections 
(node:internal/process/task_queues:95:5)"}

Thanks, the image was just built, but not able to reproduce the issue. I can patch based on your error message, though.

jmaddington pushed a commit to jmaddington/LibreChat that referenced this pull request Jun 21, 2025
* 🗝️ feat: Per-User Credentials for MCP Servers

chore: add aider to gitignore

feat: fill custom variables to MCP server

feat: replace placeholders with custom user MCP variables

feat: handle MCP install/uninstall (uses pluginauths)

feat: add MCP custom variables dialog to MCPSelect

feat: add MCP custom variables dialog to the side panel

feat: do not require to fill MCP credentials for in tools dialog

feat: add translations keys (en+cs) for custom MCP variables

fix: handle LIBRECHAT_USER_ID correctly during MCP var replacement

style: remove unused MCP translation keys

style: fix eslint for MCP custom vars

chore: move aider gitignore to AI section

* feat: Add Plugin Authentication Methods to data-schemas

* refactor: Replace PluginAuth model methods with new utility functions for improved code organization and maintainability

* refactor: Move IPluginAuth interface to types directory for better organization and update pluginAuth schema to use the new import

* refactor: Remove unused getUsersPluginsAuthValuesMap function and streamline PluginService.js; add new getPluginAuthMap function for improved plugin authentication handling

* chore: fix typing for optional tools property with GenericTool[] type

* chore: update librechat-data-provider version to 0.7.88

* refactor: optimize getUserMCPAuthMap function by reducing variable usage and improving server key collection logic

* refactor: streamline MCP tool creation by removing customUserVars parameter and enhancing user-specific authentication handling to avoid closure encapsulation

* refactor: extract processSingleValue function to streamline MCP environment variable processing and enhance readability

* refactor: enhance MCP tool processing logic by simplifying conditions and improving authentication handling for custom user variables

* ci: fix action tests

* chore: fix imports, remove comments

* chore: remove non-english translations

* fix: remove newline at end of translation.json file

---------

Co-authored-by: Aleš Kůtek <kutekales@gmail.com>
kenshinsamue pushed a commit to intelequia/LibreChat that referenced this pull request Aug 4, 2025
* 🗝️ feat: Per-User Credentials for MCP Servers

chore: add aider to gitignore

feat: fill custom variables to MCP server

feat: replace placeholders with custom user MCP variables

feat: handle MCP install/uninstall (uses pluginauths)

feat: add MCP custom variables dialog to MCPSelect

feat: add MCP custom variables dialog to the side panel

feat: do not require to fill MCP credentials for in tools dialog

feat: add translations keys (en+cs) for custom MCP variables

fix: handle LIBRECHAT_USER_ID correctly during MCP var replacement

style: remove unused MCP translation keys

style: fix eslint for MCP custom vars

chore: move aider gitignore to AI section

* feat: Add Plugin Authentication Methods to data-schemas

* refactor: Replace PluginAuth model methods with new utility functions for improved code organization and maintainability

* refactor: Move IPluginAuth interface to types directory for better organization and update pluginAuth schema to use the new import

* refactor: Remove unused getUsersPluginsAuthValuesMap function and streamline PluginService.js; add new getPluginAuthMap function for improved plugin authentication handling

* chore: fix typing for optional tools property with GenericTool[] type

* chore: update librechat-data-provider version to 0.7.88

* refactor: optimize getUserMCPAuthMap function by reducing variable usage and improving server key collection logic

* refactor: streamline MCP tool creation by removing customUserVars parameter and enhancing user-specific authentication handling to avoid closure encapsulation

* refactor: extract processSingleValue function to streamline MCP environment variable processing and enhance readability

* refactor: enhance MCP tool processing logic by simplifying conditions and improving authentication handling for custom user variables

* ci: fix action tests

* chore: fix imports, remove comments

* chore: remove non-english translations

* fix: remove newline at end of translation.json file

---------

Co-authored-by: Aleš Kůtek <kutekales@gmail.com>
patricksn3ll pushed a commit to patricksn3ll/LibreChat that referenced this pull request Dec 11, 2025
* 🗝️ feat: Per-User Credentials for MCP Servers

chore: add aider to gitignore

feat: fill custom variables to MCP server

feat: replace placeholders with custom user MCP variables

feat: handle MCP install/uninstall (uses pluginauths)

feat: add MCP custom variables dialog to MCPSelect

feat: add MCP custom variables dialog to the side panel

feat: do not require to fill MCP credentials for in tools dialog

feat: add translations keys (en+cs) for custom MCP variables

fix: handle LIBRECHAT_USER_ID correctly during MCP var replacement

style: remove unused MCP translation keys

style: fix eslint for MCP custom vars

chore: move aider gitignore to AI section

* feat: Add Plugin Authentication Methods to data-schemas

* refactor: Replace PluginAuth model methods with new utility functions for improved code organization and maintainability

* refactor: Move IPluginAuth interface to types directory for better organization and update pluginAuth schema to use the new import

* refactor: Remove unused getUsersPluginsAuthValuesMap function and streamline PluginService.js; add new getPluginAuthMap function for improved plugin authentication handling

* chore: fix typing for optional tools property with GenericTool[] type

* chore: update librechat-data-provider version to 0.7.88

* refactor: optimize getUserMCPAuthMap function by reducing variable usage and improving server key collection logic

* refactor: streamline MCP tool creation by removing customUserVars parameter and enhancing user-specific authentication handling to avoid closure encapsulation

* refactor: extract processSingleValue function to streamline MCP environment variable processing and enhance readability

* refactor: enhance MCP tool processing logic by simplifying conditions and improving authentication handling for custom user variables

* ci: fix action tests

* chore: fix imports, remove comments

* chore: remove non-english translations

* fix: remove newline at end of translation.json file

---------

Co-authored-by: Aleš Kůtek <kutekales@gmail.com>
jcbartle pushed a commit to jcbartle/LibreChat that referenced this pull request May 11, 2026
* 🗝️ feat: Per-User Credentials for MCP Servers

chore: add aider to gitignore

feat: fill custom variables to MCP server

feat: replace placeholders with custom user MCP variables

feat: handle MCP install/uninstall (uses pluginauths)

feat: add MCP custom variables dialog to MCPSelect

feat: add MCP custom variables dialog to the side panel

feat: do not require to fill MCP credentials for in tools dialog

feat: add translations keys (en+cs) for custom MCP variables

fix: handle LIBRECHAT_USER_ID correctly during MCP var replacement

style: remove unused MCP translation keys

style: fix eslint for MCP custom vars

chore: move aider gitignore to AI section

* feat: Add Plugin Authentication Methods to data-schemas

* refactor: Replace PluginAuth model methods with new utility functions for improved code organization and maintainability

* refactor: Move IPluginAuth interface to types directory for better organization and update pluginAuth schema to use the new import

* refactor: Remove unused getUsersPluginsAuthValuesMap function and streamline PluginService.js; add new getPluginAuthMap function for improved plugin authentication handling

* chore: fix typing for optional tools property with GenericTool[] type

* chore: update librechat-data-provider version to 0.7.88

* refactor: optimize getUserMCPAuthMap function by reducing variable usage and improving server key collection logic

* refactor: streamline MCP tool creation by removing customUserVars parameter and enhancing user-specific authentication handling to avoid closure encapsulation

* refactor: extract processSingleValue function to streamline MCP environment variable processing and enhance readability

* refactor: enhance MCP tool processing logic by simplifying conditions and improving authentication handling for custom user variables

* ci: fix action tests

* chore: fix imports, remove comments

* chore: remove non-english translations

* fix: remove newline at end of translation.json file

---------

Co-authored-by: Aleš Kůtek <kutekales@gmail.com>
ThomasVuNguyen pushed a commit to ThomasVuNguyen/LibreChat that referenced this pull request Jul 15, 2026
* 🗝️ feat: Per-User Credentials for MCP Servers

chore: add aider to gitignore

feat: fill custom variables to MCP server

feat: replace placeholders with custom user MCP variables

feat: handle MCP install/uninstall (uses pluginauths)

feat: add MCP custom variables dialog to MCPSelect

feat: add MCP custom variables dialog to the side panel

feat: do not require to fill MCP credentials for in tools dialog

feat: add translations keys (en+cs) for custom MCP variables

fix: handle LIBRECHAT_USER_ID correctly during MCP var replacement

style: remove unused MCP translation keys

style: fix eslint for MCP custom vars

chore: move aider gitignore to AI section

* feat: Add Plugin Authentication Methods to data-schemas

* refactor: Replace PluginAuth model methods with new utility functions for improved code organization and maintainability

* refactor: Move IPluginAuth interface to types directory for better organization and update pluginAuth schema to use the new import

* refactor: Remove unused getUsersPluginsAuthValuesMap function and streamline PluginService.js; add new getPluginAuthMap function for improved plugin authentication handling

* chore: fix typing for optional tools property with GenericTool[] type

* chore: update librechat-data-provider version to 0.7.88

* refactor: optimize getUserMCPAuthMap function by reducing variable usage and improving server key collection logic

* refactor: streamline MCP tool creation by removing customUserVars parameter and enhancing user-specific authentication handling to avoid closure encapsulation

* refactor: extract processSingleValue function to streamline MCP environment variable processing and enhance readability

* refactor: enhance MCP tool processing logic by simplifying conditions and improving authentication handling for custom user variables

* ci: fix action tests

* chore: fix imports, remove comments

* chore: remove non-english translations

* fix: remove newline at end of translation.json file

---------

Co-authored-by: Aleš Kůtek <kutekales@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants