This repository has been archived on 2026-03-09. You can view files and clone it, but cannot push or open issues or pull requests.
php-agentic/Mcp/Tools/Agent/Task/TaskToggle.php
Snider 6f0618692a
Some checks failed
CI / PHP 8.3 (push) Failing after 2s
CI / PHP 8.4 (push) Failing after 2s
feat: add plan/session/phase/task Actions + slim MCP tools
Extract business logic from MCP tool handlers into 15 Action classes
(Plan 5, Session 5, Phase 3, Task 2) following the Brain pattern.
MCP tools become thin wrappers calling Action::run(). Add framework-level
REST controllers and routes as sensible defaults for consumers.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-04 13:58:45 +00:00

84 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Agentic\Mcp\Tools\Agent\Task;
use Core\Mcp\Dependencies\ToolDependency;
use Core\Mod\Agentic\Actions\Task\ToggleTask;
use Core\Mod\Agentic\Mcp\Tools\Agent\AgentTool;
/**
* Toggle a task completion status.
*/
class TaskToggle extends AgentTool
{
protected string $category = 'task';
protected array $scopes = ['write'];
/**
* Get the dependencies for this tool.
*
* @return array<ToolDependency>
*/
public function dependencies(): array
{
return [
ToolDependency::entityExists('plan', 'Plan must exist', ['arg_key' => 'plan_slug']),
];
}
public function name(): string
{
return 'task_toggle';
}
public function description(): string
{
return 'Toggle a task completion status';
}
public function inputSchema(): array
{
return [
'type' => 'object',
'properties' => [
'plan_slug' => [
'type' => 'string',
'description' => 'Plan slug identifier',
],
'phase' => [
'type' => 'string',
'description' => 'Phase identifier (number or name)',
],
'task_index' => [
'type' => 'integer',
'description' => 'Task index (0-based)',
],
],
'required' => ['plan_slug', 'phase', 'task_index'],
];
}
public function handle(array $args, array $context = []): array
{
$workspaceId = $context['workspace_id'] ?? null;
if ($workspaceId === null) {
return $this->error('workspace_id is required');
}
try {
$result = ToggleTask::run(
$args['plan_slug'] ?? '',
$args['phase'] ?? '',
(int) ($args['task_index'] ?? 0),
(int) $workspaceId,
);
return $this->success($result);
} catch (\InvalidArgumentException $e) {
return $this->error($e->getMessage());
}
}
}