feat(mcp): MCP 密钥管理后台(CURD 重组 Base/App,密钥仅创建时明文展示)

This commit is contained in:
augushong
2026-08-16 20:55:02 +08:00
parent 15a6f2d841
commit 918d1d4dd5
15 changed files with 593 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
use think\migration\Migrator;
class SystemMcpKey extends Migrator
{
/**
* MCP密钥表.
*
* 明文密钥永不出现在本表:
* - key 存 SHA-256 哈希char 64唯一索引
* - key_prefix 存明文前 16 位char 16展示用
*/
public function change()
{
$table = $this->table('system_mcp_key')
->setComment('MCP密钥表')
->addColumn('title', 'char', ['limit' => 50, 'null' => true, 'comment' => '密钥名称'])
->addColumn('key', 'char', ['limit' => 64, 'null' => true, 'comment' => '密钥SHA-256哈希'])
->addColumn('key_prefix', 'char', ['limit' => 16, 'null' => true, 'default' => '', 'comment' => '密钥前缀(展示用)'])
->addColumn('bind_admin_id', 'biginteger', ['limit' => 11, 'null' => true, 'signed' => false, 'comment' => '绑定创建者ID'])
->addColumn('status', 'integer', ['limit' => 11, 'null' => true, 'default' => 1, 'comment' => '状态 {radio} (0:禁用,1:启用)'])
->addColumn('remark', 'char', ['limit' => 255, 'null' => true, 'default' => '', 'comment' => ''])
->addColumn('use_num', 'biginteger', ['limit' => 11, 'null' => true, 'default' => 0, 'signed' => false, 'comment' => '调用次数'])
->addColumn('last_use_time', 'integer', ['limit' => 11, 'null' => true, 'default' => 0, 'signed' => false, 'comment' => '最后使用时间'])
->addColumn('create_time', 'integer', ['limit' => 11, 'null' => true, 'default' => 0, 'signed' => false, 'comment' => '创建时间'])
->addColumn('update_time', 'integer', ['limit' => 11, 'null' => true, 'default' => 0, 'signed' => false, 'comment' => '更新时间'])
->addColumn('delete_time', 'integer', ['limit' => 11, 'null' => true, 'default' => 0, 'signed' => false, 'comment' => '删除时间'])
->addIndex(['key'], ['unique' => true, 'name' => 'key'])
->addIndex(['delete_time'], ['name' => 'delete_time'])
->create();
}
}

View File

@@ -0,0 +1,21 @@
<?php
use think\migration\Migrator;
class SystemMcpKeyNode extends Migrator
{
/**
* MCP密钥与节点关系表.
*
* 纯关系表:无任何时间戳字段。
*/
public function change()
{
$table = $this->table('system_mcp_key_node')
->setComment('MCP密钥与节点关系表')
->addColumn('key_id', 'biginteger', ['limit' => 11, 'null' => true, 'signed' => false, 'comment' => '密钥ID'])
->addColumn('node', 'char', ['limit' => 100, 'null' => true, 'default' => '', 'comment' => ''])
->addIndex(['key_id'], ['name' => 'key_id'])
->create();
}
}

View File

@@ -0,0 +1,25 @@
<?php
use think\migration\Migrator;
class SystemMcpLog extends Migrator
{
/**
* MCP调用日志表.
*
* 仅 create_time写入后不变无 update_time / delete_time。
*/
public function change()
{
$table = $this->table('system_mcp_log')
->setComment('MCP调用日志表')
->addColumn('key_id', 'biginteger', ['limit' => 11, 'null' => true, 'signed' => false, 'comment' => '密钥ID'])
->addColumn('node', 'char', ['limit' => 100, 'null' => true, 'comment' => '调用节点'])
->addColumn('arguments', 'text', ['null' => true, 'comment' => '参数摘要JSON'])
->addColumn('is_success', 'integer', ['limit' => 1, 'null' => true, 'default' => 1, 'comment' => '是否成功:0=失败,1=成功'])
->addColumn('cost_ms', 'integer', ['limit' => 11, 'null' => true, 'default' => 0, 'comment' => '耗时毫秒'])
->addColumn('create_time', 'integer', ['limit' => 11, 'null' => true, 'default' => 0, 'signed' => false, 'comment' => '创建时间'])
->addIndex(['key_id'], ['name' => 'key_id'])
->create();
}
}