diff --git a/app/api/mcp/route.ts b/app/api/mcp/route.ts index d0d8d688..1ebf627b 100644 --- a/app/api/mcp/route.ts +++ b/app/api/mcp/route.ts @@ -2256,7 +2256,7 @@ async function toolAppsDomainsSet(principal: Principal, params: Record `https://${d}${port ? `:${port}` : ''}`) + .join(','); + // PHP code: load service, find target inner app by name (or auto-pick), + // set fqdn, save, regenerate compose, re-parse. All quoting carefully + // escaped because we shell this through ssh. + const phpCode = ` +$service = App\\Models\\Service::where('uuid', '${appUuid}')->first(); +if (!$service) { echo 'service-not-found'; exit; } +$apps = $service->applications()->get(); +$target = ${inner === 'auto' ? '$apps->first(fn($a) => !str_contains(strtolower($a->name), \'worker\') && !str_contains(strtolower($a->name), \'job\')) ?? $apps->first()' : `$apps->firstWhere('name', '${inner}')`}; +if (!$target) { echo 'inner-app-not-found'; exit; } +$target->fqdn = '${fqdnsForUrl}'; +$target->save(); +updateCompose($target); +$service->parse(); +echo 'fqdn-saved=' . $target->fresh()->fqdn; +`; + const result = await runOnCoolifyHost( + `docker exec coolify php artisan tinker --execute=${shellEscape(phpCode)}` + ); + const out = (result.stdout || '').trim(); + if (out.includes('service-not-found') || out.includes('inner-app-not-found')) { + return NextResponse.json({ + error: out, + stderr: result.stderr, + }, { status: 404 }); + } + return NextResponse.json({ + result: { + uuid: appUuid, + kind: 'service', + domains: normalized, + innerApp: inner, + tinkerOut: out, + summaryHint: `Custom domain saved on service ${appUuid}. Now call apps_deploy { uuid: "${appUuid}" } to regenerate Traefik labels and bring the new domain live.`, + }, + }); + } + + const app = await getApplicationInWorkspace(appUuid, ownedUuids); + const buildPack = (app.build_pack ?? 'nixpacks') as string; await setApplicationDomains(appUuid, normalized, { forceOverride: true, buildPack, @@ -2284,6 +2353,7 @@ async function toolAppsDomainsSet(principal: Principal, params: Record