feat(mcp): MCP 调用日志只读列表页

This commit is contained in:
augushong
2026-08-16 20:55:03 +08:00
parent 918d1d4dd5
commit 25c98b6ed6
6 changed files with 187 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
<?php
namespace base\admin\controller\system;
use app\admin\model\SystemMcpKey;
use app\admin\model\SystemMcpLog;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnotation;
use app\common\controller\AdminController;
use think\App;
/**
* MCP调用日志只读列表.
* 日志仅由系统写入,不提供 add/edit/read/modify
* 保留 delete 供清理旧日志。
*
* @ControllerAnnotation(title="MCP调用日志")
*/
class McpLogBase extends AdminController
{
protected $relationSearch = true;
protected $sort = [
'id' => 'desc',
];
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new SystemMcpLog();
// 密钥下拉搜索用SystemMcpKey 软删自动排除
$this->assign('select_list_mcp_key', SystemMcpKey::select(), true);
}
/**
* @NodeAnotation(title="列表")
*/
public function index()
{
if ($this->request->isAjax()) {
if (input('selectFields')) {
return $this->selectList();
}
list($page, $limit, $where) = $this->buildTableParames();
$count = $this->model
->withJoin('mcpKey', 'LEFT')
->where($where)
->count();
$list = $this->model
->withJoin('mcpKey', 'LEFT')
->where($where)
->page($page, $limit)
->order($this->sort)
->select();
$data = [
'code' => 0,
'msg' => '',
'count' => $count,
'data' => $list,
];
return json($data);
}
return $this->fetch();
}
/**
* @NodeAnotation(title="删除")
*/
public function delete($id)
{
$this->checkPostRequest();
$row = $this->model->whereIn('id', $id)->select();
$row->isEmpty() && $this->error('数据不存在');
try {
// 仅删除日志记录,不级联影响密钥表
$save = $row->delete();
} catch (\Exception $e) {
$this->error('删除失败:' . $e->getMessage());
}
$save ? $this->success('删除成功') : $this->error('删除失败');
}
}