File size: 2,201 Bytes
f0743f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from 'react';
import UninitializedMCPTool from './UninitializedMCPTool';
import UnconfiguredMCPTool from './UnconfiguredMCPTool';
import { useAgentPanelContext } from '~/Providers';
import { useLocalize } from '~/hooks';
import MCPTool from './MCPTool';

export default function MCPTools({
  agentId,
  mcpServerNames,
  setShowMCPToolDialog,
}: {
  agentId: string;
  mcpServerNames?: string[];
  setShowMCPToolDialog: React.Dispatch<React.SetStateAction<boolean>>;
}) {
  const localize = useLocalize();
  const { mcpServersMap } = useAgentPanelContext();

  return (
    <div className="mb-4">
      <label className="text-token-text-primary mb-2 block font-medium">
        {localize('com_ui_mcp_servers')}
      </label>
      <div>
        <div className="mb-1">
          {/* Render servers with selected tools */}
          {mcpServerNames?.map((mcpServerName) => {
            const serverInfo = mcpServersMap.get(mcpServerName);
            if (!serverInfo?.isConfigured) {
              return (
                <UnconfiguredMCPTool
                  key={`${mcpServerName}-${agentId}`}
                  serverName={mcpServerName}
                />
              );
            }
            if (!serverInfo) {
              return null;
            }

            if (serverInfo.isConnected) {
              return (
                <MCPTool key={`${serverInfo.serverName}-${agentId}`} serverInfo={serverInfo} />
              );
            }

            return (
              <UninitializedMCPTool
                key={`${serverInfo.serverName}-${agentId}`}
                serverInfo={serverInfo}
              />
            );
          })}
        </div>
        <div className="mt-2">
          <button
            type="button"
            onClick={() => setShowMCPToolDialog(true)}
            className="btn btn-neutral border-token-border-light relative h-9 w-full rounded-lg font-medium"
            aria-haspopup="dialog"
          >
            <div className="flex w-full items-center justify-center gap-2">
              {localize('com_assistants_add_mcp_server_tools')}
            </div>
          </button>
        </div>
      </div>
    </div>
  );
}