mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
✨ feat: Add Support for customUserVar Replacement in 'args' Field (#8743)
This commit is contained in:
parent
8a1a38f346
commit
1050346915
2 changed files with 49 additions and 0 deletions
|
|
@ -655,6 +655,47 @@ describe('Environment Variable Extraction (MCP)', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should process customUserVars in args field', () => {
|
||||||
|
const user = createTestUser({
|
||||||
|
id: 'user-123',
|
||||||
|
email: 'test@example.com',
|
||||||
|
});
|
||||||
|
const customUserVars = {
|
||||||
|
MY_API_KEY: 'user-provided-api-key-12345',
|
||||||
|
PROFILE_NAME: 'production-profile',
|
||||||
|
};
|
||||||
|
const obj: MCPOptions = {
|
||||||
|
command: 'npx',
|
||||||
|
args: [
|
||||||
|
'-y',
|
||||||
|
'@smithery/cli@latest',
|
||||||
|
'run',
|
||||||
|
'@upstash/context7-mcp',
|
||||||
|
'--key',
|
||||||
|
'{{MY_API_KEY}}',
|
||||||
|
'--profile',
|
||||||
|
'{{PROFILE_NAME}}',
|
||||||
|
'--user',
|
||||||
|
'{{LIBRECHAT_USER_EMAIL}}',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = processMCPEnv(obj, user, customUserVars);
|
||||||
|
|
||||||
|
expect('args' in result && result.args).toEqual([
|
||||||
|
'-y',
|
||||||
|
'@smithery/cli@latest',
|
||||||
|
'run',
|
||||||
|
'@upstash/context7-mcp',
|
||||||
|
'--key',
|
||||||
|
'user-provided-api-key-12345',
|
||||||
|
'--profile',
|
||||||
|
'production-profile',
|
||||||
|
'--user',
|
||||||
|
'test@example.com',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('should prioritize customUserVars over user fields and system env vars if placeholders are the same (though not recommended)', () => {
|
it('should prioritize customUserVars over user fields and system env vars if placeholders are the same (though not recommended)', () => {
|
||||||
// This tests the order of operations: customUserVars -> userFields -> systemEnv
|
// This tests the order of operations: customUserVars -> userFields -> systemEnv
|
||||||
// BUt it's generally not recommended to have overlapping placeholder names.
|
// BUt it's generally not recommended to have overlapping placeholder names.
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,14 @@ export function processMCPEnv(
|
||||||
newObj.env = processedEnv;
|
newObj.env = processedEnv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('args' in newObj && newObj.args) {
|
||||||
|
const processedArgs: string[] = [];
|
||||||
|
for (const originalValue of newObj.args) {
|
||||||
|
processedArgs.push(processSingleValue({ originalValue, customUserVars, user }));
|
||||||
|
}
|
||||||
|
newObj.args = processedArgs;
|
||||||
|
}
|
||||||
|
|
||||||
// Process headers if they exist (for WebSocket, SSE, StreamableHTTP types)
|
// Process headers if they exist (for WebSocket, SSE, StreamableHTTP types)
|
||||||
// Note: `env` and `headers` are on different branches of the MCPOptions union type.
|
// Note: `env` and `headers` are on different branches of the MCPOptions union type.
|
||||||
if ('headers' in newObj && newObj.headers) {
|
if ('headers' in newObj && newObj.headers) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue