Add Model Context Protocol server exposing Coolify infrastructure data to AI assistants. Includes tools for listing/fetching servers, projects, applications, databases, and services, scoped to authenticated team tokens. - Add CoolifyServer with 10 read-only tools (list/get for all resource types) - Add BuildsResponse and ResolvesTeam traits for shared tool logic - Add EnsureMcpEnabled middleware guarding /mcp routes - Add enable/disable MCP API endpoints (root-only) - Add is_mcp_server_enabled toggle in instance settings and advanced UI - Add migration for is_mcp_server_enabled column - Add feature tests for MCP endpoints and toggle API - Scrub sensitive keys (passwords, tokens, raw IDs) from all responses
68 lines
2 KiB
PHP
68 lines
2 KiB
PHP
<?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\Attributes\Description;
|
|
use Laravel\Mcp\Server\Attributes\Name;
|
|
use Laravel\Mcp\Server\Tool;
|
|
|
|
#[Name('list_services')]
|
|
#[Description('List services (multi-container stacks) owned by the authenticated team. Returns summary (uuid, name, status). Use get_service for full details.')]
|
|
class ListServices extends Tool
|
|
{
|
|
use BuildsResponse;
|
|
use ResolvesTeam;
|
|
|
|
public function handle(Request $request): Response
|
|
{
|
|
if ($error = $this->ensureAbility($request, 'read')) {
|
|
return $error;
|
|
}
|
|
|
|
$teamId = $this->resolveTeamId($request);
|
|
if (is_null($teamId)) {
|
|
return Response::error('Invalid token.');
|
|
}
|
|
|
|
$args = $this->paginationArgs($request);
|
|
|
|
$projects = Project::where('team_id', $teamId)->get();
|
|
$services = collect();
|
|
foreach ($projects as $project) {
|
|
$services = $services->merge($project->services()->get());
|
|
}
|
|
|
|
$total = $services->count();
|
|
|
|
$summaries = $services
|
|
->sortBy('name')
|
|
->slice($args['offset'], $args['per_page'])
|
|
->map(fn ($svc) => [
|
|
'uuid' => $svc->uuid,
|
|
'name' => $svc->name,
|
|
'status' => $svc->status ?? null,
|
|
])
|
|
->values()
|
|
->all();
|
|
|
|
return $this->respond(
|
|
$summaries,
|
|
[],
|
|
$this->paginationMeta('list_services', $args, $total),
|
|
);
|
|
}
|
|
|
|
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).'),
|
|
];
|
|
}
|
|
}
|