38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Mcp\Tool\Reference;
|
|
|
|
use App\Mcp\Tool\Serializer;
|
|
use App\Module\Core\Infrastructure\Doctrine\DoctrineUserRepository;
|
|
use InvalidArgumentException;
|
|
use Mcp\Capability\Attribute\McpTool;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
|
|
use function sprintf;
|
|
|
|
#[McpTool(name: 'get-user', description: 'Get a user by ID with full HR profile (employee flag, hire/end date, contract, work-time ratio, leave entitlement, reference period, family situation).')]
|
|
class GetUserTool
|
|
{
|
|
public function __construct(
|
|
private readonly DoctrineUserRepository $userRepository,
|
|
private readonly Security $security,
|
|
) {}
|
|
|
|
public function __invoke(int $id): string
|
|
{
|
|
if (!$this->security->isGranted('ROLE_ADMIN')) {
|
|
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
|
|
}
|
|
|
|
$user = $this->userRepository->find($id);
|
|
if (null === $user) {
|
|
throw new InvalidArgumentException(sprintf('User with ID %d not found.', $id));
|
|
}
|
|
|
|
return json_encode(Serializer::userFull($user));
|
|
}
|
|
}
|