feat(workflow) : MCP - list-statuses projectId + list-workflows + switch-project-workflow + maj descriptions create/update-task
This commit is contained in:
@@ -24,7 +24,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
#[McpTool(name: 'create-task', description: 'Create a new task in a project. The task number is auto-generated. Use list-statuses, list-priorities, list-efforts, list-tags, list-groups to discover valid IDs.')]
|
#[McpTool(name: 'create-task', description: 'Create a new task in a project. The task number is auto-generated. Use list-statuses, list-priorities, list-efforts, list-tags, list-groups to discover valid IDs. The status parameter must reference a status that belongs to the target project\'s workflow — otherwise the call is rejected with a validation error.')]
|
||||||
class CreateTaskTool
|
class CreateTaskTool
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
#[McpTool(name: 'update-task', description: 'Update an existing task. Only provided fields are changed. Use list-statuses, list-priorities, etc. to discover valid IDs.')]
|
#[McpTool(name: 'update-task', description: 'Update an existing task. Only provided fields are changed. Use list-statuses, list-priorities, etc. to discover valid IDs. The status parameter must reference a status that belongs to the task\'s project workflow — otherwise the call is rejected with a validation error.')]
|
||||||
class UpdateTaskTool
|
class UpdateTaskTool
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|||||||
@@ -4,33 +4,49 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Mcp\Tool\TaskMeta;
|
namespace App\Mcp\Tool\TaskMeta;
|
||||||
|
|
||||||
|
use App\Entity\Project;
|
||||||
use App\Repository\TaskStatusRepository;
|
use App\Repository\TaskStatusRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Mcp\Capability\Attribute\McpTool;
|
use Mcp\Capability\Attribute\McpTool;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||||
|
|
||||||
#[McpTool(name: 'list-statuses', description: 'List all task statuses ordered by position. Statuses are global (shared across all projects). Use the returned IDs when creating or updating tasks.')]
|
#[McpTool(
|
||||||
|
name: 'list-statuses',
|
||||||
|
description: 'List task statuses. With projectId, returns only the statuses of that project\'s workflow. Without projectId, returns ALL statuses across workflows (use list-workflows to see how they group).',
|
||||||
|
)]
|
||||||
class ListStatusesTool
|
class ListStatusesTool
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly TaskStatusRepository $taskStatusRepository,
|
private readonly TaskStatusRepository $taskStatusRepository,
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
private readonly Security $security,
|
private readonly Security $security,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function __invoke(): string
|
public function __invoke(?int $projectId = null): string
|
||||||
{
|
{
|
||||||
if (!$this->security->isGranted('ROLE_USER')) {
|
if (!$this->security->isGranted('ROLE_USER')) {
|
||||||
throw new AccessDeniedException('Access denied: ROLE_USER required.');
|
throw new AccessDeniedException('Access denied: ROLE_USER required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$statuses = $this->taskStatusRepository->findBy([], ['position' => 'ASC']);
|
if (null !== $projectId) {
|
||||||
|
$project = $this->entityManager->find(Project::class, $projectId);
|
||||||
|
if (!$project) {
|
||||||
|
return json_encode(['error' => 'Project not found.']);
|
||||||
|
}
|
||||||
|
$statuses = $project->getWorkflow()->getStatuses()->toArray();
|
||||||
|
} else {
|
||||||
|
$statuses = $this->taskStatusRepository->findBy([], ['position' => 'ASC']);
|
||||||
|
}
|
||||||
|
|
||||||
return json_encode(array_map(fn ($s) => [
|
return json_encode(array_map(fn ($s) => [
|
||||||
'id' => $s->getId(),
|
'id' => $s->getId(),
|
||||||
'label' => $s->getLabel(),
|
'label' => $s->getLabel(),
|
||||||
'color' => $s->getColor(),
|
'color' => $s->getColor(),
|
||||||
'position' => $s->getPosition(),
|
'position' => $s->getPosition(),
|
||||||
'isFinal' => $s->getIsFinal(),
|
'isFinal' => $s->getIsFinal(),
|
||||||
|
'category' => $s->getCategory()->value,
|
||||||
|
'workflowId' => $s->getWorkflow()?->getId(),
|
||||||
], $statuses));
|
], $statuses));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/Mcp/Tool/Workflow/ListWorkflowsTool.php
Normal file
46
src/Mcp/Tool/Workflow/ListWorkflowsTool.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Mcp\Tool\Workflow;
|
||||||
|
|
||||||
|
use App\Repository\WorkflowRepository;
|
||||||
|
use Mcp\Capability\Attribute\McpTool;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||||
|
|
||||||
|
#[McpTool(
|
||||||
|
name: 'list-workflows',
|
||||||
|
description: 'List all workflows (status templates) with their statuses grouped under each workflow. Each project has one workflow that defines its kanban columns.',
|
||||||
|
)]
|
||||||
|
class ListWorkflowsTool
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly WorkflowRepository $workflowRepository,
|
||||||
|
private readonly Security $security,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function __invoke(): string
|
||||||
|
{
|
||||||
|
if (!$this->security->isGranted('ROLE_USER')) {
|
||||||
|
throw new AccessDeniedException('Access denied: ROLE_USER required.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$workflows = $this->workflowRepository->findBy([], ['position' => 'ASC']);
|
||||||
|
|
||||||
|
return json_encode(array_map(fn ($w) => [
|
||||||
|
'id' => $w->getId(),
|
||||||
|
'name' => $w->getName(),
|
||||||
|
'isDefault' => $w->isDefault(),
|
||||||
|
'position' => $w->getPosition(),
|
||||||
|
'statuses' => array_map(fn ($s) => [
|
||||||
|
'id' => $s->getId(),
|
||||||
|
'label' => $s->getLabel(),
|
||||||
|
'color' => $s->getColor(),
|
||||||
|
'position' => $s->getPosition(),
|
||||||
|
'isFinal' => $s->getIsFinal(),
|
||||||
|
'category' => $s->getCategory()->value,
|
||||||
|
], $w->getStatuses()->toArray()),
|
||||||
|
], $workflows));
|
||||||
|
}
|
||||||
|
}
|
||||||
65
src/Mcp/Tool/Workflow/SwitchProjectWorkflowTool.php
Normal file
65
src/Mcp/Tool/Workflow/SwitchProjectWorkflowTool.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Mcp\Tool\Workflow;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Post;
|
||||||
|
use App\Entity\Project;
|
||||||
|
use App\State\SwitchProjectWorkflowProcessor;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Mcp\Capability\Attribute\McpTool;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
#[McpTool(
|
||||||
|
name: 'switch-project-workflow',
|
||||||
|
description: 'Switch a project to another workflow. mapping must cover every status currently used by the project\'s tasks: keys are source status IDs (string), values are target status IDs in the new workflow (int) or null to send tasks to backlog. Requires ROLE_ADMIN. Returns { migratedTaskCount }.',
|
||||||
|
)]
|
||||||
|
class SwitchProjectWorkflowTool
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly SwitchProjectWorkflowProcessor $processor,
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
private readonly Security $security,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, null|int> $mapping
|
||||||
|
*/
|
||||||
|
public function __invoke(int $projectId, int $workflowId, array $mapping): string
|
||||||
|
{
|
||||||
|
if (!$this->security->isGranted('ROLE_ADMIN')) {
|
||||||
|
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$project = $this->entityManager->find(Project::class, $projectId);
|
||||||
|
if (!$project) {
|
||||||
|
return json_encode(['error' => 'Project not found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fakeRequest = Request::create('', 'POST', [], [], [], [], json_encode([
|
||||||
|
'workflowId' => $workflowId,
|
||||||
|
'mapping' => $mapping,
|
||||||
|
]));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$result = $this->processor->process(
|
||||||
|
$project,
|
||||||
|
operation: new Post(name: 'switch_workflow'),
|
||||||
|
uriVariables: ['id' => $projectId],
|
||||||
|
context: ['request' => $fakeRequest],
|
||||||
|
);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
return json_encode(['error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_encode([
|
||||||
|
'migratedTaskCount' => $result->migratedTaskCount,
|
||||||
|
'projectId' => $result->projectId,
|
||||||
|
'workflowId' => $result->workflowId,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user