Files
Leantime/app/Domain/Bom/Tools/AddMasterColumnTool.php

56 lines
1.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Leantime\Domain\Bom\Tools;
use Laravel\Mcp\Server\Tool;
use Laravel\Mcp\Server\Tools\ToolInputSchema;
use Laravel\Mcp\Server\Tools\ToolResult;
use Leantime\Domain\Bom\Services\Bom;
/**
* 给主数据BOM/工艺文件/工具清单)添加一个动态列。
*/
class AddMasterColumnTool extends Tool
{
public function __construct(
private Bom $bomService,
) {}
public function name(): string
{
return 'addMasterColumn';
}
public function description(): string
{
return '给主数据BOM/工艺文件/工具清单添加一个动态列自定义字段。key 为存储标识英文或中文label 为显示名。';
}
public function schema(ToolInputSchema $schema): ToolInputSchema
{
return $schema
->integer('id')->description('主数据 ID。')->required()
->string('key')->description('列标识(英文或中文,用于存储)。')->required()
->string('label')->description('列显示名,默认同 key。');
}
public function handle(array $arguments): ToolResult
{
$id = (int) ($arguments['id'] ?? 0);
$key = (string) ($arguments['key'] ?? '');
$label = (string) ($arguments['label'] ?? $key);
if ($key === '') {
return ToolResult::error('key 不能为空');
}
$columnId = $this->bomService->addColumn($id, $key, $label);
if ($columnId > 0) {
return ToolResult::text("动态列添加成功:{$key}columnId {$columnId})。");
}
return ToolResult::error('添加列失败可能无权限、key 冲突固定列、或主数据不存在)。');
}
}