feat(mcp) : add business tools — search, history, comments, custom fields, documents, model types
- search_inventory: global search across all 6 entity types - get_entity_history + get_activity_log: audit trail access - 4 comment tools: list, create, resolve, unresolved count - 3 custom field tools: list values, upsert, delete - 2 document tools: list, delete (upload via REST only) - 6 model type tools: list, get, create, update, delete, sync - 69 MCP tests pass total Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
62
src/Mcp/Tool/Document/ListDocumentsTool.php
Normal file
62
src/Mcp/Tool/Document/ListDocumentsTool.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mcp\Tool\Document;
|
||||
|
||||
use App\Mcp\Tool\McpToolHelper;
|
||||
use App\Repository\DocumentRepository;
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
|
||||
#[McpTool(
|
||||
name: 'list_documents',
|
||||
description: 'List documents attached to a given entity. entityType must be one of: site, machine, composant, piece, product.',
|
||||
)]
|
||||
class ListDocumentsTool
|
||||
{
|
||||
use McpToolHelper;
|
||||
|
||||
private const ENTITY_FIELDS = [
|
||||
'site' => 'site',
|
||||
'machine' => 'machine',
|
||||
'composant' => 'composant',
|
||||
'piece' => 'piece',
|
||||
'product' => 'product',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly DocumentRepository $documents,
|
||||
) {}
|
||||
|
||||
public function __invoke(string $entityType, string $entityId): array
|
||||
{
|
||||
if (!isset(self::ENTITY_FIELDS[$entityType])) {
|
||||
$this->mcpError('validation', "Invalid entityType '{$entityType}'. Must be one of: site, machine, composant, piece, product.");
|
||||
}
|
||||
|
||||
$field = self::ENTITY_FIELDS[$entityType];
|
||||
|
||||
$docs = $this->documents->findBy([$field => $entityId], ['createdAt' => 'DESC']);
|
||||
|
||||
$items = [];
|
||||
foreach ($docs as $doc) {
|
||||
$items[] = [
|
||||
'id' => $doc->getId(),
|
||||
'name' => $doc->getName(),
|
||||
'filename' => $doc->getFilename(),
|
||||
'fileUrl' => '/api/documents/'.$doc->getId().'/file',
|
||||
'downloadUrl' => '/api/documents/'.$doc->getId().'/download',
|
||||
'mimeType' => $doc->getMimeType(),
|
||||
'size' => $doc->getSize(),
|
||||
'createdAt' => $doc->getCreatedAt()->format('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->jsonResponse([
|
||||
'entityType' => $entityType,
|
||||
'entityId' => $entityId,
|
||||
'items' => $items,
|
||||
'total' => count($items),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user