Skip to content

✨ feat: Add Support for customUserVar Replacement in 'args' Field #8743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2025

Conversation

dustinhealy
Copy link
Collaborator

@dustinhealy dustinhealy commented Jul 29, 2025

Summary

This pull request adds support for custom user variables (e.g., {{MY_API_KEY}}) substitution in MCP server command arguments during reinitialization. Previously, The processMCPEnv function was only processing env, headers, and url fields but did not handle the args field used by MCP servers such as those generated by Smithery. During MCP server reinitialization through the UI, custom user variables in command arguments remained as unsubstituted placeholders (e.g., '{{MY_API_KEY}}' instead of the actual API key value), causing HTTP 401 authentication errors. Related to discussion #8731

Example Use Case:

mcpServers:
  context7-mcp:
    command: npx
    args:
      - '-y'
      - '@smithery/cli@latest'
      - run
      - '@author/servername-mcp'
      - '--key'
      - "{{MY_API_KEY}}" 
      - '--profile'
      - <redacted>
    customUserVars:
      MY_API_KEY:
        title: "API Key"
        description: "Enter your personal API key from <a href='https://smithery.ai/' target='_blank'>your account settings</a>"
    startup: false

Backend Changes:

  • packages/api/src/utils/env.ts:

    • Args Field Processing: Added processing for the args field in processMCPEnv function to handle custom user variable substitution in MCP server command arguments by iterating through the command arguments and replacing placeholders like {{MY_API_KEY}} with user-provided values.
  • packages/api/src/mcp/mcp.spec.ts:

    • Test Coverage: Added test case "should process customUserVars in args field" to verify that custom user variables are now substituted properly in the args field

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • Added unit test covering custom user variables substitution for the args field
  • Verified all existing MCP environment variable tests continue to pass
  • Manual testing of MCP server reinitialization with custom user variables

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
  • A pull request for updating the documentation has been submitted.

@dustinhealy dustinhealy changed the title feat: Add Support for customUserVar Replacement in 'args' Field ✨feat: Add Support for customUserVar Replacement in 'args' Field Jul 29, 2025
@dustinhealy dustinhealy changed the title ✨feat: Add Support for customUserVar Replacement in 'args' Field ✨ feat: Add Support for customUserVar Replacement in 'args' Field Jul 29, 2025
@danny-avila danny-avila changed the title ✨ feat: Add Support for customUserVar Replacement in 'args' Field ✨ feat: Add Support for customUserVar Replacement in 'args' Field Jul 30, 2025
@danny-avila danny-avila merged commit 1050346 into dev Jul 30, 2025
1 check passed
@danny-avila danny-avila deleted the feat/user-var-args-replacement branch July 30, 2025 18:37
jhrozek pushed a commit to StacklokLabs/LibreChat that referenced this pull request Jul 31, 2025
xycjscs pushed a commit to xycjscs/LibreChat that referenced this pull request Aug 9, 2025
miguelwon pushed a commit to miguelwon/LibreChat that referenced this pull request Aug 10, 2025
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.

2 participants