'site', 'machine' => 'machine', 'composant' => 'composant', 'piece' => 'piece', 'product' => 'product', ]; public function __construct( private readonly DocumentRepository $documents, ) {} public function __invoke(string $entityType, string $entityId): CallToolResult { 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), ]); } }