99626b89da
Ajoute 20 nouveaux outils MCP pour permettre à Claude (ou tout client MCP) de remplir un dossier client / prospect / prestataire complet — onglets Information, Contact, Adresse et Rapport — sans passer par l'UI. Entités couvertes (CRUD complet, 5 outils chacune) : - Prestataire : create / update / get / list / delete - Contact : create / update / get / list / delete - Address : create / update / get / list / delete - CommercialReport : create / update / get / list / delete Détails : - Contact / Address / CommercialReport doivent être rattachés à exactement un parent parmi clientId, prospectId, prestataireId (validation côté tool). - get-client, get-prospect et get-prestataire renvoient désormais un payload enrichi avec la liste de leurs contacts, adresses et rapports liés : un seul appel pour reconstruire l'onglet entier. - Pour CommercialReport, le type (note / call / meeting / email) et la date occurredAt sont validés ; l'auteur est rempli automatiquement par le listener existant. - Sécurité : ROLE_ADMIN aligné sur les autres outils MCP de Directory (pas de migration vers les permissions RBAC fines pour rester cohérent). Plumbing : - Repositories Contact / Address / CommercialReport : ajout de findBy() sur les interfaces (l'implémentation Doctrine l'a déjà via ServiceEntityRepository). - Bindings interface -> implémentation Doctrine ajoutés dans services.yaml pour Prestataire / Contact / Address / CommercialReport. - Sérialiseur partagé étendu : prestataire / contact / address / commercialReport / reportDocument. Vérification : 86 outils MCP exposés au total (66 avant + 20 ajoutés), test end-to-end via le transport HTTP (create-prestataire + create-contact + create-address + create-commercial-report + get-prestataire renvoyant le dossier complet). Suite PHPUnit verte. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
96 lines
3.6 KiB
PHP
96 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
|
|
|
|
use App\Module\Directory\Domain\Entity\Address;
|
|
use App\Module\Directory\Domain\Repository\ClientRepositoryInterface;
|
|
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
|
|
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
|
|
use App\Shared\Infrastructure\Mcp\Serializer;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use InvalidArgumentException;
|
|
use Mcp\Capability\Attribute\McpTool;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
|
|
use function sprintf;
|
|
|
|
#[McpTool(
|
|
name: 'create-address',
|
|
description: 'Create an address (admin) attached to exactly one of clientId / prospectId / prestataireId. Country defaults to FR (ISO 3166 alpha-2).'
|
|
)]
|
|
class CreateAddressTool
|
|
{
|
|
public function __construct(
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly ClientRepositoryInterface $clientRepository,
|
|
private readonly ProspectRepositoryInterface $prospectRepository,
|
|
private readonly PrestataireRepositoryInterface $prestataireRepository,
|
|
private readonly Security $security,
|
|
) {}
|
|
|
|
public function __invoke(
|
|
?int $clientId = null,
|
|
?int $prospectId = null,
|
|
?int $prestataireId = null,
|
|
?string $label = null,
|
|
?string $street = null,
|
|
?string $streetComplement = null,
|
|
?string $postalCode = null,
|
|
?string $city = null,
|
|
?string $country = null,
|
|
): string {
|
|
if (!$this->security->isGranted('ROLE_ADMIN')) {
|
|
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
|
|
}
|
|
|
|
$parents = array_filter([$clientId, $prospectId, $prestataireId], static fn ($v) => null !== $v);
|
|
if (1 !== count($parents)) {
|
|
throw new InvalidArgumentException('Exactly one of clientId, prospectId or prestataireId must be provided.');
|
|
}
|
|
|
|
$address = new Address();
|
|
|
|
if (null !== $clientId) {
|
|
$client = $this->clientRepository->findById($clientId);
|
|
if (null === $client) {
|
|
throw new InvalidArgumentException(sprintf('Client with ID %d not found.', $clientId));
|
|
}
|
|
$address->setClient($client);
|
|
}
|
|
if (null !== $prospectId) {
|
|
$prospect = $this->prospectRepository->findById($prospectId);
|
|
if (null === $prospect) {
|
|
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $prospectId));
|
|
}
|
|
$address->setProspect($prospect);
|
|
}
|
|
if (null !== $prestataireId) {
|
|
$prestataire = $this->prestataireRepository->findById($prestataireId);
|
|
if (null === $prestataire) {
|
|
throw new InvalidArgumentException(sprintf('Prestataire with ID %d not found.', $prestataireId));
|
|
}
|
|
$address->setPrestataire($prestataire);
|
|
}
|
|
|
|
$address->setLabel($label);
|
|
$address->setStreet($street);
|
|
$address->setStreetComplement($streetComplement);
|
|
$address->setPostalCode($postalCode);
|
|
$address->setCity($city);
|
|
if (null !== $country) {
|
|
if (2 !== strlen($country)) {
|
|
throw new InvalidArgumentException('country must be a 2-letter ISO 3166 alpha-2 code (e.g., FR, BE).');
|
|
}
|
|
$address->setCountry(strtoupper($country));
|
|
}
|
|
|
|
$this->entityManager->persist($address);
|
|
$this->entityManager->flush();
|
|
|
|
return json_encode(Serializer::address($address));
|
|
}
|
|
}
|