mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🐛 fix: Display OAuth MCP servers according to Chat Menu Setting (#8643)
* fix: chatMenu not being respected in MCPSelect * fix: chatMenu not being respected in MCPSubMenu
This commit is contained in:
parent
ec67cf2d3a
commit
3dc9e85fab
4 changed files with 23 additions and 5 deletions
|
|
@ -106,6 +106,7 @@ router.get('/', async function (req, res) {
|
||||||
const serverConfig = config.mcpServers[serverName];
|
const serverConfig = config.mcpServers[serverName];
|
||||||
payload.mcpServers[serverName] = {
|
payload.mcpServers[serverName] = {
|
||||||
customUserVars: serverConfig?.customUserVars || {},
|
customUserVars: serverConfig?.customUserVars || {},
|
||||||
|
chatMenu: serverConfig?.chatMenu,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,14 @@ function MCPSelect() {
|
||||||
const { mcpSelect, startupConfig } = useBadgeRowContext();
|
const { mcpSelect, startupConfig } = useBadgeRowContext();
|
||||||
const { mcpValues, setMCPValues, mcpToolDetails, isPinned } = mcpSelect;
|
const { mcpValues, setMCPValues, mcpToolDetails, isPinned } = mcpSelect;
|
||||||
|
|
||||||
// Get all configured MCP servers from config
|
// Get all configured MCP servers from config that allow chat menu
|
||||||
const configuredServers = useMemo(() => {
|
const configuredServers = useMemo(() => {
|
||||||
return Object.keys(startupConfig?.mcpServers || {});
|
if (!startupConfig?.mcpServers) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return Object.entries(startupConfig.mcpServers)
|
||||||
|
.filter(([, config]) => config.chatMenu !== false)
|
||||||
|
.map(([serverName]) => serverName);
|
||||||
}, [startupConfig?.mcpServers]);
|
}, [startupConfig?.mcpServers]);
|
||||||
|
|
||||||
const [isConfigModalOpen, setIsConfigModalOpen] = useState(false);
|
const [isConfigModalOpen, setIsConfigModalOpen] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { useRef, useEffect, useCallback, useMemo } from 'react';
|
||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
import { Constants, LocalStorageKeys, EModelEndpoint } from 'librechat-data-provider';
|
import { Constants, LocalStorageKeys, EModelEndpoint } from 'librechat-data-provider';
|
||||||
import type { TPlugin } from 'librechat-data-provider';
|
import type { TPlugin } from 'librechat-data-provider';
|
||||||
import { useAvailableToolsQuery } from '~/data-provider';
|
import { useAvailableToolsQuery, useGetStartupConfig } from '~/data-provider';
|
||||||
import useLocalStorage from '~/hooks/useLocalStorageAlt';
|
import useLocalStorage from '~/hooks/useLocalStorageAlt';
|
||||||
import { ephemeralAgentByConvoId } from '~/store';
|
import { ephemeralAgentByConvoId } from '~/store';
|
||||||
|
|
||||||
|
|
@ -28,12 +28,13 @@ export function useMCPSelect({ conversationId }: UseMCPSelectOptions) {
|
||||||
const key = conversationId ?? Constants.NEW_CONVO;
|
const key = conversationId ?? Constants.NEW_CONVO;
|
||||||
const hasSetFetched = useRef<string | null>(null);
|
const hasSetFetched = useRef<string | null>(null);
|
||||||
const [ephemeralAgent, setEphemeralAgent] = useRecoilState(ephemeralAgentByConvoId(key));
|
const [ephemeralAgent, setEphemeralAgent] = useRecoilState(ephemeralAgentByConvoId(key));
|
||||||
const { data: mcpToolDetails, isFetched } = useAvailableToolsQuery(EModelEndpoint.agents, {
|
const { data: startupConfig } = useGetStartupConfig();
|
||||||
|
const { data: rawMcpTools, isFetched } = useAvailableToolsQuery(EModelEndpoint.agents, {
|
||||||
select: (data: TPlugin[]) => {
|
select: (data: TPlugin[]) => {
|
||||||
const mcpToolsMap = new Map<string, TPlugin>();
|
const mcpToolsMap = new Map<string, TPlugin>();
|
||||||
data.forEach((tool) => {
|
data.forEach((tool) => {
|
||||||
const isMCP = tool.pluginKey.includes(Constants.mcp_delimiter);
|
const isMCP = tool.pluginKey.includes(Constants.mcp_delimiter);
|
||||||
if (isMCP && tool.chatMenu !== false) {
|
if (isMCP) {
|
||||||
const parts = tool.pluginKey.split(Constants.mcp_delimiter);
|
const parts = tool.pluginKey.split(Constants.mcp_delimiter);
|
||||||
const serverName = parts[parts.length - 1];
|
const serverName = parts[parts.length - 1];
|
||||||
if (!mcpToolsMap.has(serverName)) {
|
if (!mcpToolsMap.has(serverName)) {
|
||||||
|
|
@ -50,6 +51,16 @@ export function useMCPSelect({ conversationId }: UseMCPSelectOptions) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mcpToolDetails = useMemo(() => {
|
||||||
|
if (!rawMcpTools || !startupConfig?.mcpServers) {
|
||||||
|
return rawMcpTools;
|
||||||
|
}
|
||||||
|
return rawMcpTools.filter((tool) => {
|
||||||
|
const serverConfig = startupConfig?.mcpServers?.[tool.name];
|
||||||
|
return serverConfig?.chatMenu !== false;
|
||||||
|
});
|
||||||
|
}, [rawMcpTools, startupConfig?.mcpServers]);
|
||||||
|
|
||||||
const mcpState = useMemo(() => {
|
const mcpState = useMemo(() => {
|
||||||
return ephemeralAgent?.mcp ?? [];
|
return ephemeralAgent?.mcp ?? [];
|
||||||
}, [ephemeralAgent?.mcp]);
|
}, [ephemeralAgent?.mcp]);
|
||||||
|
|
|
||||||
|
|
@ -612,6 +612,7 @@ export type TStartupConfig = {
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
chatMenu?: boolean;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
mcpPlaceholder?: string;
|
mcpPlaceholder?: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue