Skip to content

Let's use AI to Earn!

mcp模块

daoyian0574d2ea12c5
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.tsx b/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.tsx
index 6fecb3fb..cd1e6017 100644
--- a/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.tsx
+++ b/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.tsx
@@ -19,10 +19,12 @@ import {
import { useShallow } from "zustand/react/shallow";
import { useAccountStore } from "@/store/account";
import UserManageModal, { IUserManageModalRef } from "./UserManageModal";
+import MCPManagerModal, { IMCPManagerModalRef } from "./MCPManagerModal";
import { AccountPlatInfoMap, PlatType } from "@/app/config/platConfig";
import { AccountStatus } from "@/app/config/accountConfig";
import { SocialAccount } from "@/api/types/account.type";
import { getOssUrl } from "@/utils/oss";
+import ChooseAccountModule from "@/components/ChooseAccountModule/ChooseAccountModule";
export interface IAccountSidebarRef {}
@@ -146,6 +148,8 @@ const AccountSidebar = memo(
);
const [userManageModalOpen, setUserManageModalOpen] = useState(false);
const userManageModalRef = useRef<IUserManageModalRef>(null);
+ const [mcpManagerModalOpen, setMcpManagerModalOpen] = useState(false);
+ const mcpManagerModalRef = useRef<IMCPManagerModalRef>(null);
// 在组件内部过滤账号列表,而不是在 useAccountStore 中过滤
const accountList = useMemo(() => {
@@ -165,6 +169,11 @@ const AccountSidebar = memo(
open={userManageModalOpen}
onCancel={() => setUserManageModalOpen(false)}
/>
+ <MCPManagerModal
+ ref={mcpManagerModalRef}
+ open={mcpManagerModalOpen}
+ onClose={setMcpManagerModalOpen}
+ />
{/*TODO 在线状态检测 */}
{/*<PubAccountDetModule*/}
{/* title="账号检测"*/}
@@ -199,6 +208,17 @@ const AccountSidebar = memo(
}}
></Button>
</Tooltip>
+ </div>
+ {/* mcp 按钮 */}
+ <div className="accountSidebar-top-box">
+ {/* 按钮蓝紫色渐变 */}
+ <Button
+ type="primary"
+ style={{background: 'linear-gradient(90deg, #625BF2 0%, #925BF2 100%)'}}
+ onClick={() => setMcpManagerModalOpen(true)}
+ >
+ MCP 管理器
+ </Button>
</div>
</div>
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.module.scss b/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.module.scss
new file mode 100644
index 00000000..2b3aef25
--- /dev/null
+++ b/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.module.scss
@@ -0,0 +1,114 @@
+.mcpManagerModal {
+ .mcpKeyList {
+ .ant-list-item {
+ border-radius: 8px;
+ margin-bottom: 8px;
+ border: 1px solid #f0f0f0;
+ transition: all 0.3s ease;
+
+ &:hover {
+ border-color: #625BF2;
+ box-shadow: 0 2px 8px rgba(98, 91, 242, 0.1);
+ }
+
+ .ant-list-item-meta {
+ .ant-list-item-meta-avatar {
+ .ant-avatar {
+ background: linear-gradient(90deg, #625BF2 0%, #925BF2 100%);
+ }
+ }
+
+ .ant-list-item-meta-content {
+ .ant-list-item-meta-title {
+ font-weight: 500;
+ margin-bottom: 4px;
+ }
+
+ .ant-list-item-meta-description {
+ .keyDisplay {
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
+ background: #f5f5f5;
+ padding: 4px 8px;
+ border-radius: 4px;
+ border: 1px solid #e8e8e8;
+ font-size: 12px;
+ color: #666;
+ word-break: break-all;
+ }
+
+ .keyInfo {
+ margin-top: 8px;
+ font-size: 12px;
+ color: #999;
+
+ .infoItem {
+ display: flex;
+ align-items: center;
+ margin-bottom: 2px;
+
+ .label {
+ margin-right: 8px;
+ min-width: 60px;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ .ant-list-item-actions {
+ .ant-btn-link {
+ color: #625BF2;
+
+ &:hover {
+ color: #925BF2;
+ }
+
+ &.ant-btn-dangerous {
+ color: #ff4d4f;
+
+ &:hover {
+ color: #ff7875;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ .createButton {
+ background: linear-gradient(90deg, #625BF2 0%, #925BF2 100%);
+ border: none;
+ border-radius: 6px;
+ height: 40px;
+ font-weight: 500;
+
+ &:hover {
+ background: linear-gradient(90deg, #5a54e8 0%, #8a54e8 100%);
+ transform: translateY(-1px);
+ box-shadow: 0 4px 12px rgba(98, 91, 242, 0.3);
+ }
+ }
+
+ .emptyState {
+ text-align: center;
+ padding: 40px 20px;
+ color: #999;
+
+ .emptyIcon {
+ font-size: 48px;
+ color: #d9d9d9;
+ margin-bottom: 16px;
+ }
+
+ .emptyText {
+ font-size: 14px;
+ margin-bottom: 8px;
+ }
+
+ .emptyDesc {
+ font-size: 12px;
+ color: #ccc;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx b/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx
new file mode 100644
index 00000000..bd863bec
--- /dev/null
+++ b/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx
@@ -0,0 +1,203 @@
+import React, { forwardRef, memo, useImperativeHandle, useRef, useState } from "react";
+import { Modal, Button, List, Avatar, Tag, Space, message, Empty } from "antd";
+import { PlusOutlined, CopyOutlined, DeleteOutlined, KeyOutlined } from "@ant-design/icons";
+import ChooseAccountModule from "@/components/ChooseAccountModule/ChooseAccountModule";
+import { SocialAccount } from "@/api/types/account.type";
+import { PubType } from "@/app/config/publishConfig";
+import styles from "./MCPManagerModal.module.scss";
+
+export interface IMCPManagerModalRef {
+ open: () => void;
+ close: () => void;
+}
+
+export interface IMCPManagerModalProps {
+ open: boolean;
+ onClose: (open: boolean) => void;
+}
+
+// MCP Key 接口类型
+interface MCPKey {
+ id: string;
+ name: string;
+ key: string;
+ accounts: SocialAccount[];
+ createdAt: string;
+ status: 'active' | 'inactive';
+}
+
+const MCPManagerModal = memo(
+ forwardRef<IMCPManagerModalRef, IMCPManagerModalProps>(
+ ({ open, onClose }, ref) => {
+ const [mcpKeys, setMcpKeys] = useState<MCPKey[]>([]);
+ const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
+ const [selectedAccounts, setSelectedAccounts] = useState<SocialAccount[]>([]);
+ const [newKeyName, setNewKeyName] = useState('');
+
+ // 模拟数据 - 实际应该从API获取
+ const mockMcpKeys: MCPKey[] = [
+ {
+ id: '1',
+ name: '默认MCP Key',
+ key: 'mcp_sk_1234567890abcdef',
+ accounts: [],
+ createdAt: '2024-01-15 10:30:00',
+ status: 'active'
+ },
+ {
+ id: '2',
+ name: '测试MCP Key',
+ key: 'mcp_sk_abcdef1234567890',
+ accounts: [],
+ createdAt: '2024-01-16 14:20:00',
+ status: 'active'
+ }
+ ];
+
+ // 初始化数据
+ React.useEffect(() => {
+ if (open) {
+ setMcpKeys(mockMcpKeys);
+ }
+ }, [open]);
+
+ const handleCreateKey = () => {
+ setIsCreateModalOpen(true);
+ };
+
+ const handleAccountConfirm = (accounts: SocialAccount[]) => {
+ setSelectedAccounts(accounts);
+ setIsCreateModalOpen(false);
+ // TODO: 调用创建MCP Key的API
+ message.success('MCP Key创建成功!');
+ };
+
+ const handleCopyKey = (key: string) => {
+ navigator.clipboard.writeText(key);
+ message.success('Key已复制到剪贴板');
+ };
+
+ const handleDeleteKey = (keyId: string) => {
+ setMcpKeys(prev => prev.filter(key => key.id !== keyId));
+ message.success('MCP Key已删除');
+ };
+
+ useImperativeHandle(ref, () => ({
+ open: () => onClose(true),
+ close: () => onClose(false),
+ }));
+
+ return (
+ <>
+ <Modal
+ title={
+ <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
+ <KeyOutlined style={{ color: '#625BF2' }} />
+ MCP 管理器
+ </div>
+ }
+ open={open}
+ onCancel={() => onClose(false)}
+ footer={null}
+ width={800}
+ className={styles.mcpManagerModal}
+ >
+ <div style={{ marginBottom: 16 }}>
+ <Button
+ type="primary"
+ icon={<PlusOutlined />}
+ onClick={handleCreateKey}
+ className={styles.createButton}
+ >
+ 创建新Key
+ </Button>
+ </div>
+
+ {mcpKeys.length === 0 ? (
+ <div className={styles.emptyState}>
+ <div className="emptyIcon">
+ <KeyOutlined />
+ </div>
+ <div className="emptyText">暂无MCP Key</div>
+ <div className="emptyDesc">点击上方按钮创建您的第一个MCP Key</div>
+ </div>
+ ) : (
+ <List
+ className={styles.mcpKeyList}
+ dataSource={mcpKeys}
+ renderItem={(item) => (
+ <List.Item
+ actions={[
+ <Button
+ key="copy"
+ type="link"
+ icon={<CopyOutlined />}
+ onClick={() => handleCopyKey(item.key)}
+ >
+ 复制
+ </Button>,
+ <Button
+ key="delete"
+ type="link"
+ danger
+ icon={<DeleteOutlined />}
+ onClick={() => handleDeleteKey(item.id)}
+ >
+ 删除
+ </Button>
+ ]}
+ >
+ <List.Item.Meta
+ avatar={<Avatar style={{ background: 'linear-gradient(90deg, #625BF2 0%, #925BF2 100%)' }}>MCP</Avatar>}
+ title={
+ <Space>
+ <span>{item.name}</span>
+ <Tag color={item.status === 'active' ? 'green' : 'red'}>
+ {item.status === 'active' ? '活跃' : '非活跃'}
+ </Tag>
+ </Space>
+ }
+ description={
+ <div>
+ <div className="keyDisplay">
+ {item.key}
+ </div>
+ <div className="keyInfo">
+ <div className="infoItem">
+ <span className="label">创建时间:</span>
+ <span>{item.createdAt}</span>
+ </div>
+ <div className="infoItem">
+ <span className="label">关联账户:</span>
+ <span>{item.accounts.length} 个</span>
+ </div>
+ </div>
+ </div>
+ }
+ />
+ </List.Item>
+ )}
+ />
+ )}
+ </Modal>
+
+ <ChooseAccountModule
+ open={isCreateModalOpen}
+ onClose={setIsCreateModalOpen}
+ onPlatConfirm={handleAccountConfirm}
+ platChooseProps={{
+ pubType: PubType.VIDEO, // 根据实际需要调整
+ choosedAccounts: selectedAccounts,
+ disableAllSelect: false,
+ isCancelChooseAccount: true,
+ }}
+ />
+ </>
+ );
+ }
+ )
+);
+
+MCPManagerModal.displayName = "MCPManagerModal";
+
+export default MCPManagerModal;
\ No newline at end of file