🔑 fix: Type-Safe User Context Forwarding for Non-OAuth Tool Discovery#12348
Merged
Conversation
Extract UserConnectionContext from OAuthConnectionOptions to properly model the non-OAuth case where user/customUserVars/requestBody need placeholder resolution without requiring OAuth-specific fields. - Remove prohibited `as unknown as` double-cast - Forward requestBody and connectionTimeout (previously omitted) - Add unit tests for argument forwarding at Manager and Factory layers - Add integration test exercising real processMCPEnv substitution
danny-avila
force-pushed
the
fix/mcp-vars
branch
from
March 21, 2026 16:39
343bc59 to
4ace073
Compare
jcbartle
pushed a commit
to jcbartle/LibreChat
that referenced
this pull request
May 11, 2026
…danny-avila#12348) * fix(mcp): pass missing customUserVars and user during unauthenticated tool discovery * fix(mcp): type-safe user context forwarding for non-OAuth tool discovery Extract UserConnectionContext from OAuthConnectionOptions to properly model the non-OAuth case where user/customUserVars/requestBody need placeholder resolution without requiring OAuth-specific fields. - Remove prohibited `as unknown as` double-cast - Forward requestBody and connectionTimeout (previously omitted) - Add unit tests for argument forwarding at Manager and Factory layers - Add integration test exercising real processMCPEnv substitution --------- Co-authored-by: Danny Avila <danny@librechat.ai>
ThomasVuNguyen
pushed a commit
to ThomasVuNguyen/LibreChat
that referenced
this pull request
Jul 15, 2026
…danny-avila#12348) * fix(mcp): pass missing customUserVars and user during unauthenticated tool discovery * fix(mcp): type-safe user context forwarding for non-OAuth tool discovery Extract UserConnectionContext from OAuthConnectionOptions to properly model the non-OAuth case where user/customUserVars/requestBody need placeholder resolution without requiring OAuth-specific fields. - Remove prohibited `as unknown as` double-cast - Forward requestBody and connectionTimeout (previously omitted) - Add unit tests for argument forwarding at Manager and Factory layers - Add integration test exercising real processMCPEnv substitution --------- Co-authored-by: Danny Avila <danny@librechat.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug that prevents MCP servers from being shared by multiple users when user-specific API keys / authentication are passed via
customUserVarsinside URL query parameters or headers (e.g.,?key={{user_api_key}}).Previously, during unauthenticated tool discovery, MCPManager.ts omitted the
userandcustomUserVarsparameters when callingMCPConnectionFactory.discoverTools(). Because of this bug, dynamic placeholders in the server config URL were never replaced with the corresponding user's tokens. This resulted in literal strings like?key={{user_api_key}}being sent backward to the MCP server endpoint, causing connection request parameters to error out and fail.By explicitly forwarding the
customUserVarsanduserproperties into the config options for discoverTools, shared MCP servers relying on per-user custom variables now successfully substitute credentials and work perfectly as intended for all users.Change Type
Testing
Test Configuration:
requiresOAuth: false.customUserVarsfor the user API Key, and map it via a placeholder in the connectionurl(e.g.,url: "https://my-mcp.server.com/server?key={{MY_CUSTOM_KEY}}").Result Status:
{{MY_CUSTOM_KEY}}is passed across thestreamable-httpclient transport, resulting in a Server-side[PARAM_ERROR]/ empty parameter rejection from the MCP backend.?key=c527bd0...) resulting in a successful HTTP 200 payload and successful tool discovery.Checklist