mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
🪄 fix: MCP UI Renders for OAuth and Custom User Vars Servers (#9559)
This commit is contained in:
parent
8d6cb5eee0
commit
a2ff6613c5
3 changed files with 11 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';
|
import React, { createContext, useContext, useEffect, useRef } from 'react';
|
||||||
import { useSetRecoilState } from 'recoil';
|
import { useSetRecoilState } from 'recoil';
|
||||||
import { Tools, Constants, LocalStorageKeys, AgentCapabilities } from 'librechat-data-provider';
|
import { Tools, Constants, LocalStorageKeys, AgentCapabilities } from 'librechat-data-provider';
|
||||||
import type { TAgentsEndpoint } from 'librechat-data-provider';
|
import type { TAgentsEndpoint } from 'librechat-data-provider';
|
||||||
|
@ -7,7 +7,6 @@ import {
|
||||||
useSearchApiKeyForm,
|
useSearchApiKeyForm,
|
||||||
useGetAgentsConfig,
|
useGetAgentsConfig,
|
||||||
useCodeApiKeyForm,
|
useCodeApiKeyForm,
|
||||||
useGetMCPTools,
|
|
||||||
useToolToggle,
|
useToolToggle,
|
||||||
} from '~/hooks';
|
} from '~/hooks';
|
||||||
import { getTimestampedValue, setTimestamp } from '~/utils/timestamps';
|
import { getTimestampedValue, setTimestamp } from '~/utils/timestamps';
|
||||||
|
@ -15,7 +14,6 @@ import { ephemeralAgentByConvoId } from '~/store';
|
||||||
|
|
||||||
interface BadgeRowContextType {
|
interface BadgeRowContextType {
|
||||||
conversationId?: string | null;
|
conversationId?: string | null;
|
||||||
mcpServerNames?: string[] | null;
|
|
||||||
agentsConfig?: TAgentsEndpoint | null;
|
agentsConfig?: TAgentsEndpoint | null;
|
||||||
webSearch: ReturnType<typeof useToolToggle>;
|
webSearch: ReturnType<typeof useToolToggle>;
|
||||||
artifacts: ReturnType<typeof useToolToggle>;
|
artifacts: ReturnType<typeof useToolToggle>;
|
||||||
|
@ -49,7 +47,6 @@ export default function BadgeRowProvider({
|
||||||
}: BadgeRowProviderProps) {
|
}: BadgeRowProviderProps) {
|
||||||
const lastKeyRef = useRef<string>('');
|
const lastKeyRef = useRef<string>('');
|
||||||
const hasInitializedRef = useRef(false);
|
const hasInitializedRef = useRef(false);
|
||||||
const { mcpToolDetails } = useGetMCPTools();
|
|
||||||
const { agentsConfig } = useGetAgentsConfig();
|
const { agentsConfig } = useGetAgentsConfig();
|
||||||
const key = conversationId ?? Constants.NEW_CONVO;
|
const key = conversationId ?? Constants.NEW_CONVO;
|
||||||
|
|
||||||
|
@ -191,16 +188,11 @@ export default function BadgeRowProvider({
|
||||||
|
|
||||||
const mcpServerManager = useMCPServerManager({ conversationId });
|
const mcpServerManager = useMCPServerManager({ conversationId });
|
||||||
|
|
||||||
const mcpServerNames = useMemo(() => {
|
|
||||||
return (mcpToolDetails ?? []).map((tool) => tool.name);
|
|
||||||
}, [mcpToolDetails]);
|
|
||||||
|
|
||||||
const value: BadgeRowContextType = {
|
const value: BadgeRowContextType = {
|
||||||
webSearch,
|
webSearch,
|
||||||
artifacts,
|
artifacts,
|
||||||
fileSearch,
|
fileSearch,
|
||||||
agentsConfig,
|
agentsConfig,
|
||||||
mcpServerNames,
|
|
||||||
conversationId,
|
conversationId,
|
||||||
codeApiKeyForm,
|
codeApiKeyForm,
|
||||||
codeInterpreter,
|
codeInterpreter,
|
||||||
|
|
|
@ -8,7 +8,6 @@ function MCPSelectContent() {
|
||||||
const { conversationId, mcpServerManager } = useBadgeRowContext();
|
const { conversationId, mcpServerManager } = useBadgeRowContext();
|
||||||
const {
|
const {
|
||||||
localize,
|
localize,
|
||||||
isPinned,
|
|
||||||
mcpValues,
|
mcpValues,
|
||||||
isInitializing,
|
isInitializing,
|
||||||
placeholderText,
|
placeholderText,
|
||||||
|
@ -69,14 +68,6 @@ function MCPSelectContent() {
|
||||||
[getServerStatusIconProps, isInitializing],
|
[getServerStatusIconProps, isInitializing],
|
||||||
);
|
);
|
||||||
|
|
||||||
if ((!mcpValues || mcpValues.length === 0) && !isPinned) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!configuredServers || configuredServers.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const configDialogProps = getConfigDialogProps();
|
const configDialogProps = getConfigDialogProps();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -102,8 +93,13 @@ function MCPSelectContent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function MCPSelect() {
|
function MCPSelect() {
|
||||||
const { mcpServerNames } = useBadgeRowContext();
|
const { mcpServerManager } = useBadgeRowContext();
|
||||||
if ((mcpServerNames?.length ?? 0) === 0) return null;
|
const { configuredServers } = mcpServerManager;
|
||||||
|
|
||||||
|
if (!configuredServers || configuredServers.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return <MCPSelectContent />;
|
return <MCPSelectContent />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ const ToolsDropdown = ({ disabled }: ToolsDropdownProps) => {
|
||||||
artifacts,
|
artifacts,
|
||||||
fileSearch,
|
fileSearch,
|
||||||
agentsConfig,
|
agentsConfig,
|
||||||
mcpServerNames,
|
mcpServerManager,
|
||||||
codeApiKeyForm,
|
codeApiKeyForm,
|
||||||
codeInterpreter,
|
codeInterpreter,
|
||||||
searchApiKeyForm,
|
searchApiKeyForm,
|
||||||
|
@ -286,7 +286,8 @@ const ToolsDropdown = ({ disabled }: ToolsDropdownProps) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mcpServerNames && mcpServerNames.length > 0) {
|
const { configuredServers } = mcpServerManager;
|
||||||
|
if (configuredServers && configuredServers.length > 0) {
|
||||||
dropdownItems.push({
|
dropdownItems.push({
|
||||||
hideOnClick: false,
|
hideOnClick: false,
|
||||||
render: (props) => <MCPSubMenu {...props} placeholder={mcpPlaceholder} />,
|
render: (props) => <MCPSubMenu {...props} placeholder={mcpPlaceholder} />,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue