2026-04-29 08:30:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Mcp\Tools;
|
|
|
|
|
|
|
|
|
|
use App\Mcp\Concerns\BuildsResponse;
|
|
|
|
|
use App\Mcp\Concerns\ResolvesTeam;
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
|
|
|
|
use Laravel\Mcp\Request;
|
|
|
|
|
use Laravel\Mcp\Response;
|
|
|
|
|
use Laravel\Mcp\Server\Tool;
|
|
|
|
|
|
|
|
|
|
class ListProjects extends Tool
|
|
|
|
|
{
|
2026-06-04 09:03:06 +00:00
|
|
|
protected string $name = 'list_projects';
|
|
|
|
|
|
|
|
|
|
protected string $description = 'List projects owned by the authenticated team. Returns summary (uuid, name, description).';
|
|
|
|
|
|
2026-04-29 08:30:43 +00:00
|
|
|
use BuildsResponse;
|
|
|
|
|
use ResolvesTeam;
|
|
|
|
|
|
|
|
|
|
public function handle(Request $request): Response
|
|
|
|
|
{
|
2026-06-04 09:03:06 +00:00
|
|
|
if ($error = $this->ensureAbility($request, 'read', $this->name)) {
|
2026-04-29 08:30:43 +00:00
|
|
|
return $error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$teamId = $this->resolveTeamId($request);
|
|
|
|
|
if (is_null($teamId)) {
|
2026-06-04 09:03:06 +00:00
|
|
|
return $this->mcpError($request, 'Invalid token.');
|
2026-04-29 08:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$args = $this->paginationArgs($request);
|
|
|
|
|
|
|
|
|
|
$query = Project::whereTeamId($teamId);
|
|
|
|
|
$total = (clone $query)->count();
|
|
|
|
|
|
|
|
|
|
$summaries = $query
|
|
|
|
|
->select('name', 'description', 'uuid')
|
|
|
|
|
->orderBy('name')
|
|
|
|
|
->skip($args['offset'])
|
|
|
|
|
->take($args['per_page'])
|
|
|
|
|
->get()
|
|
|
|
|
->map(fn ($p) => [
|
|
|
|
|
'uuid' => $p->uuid,
|
|
|
|
|
'name' => $p->name,
|
|
|
|
|
'description' => $p->description,
|
|
|
|
|
])
|
|
|
|
|
->values()
|
|
|
|
|
->all();
|
|
|
|
|
|
2026-06-04 09:03:06 +00:00
|
|
|
return $this->mcpSuccess($request, $this->respond(
|
2026-04-29 08:30:43 +00:00
|
|
|
$summaries,
|
|
|
|
|
[],
|
|
|
|
|
$this->paginationMeta('list_projects', $args, $total),
|
2026-06-04 09:03:06 +00:00
|
|
|
));
|
2026-04-29 08:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function schema(JsonSchema $schema): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'page' => $schema->integer()->description('Page number (default 1).'),
|
|
|
|
|
'per_page' => $schema->integer()->description('Items per page (default 50, max 100).'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|