payment1
This commit is contained in:
+297
-84
@@ -2,13 +2,14 @@
|
||||
namespace app\mcp;
|
||||
|
||||
use PhpMcp\Server\Server;
|
||||
use PhpMcp\Server\ServerBuilder;
|
||||
use PhpMcp\Server\Transports\StdioServerTransport;
|
||||
use PhpMcp\Server\Transports\StreamableHttpServerTransport;
|
||||
use PhpMcp\Server\Transports\HttpServerTransport;
|
||||
use PhpMcp\Server\Attributes\McpTool;
|
||||
use PhpMcp\Server\Attributes\McpResource;
|
||||
use PhpMcp\Server\Attributes\McpPrompt;
|
||||
use PhpMcp\Server\Attributes\Schema;
|
||||
use PhpMcp\Server\Defaults\BasicContainer;
|
||||
use PhpMcp\Schema\Tool;
|
||||
use PhpMcp\Schema\Resource;
|
||||
use PhpMcp\Schema\ToolAnnotations;
|
||||
use PhpMcp\Schema\Annotations;
|
||||
use think\facade\Db;
|
||||
use support\Log;
|
||||
|
||||
@@ -116,14 +117,21 @@ class McpService
|
||||
{
|
||||
// 确保 logger 不为 null
|
||||
try {
|
||||
// 尝试获取 mcp 通道
|
||||
$this->logger = Log::channel('mcp');
|
||||
if (!$this->logger) {
|
||||
// 如果 mcp 通道不存在,使用默认通道
|
||||
$this->logger = Log::channel('default');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// 如果所有通道都失败,创建一个简单的 logger
|
||||
$this->logger = Log::channel('default');
|
||||
try {
|
||||
// 如果 mcp 通道不存在,尝试使用默认通道
|
||||
$this->logger = Log::channel('default');
|
||||
} catch (\Throwable $e) {
|
||||
// 如果所有通道都失败,创建一个简单的 logger
|
||||
$this->logger = new class {
|
||||
public function info($message, $context = []) {}
|
||||
public function error($message, $context = []) {}
|
||||
public function warning($message, $context = []) {}
|
||||
public function addRecord($level, $message, $context = []) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 读取MCP配置文件
|
||||
@@ -193,18 +201,24 @@ class McpService
|
||||
$this->heartbeatInterval = $mcpConfig['heartbeat_interval'];
|
||||
}
|
||||
|
||||
Log::channel('mcp')->info('MCP配置加载成功', [
|
||||
'timeout' => $this->timeout,
|
||||
'connect_timeout' => $this->connectTimeout,
|
||||
'read_timeout' => $this->readTimeout,
|
||||
'retry_attempts' => $this->retryAttempts,
|
||||
'retry_delay' => $this->retryDelay,
|
||||
'heartbeat_enabled' => $this->heartbeatEnabled ?? false,
|
||||
'heartbeat_interval' => $this->heartbeatInterval ?? 30
|
||||
]);
|
||||
// 安全地记录日志
|
||||
if (method_exists($this->logger, 'info')) {
|
||||
$this->logger->info('MCP配置加载成功', [
|
||||
'timeout' => $this->timeout,
|
||||
'connect_timeout' => $this->connectTimeout,
|
||||
'read_timeout' => $this->readTimeout,
|
||||
'retry_attempts' => $this->retryAttempts,
|
||||
'retry_delay' => $this->retryDelay,
|
||||
'heartbeat_enabled' => $this->heartbeatEnabled ?? false,
|
||||
'heartbeat_interval' => $this->heartbeatInterval ?? 30
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::warning('MCP配置加载失败,使用默认配置: ' . $e->getMessage());
|
||||
// 安全地记录警告
|
||||
if (method_exists($this->logger, 'warning')) {
|
||||
$this->logger->warning('MCP配置加载失败,使用默认配置: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,29 +305,44 @@ class McpService
|
||||
while ($attempts < $this->retryAttempts) {
|
||||
try {
|
||||
$attempts++;
|
||||
Log::channel('mcp')->info("执行{$operationName},第{$attempts}次尝试");
|
||||
// 安全地记录日志
|
||||
if (method_exists($this->logger, 'info')) {
|
||||
$this->logger->info("执行{$operationName},第{$attempts}次尝试");
|
||||
}
|
||||
|
||||
$result = $operation();
|
||||
|
||||
if ($attempts > 1) {
|
||||
Log::channel('mcp')->info("{$operationName}在第{$attempts}次尝试后成功");
|
||||
// 安全地记录日志
|
||||
if (method_exists($this->logger, 'info')) {
|
||||
$this->logger->info("{$operationName}在第{$attempts}次尝试后成功");
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$lastException = $e;
|
||||
Log::warning("{$operationName}第{$attempts}次尝试失败: " . $e->getMessage());
|
||||
// 安全地记录警告
|
||||
if (method_exists($this->logger, 'warning')) {
|
||||
$this->logger->warning("{$operationName}第{$attempts}次尝试失败: " . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($attempts < $this->retryAttempts) {
|
||||
$delay = $this->retryDelay * pow(1.5, $attempts - 1); // 指数退避
|
||||
Log::channel('mcp')->info("等待{$delay}ms后重试");
|
||||
// 安全地记录日志
|
||||
if (method_exists($this->logger, 'info')) {
|
||||
$this->logger->info("等待{$delay}ms后重试");
|
||||
}
|
||||
usleep($delay * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log::channel('mcp')->error("{$operationName}在{$this->retryAttempts}次尝试后仍然失败");
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error("{$operationName}在{$this->retryAttempts}次尝试后仍然失败");
|
||||
}
|
||||
throw $lastException;
|
||||
}
|
||||
|
||||
@@ -343,27 +372,11 @@ class McpService
|
||||
}
|
||||
|
||||
$this->server = $builder->withContainer($container)
|
||||
->withTool([self::class, 'handleDbQuery'], 'db-query', '执行数据库查询操作(仅支持SELECT语句)')
|
||||
->withTool([self::class, 'handleSysConfig'], 'sys-config', '获取系统配置信息')
|
||||
->withTool([self::class, 'handleWriteLog'], 'write-log', '写入系统日志')
|
||||
->withTool([self::class, 'handleFileOperation'], 'file-operation', '文件读写操作')
|
||||
->withTool([self::class, 'handleUserManagement'], 'user-management', '用户管理相关操作')
|
||||
->withTool([self::class, 'handleSystemInfo'], 'system-info', '获取系统运行信息')
|
||||
->withTool([self::class, 'handleCreateController'], 'controller', '生成webman控制器文件')
|
||||
->withTool([self::class, 'handleCreateModel'], 'model', '生成webman模型文件')
|
||||
->withTool([self::class, 'handleCreateView'], 'view', '生成webman视图文件')
|
||||
->withTool([self::class, 'handleCreateJs'], 'js', '生成webman JS文件')
|
||||
->withTool([self::class, 'handleCreateApi'], 'api', '生成webman API接口文件')
|
||||
->withTool([self::class, 'handleCurd'], 'curd', '生成webman CURD模块')
|
||||
->withTool([self::class, 'handleAddon'], 'addon', '生成webman 插件模块')
|
||||
->withTool([self::class, 'handleMenu'], 'menu', '生成webman 菜单模块')
|
||||
->withTool([self::class, 'handleCreateTable'], 'table', '创建数据库表格, 支持字段信息、类型、注释等')
|
||||
->withTool([self::class, 'handleThinkCommand'], 'think-command', '执行webman框架命令')
|
||||
->withTool([self::class, 'handleMcpCommand'], 'mcp-command', '执行MCP专用命令')
|
||||
->withTool([self::class, 'handleWebmanCommand'], 'webman-command', '执行webman框架命令')
|
||||
->withPrompt([self::class, 'handleWithPrompt'], 'with-prompt', '通过自然语言描述生成数据库表、控制器、模型等')
|
||||
->withResource([self::class, 'handleConfigResource'], 'config://system', 'config-system', '系统配置信息资源', 'application/json')
|
||||
->withResource([self::class, 'handleSchemaResource'], 'schema://database', 'schema-database', '数据库表结构信息资源', 'application/json')
|
||||
// 使用属性发现自动注册工具、资源和提示
|
||||
->discover(
|
||||
basePath: __DIR__ . '/..',
|
||||
scanDirs: ['mcp']
|
||||
)
|
||||
->build();
|
||||
return $this->server;
|
||||
}
|
||||
@@ -376,7 +389,13 @@ class McpService
|
||||
* @param array $params 查询参数
|
||||
* @return array
|
||||
*/
|
||||
public function handleDbQuery(string $query, array $params = []): array
|
||||
#[McpTool(name: 'db-query', description: '执行数据库查询操作(仅支持SELECT语句)')]
|
||||
public function handleDbQuery(
|
||||
#[Schema(type: 'string', description: 'SQL查询语句')]
|
||||
string $query,
|
||||
#[Schema(type: 'array', description: '查询参数')]
|
||||
array $params = []
|
||||
): array
|
||||
{
|
||||
try {
|
||||
if (empty($query)) {
|
||||
@@ -400,7 +419,10 @@ class McpService
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP数据库查询错误: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP数据库查询错误: ' . $e->getMessage());
|
||||
}
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
@@ -413,7 +435,11 @@ class McpService
|
||||
* @param string $key 配置键名(可选)
|
||||
* @return array
|
||||
*/
|
||||
public function handleSysConfig(string $key = ''): array
|
||||
#[McpTool(name: 'sys-config', description: '获取系统配置信息')]
|
||||
public function handleSysConfig(
|
||||
#[Schema(type: 'string', description: '配置键名(可选)')]
|
||||
string $key = ''
|
||||
): array
|
||||
{
|
||||
try {
|
||||
if (empty($key)) {
|
||||
@@ -451,7 +477,15 @@ class McpService
|
||||
* @param array $context 上下文数据
|
||||
* @return string
|
||||
*/
|
||||
public function handleWriteLog(string $message, string $level = 'info', array $context = []): string
|
||||
#[McpTool(name: 'write-log', description: '写入系统日志')]
|
||||
public function handleWriteLog(
|
||||
#[Schema(type: 'string', description: '日志消息')]
|
||||
string $message,
|
||||
#[Schema(type: 'string', description: '日志级别')]
|
||||
string $level = 'info',
|
||||
#[Schema(type: 'array', description: '上下文数据')]
|
||||
array $context = []
|
||||
): string
|
||||
{
|
||||
try {
|
||||
if (empty($message)) {
|
||||
@@ -469,7 +503,10 @@ class McpService
|
||||
return "日志记录成功 [级别: {$level}]";
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP日志写入错误: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP日志写入错误: ' . $e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -480,7 +517,13 @@ class McpService
|
||||
* @param string $filepath 文件路径
|
||||
* @return array
|
||||
*/
|
||||
public function handleFileOperation(string $operation, string $filepath): array
|
||||
#[McpTool(name: 'file-operation', description: '文件读写操作')]
|
||||
public function handleFileOperation(
|
||||
#[Schema(type: 'string', description: '操作类型')]
|
||||
string $operation,
|
||||
#[Schema(type: 'string', description: '文件路径')]
|
||||
string $filepath
|
||||
): array
|
||||
{
|
||||
try {
|
||||
if (empty($operation) || empty($filepath)) {
|
||||
@@ -541,7 +584,10 @@ class McpService
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP文件操作错误: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP文件操作错误: ' . $e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -553,7 +599,15 @@ class McpService
|
||||
* @param int $limit 返回数量限制(可选)
|
||||
* @return array
|
||||
*/
|
||||
public function handleUserManagement(string $action, int $userId = 0, int $limit = 10): array
|
||||
#[McpTool(name: 'user-management', description: '用户管理相关操作')]
|
||||
public function handleUserManagement(
|
||||
#[Schema(type: 'string', description: '操作类型')]
|
||||
string $action,
|
||||
#[Schema(type: 'integer', description: '用户ID(可选)')]
|
||||
int $userId = 0,
|
||||
#[Schema(type: 'integer', description: '返回数量限制(可选)')]
|
||||
int $limit = 10
|
||||
): array
|
||||
{
|
||||
try {
|
||||
switch ($action) {
|
||||
@@ -599,7 +653,10 @@ class McpService
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP用户管理错误: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP用户管理错误: ' . $e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -609,7 +666,11 @@ class McpService
|
||||
* @param string $type 信息类型
|
||||
* @return array
|
||||
*/
|
||||
public function handleSystemInfo(string $type = 'general'): array
|
||||
#[McpTool(name: 'system-info', description: '获取系统运行信息')]
|
||||
public function handleSystemInfo(
|
||||
#[Schema(type: 'string', description: '信息类型')]
|
||||
string $type = 'general'
|
||||
): array
|
||||
{
|
||||
try {
|
||||
switch ($type) {
|
||||
@@ -661,7 +722,10 @@ class McpService
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP系统信息错误: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP系统信息错误: ' . $e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -688,6 +752,7 @@ class McpService
|
||||
* 处理配置资源
|
||||
* @return string
|
||||
*/
|
||||
#[McpResource(uri: 'config://system', name: 'config-system', description: '系统配置信息资源', contentType: 'application/json')]
|
||||
public function handleConfigResource(): string
|
||||
{
|
||||
$configs = [
|
||||
@@ -709,6 +774,7 @@ class McpService
|
||||
* 处理数据库模式资源
|
||||
* @return string
|
||||
*/
|
||||
#[McpResource(uri: 'schema://database', name: 'schema-database', description: '数据库表结构信息资源', contentType: 'application/json')]
|
||||
public function handleSchemaResource(): string
|
||||
{
|
||||
try {
|
||||
@@ -727,7 +793,10 @@ class McpService
|
||||
return json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP数据库模式获取错误: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP数据库模式获取错误: ' . $e->getMessage());
|
||||
}
|
||||
return json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
@@ -772,11 +841,17 @@ class McpService
|
||||
$server = $this->buildServer();
|
||||
$transport = new StdioServerTransport();
|
||||
|
||||
Log::channel('mcp')->info('MCP STDIO服务器启动成功');
|
||||
// 安全地记录日志
|
||||
if (method_exists($this->logger, 'info')) {
|
||||
$this->logger->info('MCP STDIO服务器启动成功');
|
||||
}
|
||||
$server->listen($transport);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP STDIO服务器启动失败: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP STDIO服务器启动失败: ' . $e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -793,10 +868,16 @@ class McpService
|
||||
$server = $this->buildServer();
|
||||
$server->listen($transport);
|
||||
|
||||
Log::channel('mcp')->info('MCP服务器启动成功');
|
||||
// 安全地记录日志
|
||||
if (method_exists($this->logger, 'info')) {
|
||||
$this->logger->info('MCP服务器启动成功');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP服务器启动失败: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP服务器启动失败: ' . $e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -811,13 +892,19 @@ class McpService
|
||||
$this->startHeartbeat();
|
||||
|
||||
$server = $this->buildServer();
|
||||
$transport = new \PhpMcp\Server\Transports\StreamableHttpServerTransport($host, $port, $mcpPath);
|
||||
$transport = new StreamableHttpServerTransport($host, $port, $mcpPath);
|
||||
|
||||
Log::channel('mcp')->info("MCP SSE服务器启动成功,监听地址: http://{$host}:{$port}/{$mcpPath}");
|
||||
// 安全地记录日志
|
||||
if (method_exists($this->logger, 'info')) {
|
||||
$this->logger->info("MCP SSE服务器启动成功,监听地址: http://{$host}:{$port}/{$mcpPath}");
|
||||
}
|
||||
$server->listen($transport);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP SSE服务器启动失败: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP SSE服务器启动失败: ' . $e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -832,13 +919,19 @@ class McpService
|
||||
$this->startHeartbeat();
|
||||
|
||||
$server = $this->buildServer();
|
||||
$transport = new \PhpMcp\Server\Transports\HttpServerTransport($host, $port, $mcpPath);
|
||||
$transport = new HttpServerTransport($host, $port, $mcpPath);
|
||||
|
||||
Log::channel('mcp')->info("MCP HTTP服务器启动成功,监听地址: http://{$host}:{$port}/{$mcpPath}");
|
||||
// 安全地记录日志
|
||||
if (method_exists($this->logger, 'info')) {
|
||||
$this->logger->info("MCP HTTP服务器启动成功,监听地址: http://{$host}:{$port}/{$mcpPath}");
|
||||
}
|
||||
$server->listen($transport);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::channel('mcp')->error('MCP HTTP服务器启动失败: ' . $e->getMessage());
|
||||
// 安全地记录错误
|
||||
if (method_exists($this->logger, 'error')) {
|
||||
$this->logger->error('MCP HTTP服务器启动失败: ' . $e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -877,7 +970,17 @@ class McpService
|
||||
* @param string $description 控制器描述 (可选)
|
||||
* @return array
|
||||
*/
|
||||
public function handleCreateController(string $module, string $controller, array $fields = [], string $description = ''): array
|
||||
#[McpTool(name: 'controller', description: '生成webman控制器文件')]
|
||||
public function handleCreateController(
|
||||
#[Schema(type: 'string', description: '模块名称 (admin/api/frontend等)')]
|
||||
string $module,
|
||||
#[Schema(type: 'string', description: '控制器名称')]
|
||||
string $controller,
|
||||
#[Schema(type: 'array', description: '字段信息 (可选)')]
|
||||
array $fields = [],
|
||||
#[Schema(type: 'string', description: '控制器描述 (可选)')]
|
||||
string $description = ''
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 生成控制器类名
|
||||
@@ -934,7 +1037,17 @@ class McpService
|
||||
* @param string $description 模型描述 (可选)
|
||||
* @return array
|
||||
*/
|
||||
public function handleCreateModel(string $modelName, array $fields = [], string $tableName = '', string $description = ''): array
|
||||
#[McpTool(name: 'model', description: '生成webman模型文件')]
|
||||
public function handleCreateModel(
|
||||
#[Schema(type: 'string', description: '模型名称')]
|
||||
string $modelName,
|
||||
#[Schema(type: 'array', description: '字段信息 (可选)')]
|
||||
array $fields = [],
|
||||
#[Schema(type: 'string', description: '表名 (可选,默认使用模型名)')]
|
||||
string $tableName = '',
|
||||
#[Schema(type: 'string', description: '模型描述 (可选)')]
|
||||
string $description = ''
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 生成模型类名
|
||||
@@ -1078,7 +1191,19 @@ class {$modelClass} extends Base
|
||||
* @param string $charset 字符集 (默认 utf8mb4)
|
||||
* @return array
|
||||
*/
|
||||
public function handleCreateTable(string $tableName, array $fields, string $tableComment = '', string $engine = 'InnoDB', string $charset = 'utf8mb4'): array
|
||||
#[McpTool(name: 'table', description: '创建数据库表格,支持字段信息、类型、注释等')]
|
||||
public function handleCreateTable(
|
||||
#[Schema(type: 'string', description: '表名')]
|
||||
string $tableName,
|
||||
#[Schema(type: 'array', description: '字段信息数组')]
|
||||
array $fields,
|
||||
#[Schema(type: 'string', description: '表注释')]
|
||||
string $tableComment = '',
|
||||
#[Schema(type: 'string', description: '存储引擎 (默认 InnoDB)')]
|
||||
string $engine = 'InnoDB',
|
||||
#[Schema(type: 'string', description: '字符集 (默认 utf8mb4)')]
|
||||
string $charset = 'utf8mb4'
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 验证表名
|
||||
@@ -1293,7 +1418,19 @@ class {$modelClass} extends Base
|
||||
* @param array $options 其他选项
|
||||
* @return array
|
||||
*/
|
||||
public function handleCurd(string $tableName, string $module = 'admin', array $fields = [], string $description = '', array $options = []): array
|
||||
#[McpTool(name: 'curd', description: '生成webman CURD模块')]
|
||||
public function handleCurd(
|
||||
#[Schema(type: 'string', description: '表名')]
|
||||
string $tableName,
|
||||
#[Schema(type: 'string', description: '模块名称 (默认 admin)')]
|
||||
string $module = 'admin',
|
||||
#[Schema(type: 'array', description: '字段信息 (可选)')]
|
||||
array $fields = [],
|
||||
#[Schema(type: 'string', description: '描述 (可选)')]
|
||||
string $description = '',
|
||||
#[Schema(type: 'array', description: '选项 (可选)')]
|
||||
array $options = []
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 构建命令行参数
|
||||
@@ -1359,7 +1496,15 @@ class {$modelClass} extends Base
|
||||
* @param array $options 其他选项
|
||||
* @return array
|
||||
*/
|
||||
public function handleAddon(string $action, string $addonName = '', array $options = []): array
|
||||
#[McpTool(name: 'addon', description: '生成webman 插件模块')]
|
||||
public function handleAddon(
|
||||
#[Schema(type: 'string', description: '操作类型')]
|
||||
string $action,
|
||||
#[Schema(type: 'string', description: '插件名称 (可选)')]
|
||||
string $addonName = '',
|
||||
#[Schema(type: 'array', description: '选项 (可选)')]
|
||||
array $options = []
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 构建命令行参数
|
||||
@@ -1459,7 +1604,15 @@ class {$modelClass} extends Base
|
||||
* @param array $options 其他选项
|
||||
* @return array
|
||||
*/
|
||||
public function handleMenu(string $action, array $menuData = [], array $options = []): array
|
||||
#[McpTool(name: 'menu', description: '生成webman 菜单模块')]
|
||||
public function handleMenu(
|
||||
#[Schema(type: 'string', description: '操作类型')]
|
||||
string $action,
|
||||
#[Schema(type: 'array', description: '菜单数据 (可选)')]
|
||||
array $menuData = [],
|
||||
#[Schema(type: 'array', description: '选项 (可选)')]
|
||||
array $options = []
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 构建命令行参数
|
||||
@@ -1533,7 +1686,13 @@ class {$modelClass} extends Base
|
||||
* @param string $type 生成类型 (table/controller/model/js/api/view/all)
|
||||
* @return array
|
||||
*/
|
||||
public function handleWithPrompt(string $prompt, string $type = 'all'): array
|
||||
#[McpPrompt(name: 'with-prompt', description: '通过自然语言描述生成数据库表、控制器、模型等')]
|
||||
public function handleWithPrompt(
|
||||
#[Schema(type: 'string', description: '自然语言描述')]
|
||||
string $prompt,
|
||||
#[Schema(type: 'string', description: '生成类型')]
|
||||
string $type = 'all'
|
||||
): array
|
||||
{
|
||||
try {
|
||||
if (empty($prompt)) {
|
||||
@@ -2181,11 +2340,21 @@ class {$modelClass} extends Base
|
||||
* @param string $description 描述 (可选)
|
||||
* @return array
|
||||
*/
|
||||
public function handleCreateJs(string $module, string $controller, array $fields = [], string $description = ''): array
|
||||
#[McpTool(name: 'js', description: '生成webman JS文件')]
|
||||
public function handleCreateJs(
|
||||
#[Schema(type: 'string', description: '模块名称')]
|
||||
string $module,
|
||||
#[Schema(type: 'string', description: 'JS文件名')]
|
||||
string $name,
|
||||
#[Schema(type: 'array', description: 'JS数据 (可选)')]
|
||||
array $data = [],
|
||||
#[Schema(type: 'string', description: 'JS描述 (可选)')]
|
||||
string $description = ''
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 生成JS文件名
|
||||
$jsFileName = strtolower($controller);
|
||||
$jsFileName = strtolower($name);
|
||||
|
||||
$jsPath = "plugin/admin/public/js/{$jsFileName}.js";
|
||||
if ($module == 'frontend') {
|
||||
@@ -2200,7 +2369,7 @@ class {$modelClass} extends Base
|
||||
}
|
||||
|
||||
// 生成JS内容
|
||||
$jsContent = $this->generateJsContent($module, $controller, $fields, $description);
|
||||
$jsContent = $this->generateJsContent($module, $name, $data, $description);
|
||||
|
||||
// 确保目录存在
|
||||
$dir = dirname($jsPath);
|
||||
@@ -2238,7 +2407,17 @@ class {$modelClass} extends Base
|
||||
* @param string $description 描述 (可选)
|
||||
* @return array
|
||||
*/
|
||||
public function handleCreateApi(string $controller, string $module = 'api', array $fields = [], string $description = ''): array
|
||||
#[McpTool(name: 'api', description: '生成webman API接口文件')]
|
||||
public function handleCreateApi(
|
||||
#[Schema(type: 'string', description: '控制器名称')]
|
||||
string $controller,
|
||||
#[Schema(type: 'string', description: '模块名称 (默认 api)')]
|
||||
string $module = 'api',
|
||||
#[Schema(type: 'array', description: '字段信息 (可选)')]
|
||||
array $fields = [],
|
||||
#[Schema(type: 'string', description: 'API描述 (可选)')]
|
||||
string $description = ''
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 生成API控制器类名
|
||||
@@ -2455,7 +2634,17 @@ class {$modelClass} extends Base
|
||||
* @param string $description 描述 (可选)
|
||||
* @return array
|
||||
*/
|
||||
public function handleCreateView(string $module, string $controller, array $fields = [], string $description = ''): array
|
||||
#[McpTool(name: 'view', description: '生成webman视图文件')]
|
||||
public function handleCreateView(
|
||||
#[Schema(type: 'string', description: '模块名称')]
|
||||
string $module,
|
||||
#[Schema(type: 'string', description: '控制器名称')]
|
||||
string $controller,
|
||||
#[Schema(type: 'array', description: '字段信息 (可选)')]
|
||||
array $fields = [],
|
||||
#[Schema(type: 'string', description: '视图描述 (可选)')]
|
||||
string $description = ''
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 生成视图文件名
|
||||
@@ -3143,7 +3332,15 @@ class {$modelClass} extends Base
|
||||
* @param array $options 命令选项 (可选)
|
||||
* @return array
|
||||
*/
|
||||
public function handleThinkCommand(string $command, array $params = [], array $options = []): array
|
||||
#[McpTool(name: 'think-command', description: '执行webman框架命令')]
|
||||
public function handleThinkCommand(
|
||||
#[Schema(type: 'string', description: '命令名称')]
|
||||
string $command,
|
||||
#[Schema(type: 'array', description: '命令参数 (可选)')]
|
||||
array $params = [],
|
||||
#[Schema(type: 'array', description: '命令选项 (可选)')]
|
||||
array $options = []
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// 验证命令是否为安全的内置命令
|
||||
@@ -3283,7 +3480,15 @@ class {$modelClass} extends Base
|
||||
* @param array $options 选项
|
||||
* @return array
|
||||
*/
|
||||
public function handleMcpCommand(string $command, array $params = [], array $options = []): array
|
||||
#[McpTool(name: 'mcp-command', description: '执行MCP专用命令')]
|
||||
public function handleMcpCommand(
|
||||
#[Schema(type: 'string', description: '命令名称')]
|
||||
string $command,
|
||||
#[Schema(type: 'array', description: '命令参数 (可选)')]
|
||||
array $params = [],
|
||||
#[Schema(type: 'array', description: '命令选项 (可选)')]
|
||||
array $options = []
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// MCP 专用命令列表
|
||||
@@ -3374,7 +3579,15 @@ class {$modelClass} extends Base
|
||||
* @param array $options 选项
|
||||
* @return array
|
||||
*/
|
||||
public function handleWebmanCommand(string $command, array $params = [], array $options = []): array
|
||||
#[McpTool(name: 'webman-command', description: '执行webman框架命令')]
|
||||
public function handleWebmanCommand(
|
||||
#[Schema(type: 'string', description: '命令名称')]
|
||||
string $command,
|
||||
#[Schema(type: 'array', description: '命令参数 (可选)')]
|
||||
array $params = [],
|
||||
#[Schema(type: 'array', description: '命令选项 (可选)')]
|
||||
array $options = []
|
||||
): array
|
||||
{
|
||||
try {
|
||||
// webman 框架命令列表
|
||||
|
||||
Reference in New Issue
Block a user