Files
Leantime/app/Domain/Bom/Tools/GetMasterDetailTool.php
wangruiguo d647428529
Some checks failed
Security Audit / Composer Security Audit (push) Has been cancelled
Security Audit / NPM Security Audit (push) Has been cancelled
Security Audit / CodeQL Analysis (push) Has been cancelled
OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
2026-09-03 18:49:20 +08:00

78 lines
2.5 KiB
PHP
Raw 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 Illuminate\Support\Str;
use Laravel\Mcp\Server\Tool;
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
use Laravel\Mcp\Server\Tools\ToolInputSchema;
use Laravel\Mcp\Server\Tools\ToolResult;
use Leantime\Domain\Bom\Services\Bom;
/**
* 查看主数据(BOM/工艺文件/工具清单)详情:含固定列 + 动态列 + 明细行 + 数据源。
*/
#[IsReadOnly]
class GetMasterDetailTool extends Tool
{
public function __construct(
private Bom $bomService,
) {}
public function name(): string
{
return 'getMasterDetail';
}
public function description(): string
{
return '查看主数据(BOM/工艺文件/工具清单)的完整明细,含固定列、动态列、明细行、Teable 数据源。';
}
public function schema(ToolInputSchema $schema): ToolInputSchema
{
return $schema
->integer('id')->description('主数据 ID。')->required()
->integer('limit')->description('最多返回多少行明细,默认 50。');
}
public function handle(array $arguments): ToolResult
{
$id = (int) ($arguments['id'] ?? 0);
$limit = (int) ($arguments['limit'] ?? 50);
$detail = $this->bomService->getBomDetail($id);
if ($detail === false) {
return ToolResult::error("主数据不存在或无权访问:{$id}");
}
$bom = $detail['bom'] ?? [];
$columns = $detail['columns'] ?? [];
$items = $detail['items'] ?? [];
$result = [
'id' => (int) ($bom['id'] ?? 0),
'type' => (string) ($bom['type'] ?? 'bom'),
'bomNo' => (string) ($bom['bomNo'] ?? ''),
'productName' => Str::sanitizeForLLM((string) ($bom['productName'] ?? '')),
'version' => (string) ($bom['version'] ?? ''),
'columns' => array_map(fn ($c) => [
'key' => (string) $c['key'],
'label' => (string) ($c['label'] ?? $c['key']),
], $columns),
'itemCount' => count($items),
'items' => array_slice(array_map(function ($it) {
$row = [];
foreach ($it as $k => $v) {
if (is_scalar($v)) {
$row[$k] = Str::sanitizeForLLM((string) $v);
}
}
return $row;
}, $items), 0, $limit),
];
return ToolResult::json($result);
}
}