👤 fix: Missing User Placeholder Fields for MCP Services (#9824)

This commit is contained in:
Danny Avila 2025-09-24 22:48:38 -04:00 committed by GitHub
parent 57f8b333bc
commit 4f3683fd9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 388 additions and 38 deletions

View file

@ -1,5 +1,6 @@
import { extractEnvVariable } from 'librechat-data-provider';
import type { TUser, MCPOptions } from 'librechat-data-provider';
import type { IUser } from '@librechat/data-schemas';
import type { RequestBody } from '~/types';
/**
@ -26,6 +27,31 @@ const ALLOWED_USER_FIELDS = [
'termsAccepted',
] as const;
type AllowedUserField = (typeof ALLOWED_USER_FIELDS)[number];
type SafeUser = Pick<IUser, AllowedUserField>;
/**
* Creates a safe user object containing only allowed fields.
* Optimized for performance while maintaining type safety.
*
* @param user - The user object to extract safe fields from
* @returns A new object containing only allowed fields
*/
export function createSafeUser(user: IUser | null | undefined): Partial<SafeUser> {
if (!user) {
return {};
}
const safeUser: Partial<SafeUser> = {};
for (const field of ALLOWED_USER_FIELDS) {
if (field in user) {
safeUser[field] = user[field];
}
}
return safeUser;
}
/**
* List of allowed request body fields that can be used in header placeholders.
* These are common fields from the request body that are safe to expose in headers.