Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

3.4 KB
Raw Blame
/*
 *  Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import { SharedBadge } from '@/components/shared-badge';
import { Card, CardContent } from '@/components/ui/card';
import { Checkbox } from '@/components/ui/checkbox';
import { McpSelectionGuard } from '@/ee/pages/user-setting/mcp/mcp-selection-guard';
import { IMcpServer } from '@/interfaces/database/mcp';
import { formatDate } from '@/utils/date';
import { isPlainObject } from 'lodash';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { McpOperation } from './mcp-operation';
import { UseBulkOperateMCPReturnType } from './use-bulk-operate-mcp';
import { UseEditMcpReturnType } from './use-edit-mcp';

export type DatasetCardProps = {
  data: IMcpServer;
  isSelectionMode: boolean;
} & Pick<UseBulkOperateMCPReturnType, 'handleSelectChange' | 'selectedList'> &
  Pick<UseEditMcpReturnType, 'showEditModal'> & {
    showPrivilegeModal(): void;
  };

export function McpCard({
  data,
  selectedList,
  handleSelectChange,
  showEditModal,
  showPrivilegeModal,
  isSelectionMode,
}: DatasetCardProps) {
  const { t } = useTranslation();
  const toolLength = useMemo(() => {
    const tools = data.variables?.tools;
    if (isPlainObject(tools)) {
      return Object.keys(tools || {}).length;
    }
    return 0;
  }, [data.variables?.tools]);
  const onCheckedChange = (checked: boolean) => {
    if (typeof checked === 'boolean') {
      handleSelectChange(data.id, checked);
    }
  };

  return (
    <Card key={data.id}>
      <CardContent className="p-2.5 pt-2 group">
        <section className="flex justify-between pb-2">
          <h3 className="text-base font-normal truncate flex-1 text-text-primary">
            {data.name}
          </h3>
          <div className="space-x-4">
            {isSelectionMode ? (
              <McpSelectionGuard mcp={data}>
                <Checkbox
                  checked={selectedList.includes(data.id)}
                  onCheckedChange={onCheckedChange}
                  onClick={(e) => {
                    e.stopPropagation();
                  }}
                />
              </McpSelectionGuard>
            ) : (
              <McpOperation
                mcp={data}
                showEditModal={showEditModal}
                showPrivilegeModal={showPrivilegeModal}
              />
            )}
          </div>
        </section>
        <div className="flex justify-between items-end text-xs text-text-secondary">
          <div className="w-full">
            <div className="line-clamp-1 pb-1">
              {toolLength} {t('mcp.cachedTools')}
            </div>
            <section className="flex items-center justify-between">
              <p>{formatDate(data.update_date)}</p>
              <SharedBadge>{data?.nickname}</SharedBadge>
            </section>
          </div>
        </div>
      </CardContent>
    </Card>
  );
}