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:
57
src/Mcp/Tool/EntityHistoryTool.php
Normal file
57
src/Mcp/Tool/EntityHistoryTool.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mcp\Tool;
|
||||
|
||||
use App\Repository\AuditLogRepository;
|
||||
use DateTimeInterface;
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
#[McpTool(
|
||||
name: 'get_entity_history',
|
||||
description: 'Get the audit history for a specific entity (machine, piece, composant, product). Returns list of changes with diffs.',
|
||||
)]
|
||||
class EntityHistoryTool
|
||||
{
|
||||
use McpToolHelper;
|
||||
|
||||
private const VALID_TYPES = ['machine', 'piece', 'composant', 'product'];
|
||||
|
||||
public function __construct(
|
||||
private readonly AuditLogRepository $auditLogs,
|
||||
private readonly Security $security,
|
||||
) {}
|
||||
|
||||
public function __invoke(string $entityType, string $entityId): array
|
||||
{
|
||||
$this->requireRole($this->security, 'ROLE_VIEWER');
|
||||
|
||||
if (!in_array($entityType, self::VALID_TYPES, true)) {
|
||||
$this->mcpError('Validation', sprintf(
|
||||
'Invalid entityType "%s". Must be one of: %s',
|
||||
$entityType,
|
||||
implode(', ', self::VALID_TYPES),
|
||||
));
|
||||
}
|
||||
|
||||
$logs = $this->auditLogs->findEntityHistory($entityType, $entityId, 200);
|
||||
|
||||
$items = array_map(
|
||||
static fn ($log) => [
|
||||
'id' => $log->getId(),
|
||||
'action' => $log->getAction(),
|
||||
'diff' => $log->getDiff(),
|
||||
'actorProfileId' => $log->getActorProfileId(),
|
||||
'createdAt' => $log->getCreatedAt()->format(DateTimeInterface::ATOM),
|
||||
],
|
||||
$logs,
|
||||
);
|
||||
|
||||
return $this->jsonResponse([
|
||||
'items' => array_values($items),
|
||||
'total' => count($items),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user