🧹 chore: Type Agent MCP lean projection in ServerConfigsDB (#13171)

Replace the (a: any) cast and its eslint-disable directive in
ServerConfigsDB.getAll() with a precise lean-projection generic.
The Mongoose query already projects only mcpServerNames, so we
can use Pick<IAgent, 'mcpServerNames'> and let .lean<T[]>() carry
the shape through without resorting to any.

Switches the empty-array guard from || to ?? for clarity; both
behave identically for string[] | undefined.

Aligns with the project's "Never use any" rule (CLAUDE.md ->
Type Safety). No runtime change.
This commit is contained in:
Gaurav Dubey 2026-05-19 01:02:43 +05:30 committed by GitHub
parent 77c523ea35
commit 6466263493
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,7 +6,7 @@ import {
PermissionBits,
} from 'librechat-data-provider';
import { logger, encryptV2, decryptV2, createMethods } from '@librechat/data-schemas';
import type { AllMethods, MCPServerDocument } from '@librechat/data-schemas';
import type { AllMethods, IAgent, MCPServerDocument } from '@librechat/data-schemas';
import type { IServerConfigsRepositoryInterface } from '~/mcp/registry/ServerConfigsRepositoryInterface';
import type { ParsedServerConfig, AddServerResult } from '~/mcp/types';
import { AccessControlService } from '~/acl/accessControlService';
@ -370,14 +370,9 @@ export class ServerConfigsDB implements IServerConfigsRepositoryInterface {
mcpServerNames: { $exists: true, $not: { $size: 0 } },
},
{ mcpServerNames: 1 },
).lean();
).lean<Pick<IAgent, 'mcpServerNames'>[]>();
agentMCPServerNames = [
...new Set(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
agentsWithMCP.flatMap((a: any) => a.mcpServerNames || []),
),
];
agentMCPServerNames = [...new Set(agentsWithMCP.flatMap((a) => a.mcpServerNames ?? []))];
}
const directResults = await this._dbMethods.getListMCPServersByIds({