hostinger-api-mcp 4.15.2 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +31 -6
  3. package/gemini-extension.json +1 -1
  4. package/package.json +1 -1
  5. package/server.json +2 -2
  6. package/skills/headless/SKILL.md +23 -0
  7. package/skills/headless/VERSION +2 -2
  8. package/skills/headless/local-server.mjs +64 -0
  9. package/skills/headless/processes.mjs +62 -0
  10. package/skills/headless/report.schema.json +16 -0
  11. package/skills/headless/run-log.mjs +27 -54
  12. package/skills/headless/servers.mjs +169 -0
  13. package/skills/headless/steps/06-frontend/SKILL.md +3 -1
  14. package/skills/headless/steps/06-frontend/bring-your-own-frontend.md +5 -0
  15. package/skills/headless/steps/07-validate/SKILL.md +5 -4
  16. package/skills/headless/steps/09-done/SKILL.md +3 -0
  17. package/skills/headless/workspace.mjs +28 -0
  18. package/src/core/runtime.js +1 -1
  19. package/src/core/runtime.ts +1 -1
  20. package/src/core/skills.js +49 -21
  21. package/src/core/skills.ts +49 -21
  22. package/src/core/tools/all.js +39 -4
  23. package/src/core/tools/all.ts +39 -4
  24. package/src/core/tools/horizons.js +39 -4
  25. package/src/core/tools/horizons.ts +39 -4
  26. package/src/servers/agency-hosting.js +1 -1
  27. package/src/servers/agency-hosting.ts +1 -1
  28. package/src/servers/agent-readiness.js +1 -1
  29. package/src/servers/agent-readiness.ts +1 -1
  30. package/src/servers/all.js +1 -1
  31. package/src/servers/all.ts +1 -1
  32. package/src/servers/billing.js +1 -1
  33. package/src/servers/billing.ts +1 -1
  34. package/src/servers/dns.js +1 -1
  35. package/src/servers/dns.ts +1 -1
  36. package/src/servers/domains.js +1 -1
  37. package/src/servers/domains.ts +1 -1
  38. package/src/servers/ecommerce.js +1 -1
  39. package/src/servers/ecommerce.ts +1 -1
  40. package/src/servers/gpu.js +1 -1
  41. package/src/servers/gpu.ts +1 -1
  42. package/src/servers/horizons.js +1 -1
  43. package/src/servers/horizons.ts +1 -1
  44. package/src/servers/hosting.js +1 -1
  45. package/src/servers/hosting.ts +1 -1
  46. package/src/servers/mail.js +1 -1
  47. package/src/servers/mail.ts +1 -1
  48. package/src/servers/reach.js +1 -1
  49. package/src/servers/reach.ts +1 -1
  50. package/src/servers/vps.js +1 -1
  51. package/src/servers/vps.ts +1 -1
  52. package/src/servers/wordpress.js +1 -1
  53. package/src/servers/wordpress.ts +1 -1
  54. package/types.d.ts +39 -4
@@ -0,0 +1,169 @@
1
+ // The local dev and preview servers a Headless build starts, recorded in <workspace>/servers.json so
2
+ // the run can stop them when it ends. local-server.mjs is the agent's command for it; run-log.mjs
3
+ // stops them at run-start and report.
4
+
5
+ import { spawn } from 'node:child_process';
6
+ import { closeSync, mkdirSync, openSync, readFileSync } from 'node:fs';
7
+ import { createServer } from 'node:net';
8
+ import { join } from 'node:path';
9
+ import { groupAlive, processTable, signalGroup } from './processes.mjs';
10
+ import { now, writeJsonAtomic } from './workspace.mjs';
11
+
12
+ // Statuses after which a server is known to be down. Any other (starting, running, still_running,
13
+ // not_verified) may still be running, so a later stop tries it again.
14
+ const DOWN = ['stopped', 'already_gone'];
15
+ export const isDown = (server) => DOWN.includes(server.status);
16
+ const STOP_GRACE_MS = 5000;
17
+ const KILL_GRACE_MS = 2000;
18
+ const START_ATTEMPTS = 3;
19
+
20
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
21
+ const serversPath = (dir) => join(dir, 'servers.json');
22
+
23
+ // Merges fields into this server's record; servers.json keeps every server the domain started, so a
24
+ // pid alone may match an old one.
25
+ function updateServer(dir, server, fields) {
26
+ const same = (s) => s.pid === server.pid && s.started_at === server.started_at;
27
+ writeJsonAtomic(serversPath(dir), readServers(dir).map((s) => (same(s) ? { ...s, ...fields } : s)));
28
+ }
29
+
30
+ function readServers(dir) {
31
+ try {
32
+ const servers = JSON.parse(readFileSync(serversPath(dir), 'utf8'));
33
+ return Array.isArray(servers) ? servers : [];
34
+ } catch {
35
+ return [];
36
+ }
37
+ }
38
+
39
+ const STATUS_TEXT = { stopped: 'stopped', already_gone: 'already gone', still_running: 'still running', not_verified: 'could not be confirmed stopped' };
40
+ export const describeServer = (s) => `port ${s.port} (pid ${s.pid}, ${s.command}): ${STATUS_TEXT[s.status] ?? s.status}`;
41
+
42
+ // The servers started since `since` (a run's started_at), as the build report shows them.
43
+ export const serversSince = (dir, since) => readServers(dir)
44
+ .filter((s) => s.started_at >= since)
45
+ .map(({ pid, port, command, started_at, stopped_at, status }) => ({ pid, port, command, started_at, stopped_at: stopped_at ?? null, status }));
46
+
47
+ // Whether something listens on the port, on any address.
48
+ const portBusy = (port) => new Promise((resolve) => {
49
+ const probe = createServer();
50
+ probe.once('error', (error) => resolve(error.code === 'EADDRINUSE'));
51
+ probe.listen(port, () => probe.close(() => resolve(false)));
52
+ });
53
+
54
+ // A port the system has just handed out is free, unless another program takes it before the server
55
+ // binds it: startServer retries then. One rule for every framework, as Next.js has no port auto-increment.
56
+ const freePort = () => new Promise((resolve, reject) => {
57
+ const probe = createServer();
58
+ probe.once('error', reject);
59
+ probe.listen(0, () => {
60
+ const { port } = probe.address();
61
+ probe.close(() => resolve(port));
62
+ });
63
+ });
64
+
65
+ async function gone(pid, ms) {
66
+ for (const until = Date.now() + ms; Date.now() < until; await sleep(100)) if (!groupAlive(pid)) return true;
67
+ return !groupAlive(pid);
68
+ }
69
+
70
+ // A recorded PID now held by a process with another start time was reused: it isn't ours, so it is
71
+ // left alone. Without a start time to compare (no process list), the group is stopped only while the
72
+ // port is still bound.
73
+ async function stopOne(server, table) {
74
+ if (!groupAlive(server.pid)) return 'already_gone';
75
+ const leader = table?.get(server.pid);
76
+ if (leader && server.started && leader.started !== server.started) return 'already_gone';
77
+ if ((!table || !server.started) && !(await portBusy(server.port))) return 'not_verified';
78
+ signalGroup(server.pid, 'SIGTERM');
79
+ return (await gone(server.pid, STOP_GRACE_MS)) ? 'stopped' : kill(server.pid);
80
+ }
81
+
82
+ async function kill(pid) {
83
+ signalGroup(pid, 'SIGKILL');
84
+ return (await gone(pid, KILL_GRACE_MS)) ? 'stopped' : 'still_running';
85
+ }
86
+
87
+ // Stops every server recorded in the workspace that may still be running, and returns those it tried.
88
+ // One session builds a domain at a time (run-log.mjs's lock), so whatever is recorded here belongs to
89
+ // this session or to one that is gone; servers elsewhere (the user's own, other domains) are never
90
+ // looked at.
91
+ export async function stopServers(dir) {
92
+ const servers = readServers(dir);
93
+ const live = servers.filter((s) => !isDown(s));
94
+ if (!live.length) return [];
95
+ const table = processTable();
96
+ for (const server of live) {
97
+ server.status = await stopOne(server, table);
98
+ server.stopped_at = now();
99
+ }
100
+ writeJsonAtomic(serversPath(dir), servers);
101
+ return live;
102
+ }
103
+
104
+ // Resolves once the port answers HTTP (any status), or with why the server exited or ran out of time.
105
+ async function serving(child, port, timeoutMs) {
106
+ let exited = null;
107
+ child.once('exit', (code, signal) => (exited = `exited with ${signal ?? `code ${code}`}`));
108
+ child.once('error', (error) => (exited = `could not start: ${error.message}`));
109
+ for (const until = Date.now() + timeoutMs; Date.now() < until; await sleep(250)) {
110
+ if (exited) return exited;
111
+ // Astro and Vite listen on localhost, which may be IPv6 only; Next.js listens on every address.
112
+ for (const host of ['127.0.0.1', '[::1]']) {
113
+ try {
114
+ await fetch(`http://${host}:${port}/`, { redirect: 'manual', signal: AbortSignal.timeout(2000) });
115
+ return null;
116
+ } catch {}
117
+ }
118
+ }
119
+ return exited ?? `did not answer on port ${port} within ${timeoutMs / 1000}s`;
120
+ }
121
+
122
+ const tail = (file) => readFileSync(file, 'utf8').trim().split('\n').slice(-15).join('\n');
123
+
124
+ // Spawns the command on the port, logging to servers/<port>.log, and records it as starting before
125
+ // anyone waits on it, so it is still stopped when start is killed mid-wait. Without a process list
126
+ // (no start time) a stop only stops it once it binds its port. server is null when it didn't spawn.
127
+ function launch(dir, command, port) {
128
+ const [program, ...args] = command.map((a) => a.replaceAll('{port}', String(port)));
129
+ const project = process.cwd();
130
+ const log = join(dir, 'servers', `${port}.log`);
131
+ const out = openSync(log, 'w');
132
+ // Its own process group (detached), so a stop reaches npx, the framework and its workers alike.
133
+ // ASTRO_PREVIEW_BACKGROUND keeps `astro preview` in the foreground under an agent, so the recorded
134
+ // pid is the real server. Windows starts npx and npm through .cmd shims, which need a shell.
135
+ const child = spawn(program, args, {
136
+ cwd: project,
137
+ detached: true,
138
+ stdio: ['ignore', out, out],
139
+ env: { ...process.env, PORT: String(port), ASTRO_PREVIEW_BACKGROUND: '1' },
140
+ shell: process.platform === 'win32',
141
+ windowsHide: true,
142
+ });
143
+ closeSync(out);
144
+ if (!child.pid) return { child, server: null, log };
145
+ const started = processTable()?.get(child.pid)?.started ?? null;
146
+ const server = { pid: child.pid, started, port, command: [program, ...args].join(' '), cwd: project, log, started_at: now(), status: 'starting' };
147
+ writeJsonAtomic(serversPath(dir), [...readServers(dir), server]);
148
+ return { child, server, log };
149
+ }
150
+
151
+ // Starts `command` from the current folder on a free port and records it, replacing the servers this
152
+ // domain already runs, since a running server keeps serving the build it started with.
153
+ export async function startServer(dir, command, { timeoutMs }) {
154
+ await stopServers(dir);
155
+ mkdirSync(join(dir, 'servers'), { recursive: true });
156
+ for (let attempt = 1; ; attempt += 1) {
157
+ const port = await freePort();
158
+ const { child, server, log } = launch(dir, command, port);
159
+ const error = await serving(child, port, timeoutMs);
160
+ if (!error) {
161
+ child.unref();
162
+ updateServer(dir, server, { status: 'running' });
163
+ return { ok: true, url: `http://localhost:${port}/`, port, pid: child.pid, log };
164
+ }
165
+ if (server) updateServer(dir, server, { status: await kill(server.pid), stopped_at: now() });
166
+ if (attempt < START_ATTEMPTS && /EADDRINUSE/.test(tail(log))) continue;
167
+ return { ok: false, error: `the server ${error}`, log, log_tail: tail(log) };
168
+ }
169
+ }
@@ -148,7 +148,9 @@ built. Update `state.json` (`stage: "validate"`).
148
148
  Validate (Step 7) owns the clean rebuild + user preview; deploy (Step 8) ships it with the `app_type`
149
149
  and output directory that match the chosen framework + rendering.
150
150
 
151
- **Visual check.** With the site running locally against the live backend, look at the home page and one
151
+ **Visual check.** After `npm run build`, start the site locally against the live backend with
152
+ `local-server.mjs`, as *Local servers* in the top-level `SKILL.md` shows, and open the `url` it prints.
153
+ After a fix, rebuild and start it again. Look at the home page and one
152
154
  page of each template (e.g. a post, a product, the contact page) at desktop and phone width. Take all the
153
155
  screenshots first, then open them all in one turn where your tool can open several images at once, since
154
156
  each separate look costs a model turn. Don't tile several pages onto one image or take one tall
@@ -11,3 +11,8 @@ the user's direction (vibe-code with them). Your job is to connect it to the liv
11
11
  `wp/v2` reads, the WooCommerce/Ecommerce Store API, env/keys) and make it deployable (set
12
12
  `engines.node` to `22`, remove any `.htaccess`), then hand off to deploy. This generalises the Webapp
13
13
  "existing app" case in `SKILL.md` to WordPress and Ecommerce too.
14
+
15
+ Run their dev or preview server only through `local-server.mjs` (top-level `SKILL.md`, *Local
16
+ servers*), from their project folder, so the run stops it when it ends: put `{port}` where their script
17
+ takes a port (`node <skill>/local-server.mjs start <domain> -- npm run dev -- --port {port}`), or leave it
18
+ out when the framework reads `PORT`. Never stop or reuse a server the user already had running.
@@ -92,11 +92,12 @@ fixtures, placeholder copy or `.htaccess` in the output).
92
92
 
93
93
  ## 5 — Preview & approval (optional — only when a person is signing off)
94
94
 
95
- When someone wants to see it first: start the local preview (Astro: `npm run preview`; Next.js:
96
- `npx next start`), show the user a couple of key routes at desktop and phone width (capture phone width
95
+ When someone wants to see it first: start the local preview with `local-server.mjs`, as *Local
96
+ servers* in the top-level `SKILL.md` shows, and give the user the `url` it prints. It stays up while you
97
+ wait for their answer; the run's report stops it. Show the user a couple of key routes at desktop and phone width (capture phone width
97
98
  as in frontend's *Visual check*; frontend already caught the layout bugs, so this is for the user, not a
98
- re-review) and navigation, and present it for **explicit approval**. If preview tooling is unavailable,
99
- give the user the command and URL. On an autonomous or temp-domain run, skip this — deploy will verify the live result anyway.
99
+ re-review) and navigation, and present it for **explicit approval**. If the preview won't start,
100
+ give the user the command to run it themselves. On an autonomous or temp-domain run, skip this — deploy will verify the live result anyway.
100
101
 
101
102
  Then (after approval, or immediately if 4–5 were skipped): `state.json` → `stage: "deploy"`, fresh
102
103
  `updated_at`; leave `provision` unchanged.
@@ -207,6 +207,9 @@ the flow." On a 422 say it's saved locally only; on any other failure say it'll
207
207
  a stage that was never logged. Fix what you can: `stage-end` an open stage, or correct a start with
208
208
  `stage-fix <stage> --started-ago <time>`, then run `report` again. What you can't fix stays in the report's
209
209
  *Logging gaps* section.
210
+ - `report` also stops the local servers this run started. Each `server not stopped:` line it prints
211
+ names one it couldn't confirm stopped: tell the user in one line its port and pid, so they can stop
212
+ it.
210
213
  - In the final report's *Where state lives*, add the path to `report.html` so the user can open it.
211
214
 
212
215
  Do this on every run, including the early stops: those reports are the most useful ones.
@@ -0,0 +1,28 @@
1
+ // The folder a Headless build keeps for a domain, ~/.hostinger/<domain>, shared by the scripts that
2
+ // write there (run-log.mjs, local-server.mjs).
3
+
4
+ import { existsSync, mkdirSync, renameSync, writeFileSync } from 'node:fs';
5
+ import { homedir } from 'node:os';
6
+ import { join } from 'node:path';
7
+
8
+ // A domain names a folder under ~/.hostinger, so "../x" or "a/b" must never reach the file system.
9
+ const HOSTNAME = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/i;
10
+
11
+ export const now = () => new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
12
+
13
+ // The domain's workspace folder; throws a message for the agent when the domain isn't one, or when
14
+ // the folder is missing and not created (run-start, a run's first command, creates it).
15
+ export function workspaceDir(domain, { create = false } = {}) {
16
+ if (!HOSTNAME.test(domain ?? '')) throw new Error(`"${domain ?? ''}" is not a domain (use its ASCII form, e.g. xn--caf-dma.com)`);
17
+ const dir = join(homedir(), '.hostinger', domain);
18
+ if (create) mkdirSync(dir, { recursive: true });
19
+ else if (!existsSync(dir)) throw new Error(`no workspace at ${dir}; run-log.mjs run-start creates it`);
20
+ return dir;
21
+ }
22
+
23
+ // Through a rename, so a reader never sees half of the file.
24
+ export function writeJsonAtomic(file, value) {
25
+ const tmp = `${file}.${process.pid}.tmp`;
26
+ writeFileSync(tmp, `${JSON.stringify(value, null, 2)}\n`);
27
+ renameSync(tmp, file);
28
+ }
@@ -62,7 +62,7 @@ const GetSkillRequestSchema = z.object({
62
62
 
63
63
  /**
64
64
  * MCP Server for Hostinger API
65
- * Generated from OpenAPI spec version 3.4.3
65
+ * Generated from OpenAPI spec version 3.5.0
66
66
  */
67
67
  class MCPServer {
68
68
  constructor({ name, version, tools, instructions, skills = [] }) {
@@ -97,7 +97,7 @@ interface Skill { uri: string; frontmatter: Record<string, unknown>; resources:
97
97
 
98
98
  /**
99
99
  * MCP Server for Hostinger API
100
- * Generated from OpenAPI spec version 3.4.3
100
+ * Generated from OpenAPI spec version 3.5.0
101
101
  */
102
102
  class MCPServer {
103
103
  private readonly name: string;