Skip to content

Commit 9f94d88

Browse files
authored
Feat: Delete MCP server #3221 (#8772)
### What problem does this PR solve? Feat: Delete MCP server #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
1 parent 2e0905d commit 9f94d88

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

web/src/hooks/use-mcp-request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ export const useDeleteMcpServer = () => {
106106
mutateAsync,
107107
} = useMutation({
108108
mutationKey: [McpApiAction.DeleteMcpServer],
109-
mutationFn: async (params: Record<string, any>) => {
110-
const { data = {} } = await mcpServerService.delete(params);
109+
mutationFn: async (ids: string[]) => {
110+
const { data = {} } = await mcpServerService.delete({ mcp_ids: ids });
111111
if (data.code === 0) {
112112
message.success(i18n.t(`message.deleted`));
113113

web/src/pages/agent/constant.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ export const initialWaitingDialogueValues = {};
685685
export const initialAgentValues = {
686686
...initialLlmBaseValues,
687687
description: '',
688+
user_prompt: '',
688689
sys_prompt: ``,
689690
prompts: [{ role: PromptRole.User, content: `{${AgentGlobals.SysQuery}}` }],
690691
message_history_window_size: 12,

web/src/pages/agent/form/agent-form/index.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@/components/ui/form';
1313
import { Input, NumberInput } from '@/components/ui/input';
1414
import { RAGFlowSelect } from '@/components/ui/select';
15+
import { Textarea } from '@/components/ui/textarea';
1516
import { buildOptions } from '@/utils/form';
1617
import { zodResolver } from '@hookform/resolvers/zod';
1718
import { useMemo } from 'react';
@@ -39,6 +40,7 @@ const exceptionMethodOptions = buildOptions(AgentExceptionMethod);
3940
const FormSchema = z.object({
4041
sys_prompt: z.string(),
4142
description: z.string().optional(),
43+
user_prompt: z.string().optional(),
4244
prompts: z.string().optional(),
4345
// prompts: z
4446
// .array(
@@ -98,7 +100,23 @@ const AgentForm = ({ node }: INextOperatorForm) => {
98100
}}
99101
>
100102
<FormContainer>
101-
{isSubAgent && <DescriptionField></DescriptionField>}
103+
{isSubAgent && (
104+
<>
105+
<DescriptionField></DescriptionField>
106+
<FormField
107+
control={form.control}
108+
name={`user_prompt`}
109+
render={({ field }) => (
110+
<FormItem className="flex-1">
111+
<FormLabel>Subagent Input</FormLabel>
112+
<FormControl>
113+
<Textarea {...field}></Textarea>
114+
</FormControl>
115+
</FormItem>
116+
)}
117+
/>
118+
</>
119+
)}
102120
<LargeModelFormField></LargeModelFormField>
103121
<FormField
104122
control={form.control}

web/src/pages/agent/hooks/use-add-node.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ import {
5656
getNodeDragHandle,
5757
} from '../utils';
5858

59+
function isBottomSubAgent(type: string, position: Position) {
60+
return (
61+
(type === Operator.Agent && position === Position.Bottom) ||
62+
type === Operator.Tool
63+
);
64+
}
5965
export const useInitializeOperatorParams = () => {
6066
const llmId = useFetchModelId();
6167

@@ -114,8 +120,17 @@ export const useInitializeOperatorParams = () => {
114120
}, [llmId]);
115121

116122
const initializeOperatorParams = useCallback(
117-
(operatorName: Operator) => {
118-
return initialFormValuesMap[operatorName];
123+
(operatorName: Operator, position: Position) => {
124+
const initialValues = initialFormValuesMap[operatorName];
125+
if (isBottomSubAgent(operatorName, position)) {
126+
return {
127+
...initialValues,
128+
description: 'This is an agent for a specific task.',
129+
user_prompt: 'This is the order you need to send to the agent.',
130+
};
131+
}
132+
133+
return initialValues;
119134
},
120135
[initialFormValuesMap],
121136
);
@@ -235,13 +250,6 @@ function useAddToolNode() {
235250
return { addToolNode };
236251
}
237252

238-
function isBottomSubAgent(type: string, position: Position) {
239-
return (
240-
(type === Operator.Agent && position === Position.Bottom) ||
241-
type === Operator.Tool
242-
);
243-
}
244-
245253
function useResizeIterationNode() {
246254
const { getNode, nodes, updateNode } = useGraphStore((state) => state);
247255

@@ -324,7 +332,7 @@ export function useAddNode(reactFlowInstance?: ReactFlowInstance<any, any>) {
324332
getNodeName(type),
325333
nodes,
326334
),
327-
form: initializeOperatorParams(type as Operator),
335+
form: initializeOperatorParams(type as Operator, params.position),
328336
},
329337
sourcePosition: Position.Right,
330338
targetPosition: Position.Left,

web/src/pages/profile-setting/mcp/mcp-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function McpCard({
3535
<section className="flex justify-between pb-2">
3636
<h3 className="text-lg font-semibold line-clamp-1">{data.name}</h3>
3737
<div className="space-x-4">
38-
<McpDropdown>
38+
<McpDropdown mcpId={data.id}>
3939
<MoreButton></MoreButton>
4040
</McpDropdown>
4141
<Checkbox

web/src/pages/profile-setting/mcp/mcp-dropdown.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,33 @@ import {
66
DropdownMenuSeparator,
77
DropdownMenuTrigger,
88
} from '@/components/ui/dropdown-menu';
9+
import { useDeleteMcpServer } from '@/hooks/use-mcp-request';
910
import { PenLine, Trash2 } from 'lucide-react';
1011
import { MouseEventHandler, PropsWithChildren, useCallback } from 'react';
1112
import { useTranslation } from 'react-i18next';
1213

13-
export function McpDropdown({ children }: PropsWithChildren) {
14+
export function McpDropdown({
15+
children,
16+
mcpId,
17+
}: PropsWithChildren & { mcpId: string }) {
1418
const { t } = useTranslation();
19+
const { deleteMcpServer } = useDeleteMcpServer();
1520

1621
const handleShowAgentRenameModal: MouseEventHandler<HTMLDivElement> =
1722
useCallback((e) => {
1823
e.stopPropagation();
1924
}, []);
2025

21-
const handleDelete: MouseEventHandler<HTMLDivElement> =
22-
useCallback(() => {}, []);
26+
const handleDelete: MouseEventHandler<HTMLDivElement> = useCallback(() => {
27+
deleteMcpServer([mcpId]);
28+
}, [deleteMcpServer, mcpId]);
2329

2430
return (
2531
<DropdownMenu>
2632
<DropdownMenuTrigger asChild>{children}</DropdownMenuTrigger>
2733
<DropdownMenuContent>
2834
<DropdownMenuItem onClick={handleShowAgentRenameModal}>
29-
{t('common.rename')} <PenLine />
35+
{t('common.edit')} <PenLine />
3036
</DropdownMenuItem>
3137
<DropdownMenuSeparator />
3238
<ConfirmDeleteDialog onOk={handleDelete}>

web/src/pages/profile-setting/mcp/use-bulk-operate-mcp.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import { useDeleteMcpServer } from '@/hooks/use-mcp-request';
12
import { Trash2, Upload } from 'lucide-react';
23
import { useCallback, useState } from 'react';
34
import { useTranslation } from 'react-i18next';
45

56
export function useBulkOperateMCP() {
67
const { t } = useTranslation();
78
const [selectedList, setSelectedList] = useState<Array<string>>([]);
9+
const { deleteMcpServer } = useDeleteMcpServer();
810

911
const handleEnableClick = useCallback(() => {}, []);
1012

11-
const handleDelete = useCallback(() => {}, []);
13+
const handleDelete = useCallback(() => {
14+
deleteMcpServer(selectedList);
15+
}, [deleteMcpServer, selectedList]);
1216

1317
const handleSelectChange = useCallback((id: string, checked: boolean) => {
1418
setSelectedList((list) => {

0 commit comments

Comments
 (0)