From adc10d1157262b235945ab981b14ae3ad10e13d9 Mon Sep 17 00:00:00 2001 From: augushong Date: Sun, 16 Aug 2026 23:33:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(mcp):=20MCP=20=E7=AE=A1=E7=90=86=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E4=B8=8E=E5=88=86=E5=8F=91=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20260816204000_system_mcp_menu_seed.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 database/migrations/20260816204000_system_mcp_menu_seed.php diff --git a/database/migrations/20260816204000_system_mcp_menu_seed.php b/database/migrations/20260816204000_system_mcp_menu_seed.php new file mode 100644 index 0000000..b5624e0 --- /dev/null +++ b/database/migrations/20260816204000_system_mcp_menu_seed.php @@ -0,0 +1,88 @@ +getAdapter()->getOption('table_prefix'); + $now = time(); + $rows = [ + [ + 'id' => 312, + 'title' => 'MCP密钥管理', + 'icon' => 'fa fa-key', + 'href' => 'system.mcp_key/index', + 'auth_node' => 'system.mcp_key/index', + ], + [ + 'id' => 313, + 'title' => 'MCP调用日志', + 'icon' => 'fa fa-file-text-o', + 'href' => 'system.mcp_log/index', + 'auth_node' => 'system.mcp_log/index', + ], + ]; + + foreach ($rows as $row) { + $href = $this->quoteLiteral($row['href']); + $exists = $this->fetchRow( + "SELECT `id` FROM `{$prefix}system_menu` WHERE `href` = {$href} AND `delete_time` = 0" + ); + if (!empty($exists)) { + continue; + } + + $sql = sprintf( + "INSERT INTO `%ssystem_menu` (`id`, `pid`, `title`, `icon`, `href`, `auth_node`, `params`, `target`, `sort`, `status`, `remark`, `create_time`, `update_time`, `delete_time`)" + . " VALUES (%d, 228, %s, %s, %s, %s, '', '_self', 0, 1, '', %d, %d, 0)", + $prefix, + $row['id'], + $this->quoteLiteral($row['title']), + $this->quoteLiteral($row['icon']), + $this->quoteLiteral($row['href']), + $this->quoteLiteral($row['auth_node']), + $now, + $now + ); + $this->execute($sql); + } + } + + public function down() + { + $prefix = $this->getAdapter()->getOption('table_prefix'); + $hrefs = implode(', ', [ + $this->quoteLiteral('system.mcp_key/index'), + $this->quoteLiteral('system.mcp_log/index'), + ]); + $this->execute("DELETE FROM `{$prefix}system_menu` WHERE `href` IN ({$hrefs})"); + } + + /** + * MySQL 字面量包装:单引号包裹 + 反斜杠转义(照 XhprofWatchSeed 惯例). + */ + private function quoteLiteral(string $value): string + { + return "'" . addcslashes($value, "\\") . "'"; + } +}