hostinger-api-mcp 3.28.6 → 3.29.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.
- package/CHANGELOG.md +7 -0
- package/gemini-extension.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/headless/SKILL.md +1 -0
- package/skills/headless/VERSION +2 -2
- package/skills/headless/hostinger-mcp.mjs +88 -0
- package/skills/headless/push-content.mjs +530 -0
- package/skills/headless/steps/04-content-model/SKILL.md +9 -9
- package/skills/headless/steps/04-content-model/wordpress/SKILL.md +83 -252
- package/skills/headless/steps/04-content-model/wordpress/by-hand.md +31 -0
- package/skills/headless/steps/04-content-model/wordpress/custom-plugins.md +2 -2
- package/skills/headless/steps/04-content-model/wordpress/woocommerce.md +21 -49
- package/skills/headless/steps/05-design/SKILL.md +1 -1
- package/skills/headless/wait.mjs +15 -95
- package/skills/headless/wp-mcp.mjs +125 -0
- package/src/core/skills.js +49 -21
- package/src/core/skills.ts +49 -21
- package/src/servers/agency-hosting.js +1 -1
- package/src/servers/agency-hosting.ts +1 -1
- package/src/servers/agent-readiness.js +1 -1
- package/src/servers/agent-readiness.ts +1 -1
- package/src/servers/all.js +1 -1
- package/src/servers/all.ts +1 -1
- package/src/servers/billing.js +1 -1
- package/src/servers/billing.ts +1 -1
- package/src/servers/dns.js +1 -1
- package/src/servers/dns.ts +1 -1
- package/src/servers/domains.js +1 -1
- package/src/servers/domains.ts +1 -1
- package/src/servers/ecommerce.js +1 -1
- package/src/servers/ecommerce.ts +1 -1
- package/src/servers/gpu.js +1 -1
- package/src/servers/gpu.ts +1 -1
- package/src/servers/horizons.js +1 -1
- package/src/servers/horizons.ts +1 -1
- package/src/servers/hosting.js +1 -1
- package/src/servers/hosting.ts +1 -1
- package/src/servers/mail.js +1 -1
- package/src/servers/mail.ts +1 -1
- package/src/servers/reach.js +1 -1
- package/src/servers/reach.ts +1 -1
- package/src/servers/vps.js +1 -1
- package/src/servers/vps.ts +1 -1
- package/src/servers/wordpress.js +1 -1
- package/src/servers/wordpress.ts +1 -1
package/skills/headless/wait.mjs
CHANGED
|
@@ -13,17 +13,7 @@
|
|
|
13
13
|
// error retrying can't fix (the JSON says which), 2 when it couldn't run (`fallback` names the
|
|
14
14
|
// operation to poll by hand instead).
|
|
15
15
|
|
|
16
|
-
import {
|
|
17
|
-
import { homedir } from 'node:os';
|
|
18
|
-
|
|
19
|
-
// ── platform-safe binary names (npm/npx are .cmd on Windows), as in connect/bootstrap.mjs ──────────
|
|
20
|
-
const isWin = process.platform === 'win32';
|
|
21
|
-
const bin = (name) => (isWin ? `${name}.cmd` : name);
|
|
22
|
-
const MCP = [bin('npx'), '-y', '--package=@hostinger/mcp@latest', 'hostinger-api-mcp'];
|
|
23
|
-
// Node >= 18.20.2 / 20.12.2 refuses to spawn a .cmd/.bat without a shell
|
|
24
|
-
// (CVE-2024-27980), so npx.cmd needs shell:true on Windows. Our args are all
|
|
25
|
-
// fixed literals, so enabling the shell introduces no injection risk.
|
|
26
|
-
const spawnShell = isWin;
|
|
16
|
+
import { connect } from './hostinger-mcp.mjs';
|
|
27
17
|
|
|
28
18
|
const log = (message) => process.stderr.write(`wait: ${message}\n`);
|
|
29
19
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -53,83 +43,6 @@ function duration(text) {
|
|
|
53
43
|
return Number(m[1]) * { s: 1e3, m: 6e4, h: 36e5 }[m[2]];
|
|
54
44
|
}
|
|
55
45
|
|
|
56
|
-
// One MCP server for the whole wait, spoken to over newline-delimited JSON-RPC on stdio. Once the
|
|
57
|
-
// server dies every pending and later call rejects, so the wait ends with exit 2 rather than hanging.
|
|
58
|
-
function connect() {
|
|
59
|
-
const child = spawn(MCP[0], MCP.slice(1), { stdio: ['pipe', 'pipe', 'pipe'], shell: spawnShell, cwd: homedir() });
|
|
60
|
-
const pending = new Map();
|
|
61
|
-
let buffer = '';
|
|
62
|
-
let diag = '';
|
|
63
|
-
let dead = null;
|
|
64
|
-
let nextId = 0;
|
|
65
|
-
const die = (reason) => {
|
|
66
|
-
dead ??= new Error(`the Hostinger MCP server stopped (${reason}): ${diag.trim().slice(-500)}`);
|
|
67
|
-
for (const { reject } of pending.values()) reject(dead);
|
|
68
|
-
pending.clear();
|
|
69
|
-
};
|
|
70
|
-
child.on('error', (e) => die(e.message));
|
|
71
|
-
// 'close' comes after stderr is drained, so the reason is in diag. A write to a dying server fails
|
|
72
|
-
// with EPIPE before that; 'close' still follows, so the EPIPE itself is ignored.
|
|
73
|
-
child.on('close', (code) => die(`exit code ${code}`));
|
|
74
|
-
child.stdin.on('error', () => {});
|
|
75
|
-
child.stderr.on('data', (chunk) => (diag = (diag + chunk).slice(-2000)));
|
|
76
|
-
child.stdout.on('data', (chunk) => {
|
|
77
|
-
buffer += chunk;
|
|
78
|
-
let i;
|
|
79
|
-
while ((i = buffer.indexOf('\n')) >= 0) {
|
|
80
|
-
const line = buffer.slice(0, i);
|
|
81
|
-
buffer = buffer.slice(i + 1);
|
|
82
|
-
try {
|
|
83
|
-
const message = JSON.parse(line);
|
|
84
|
-
pending.get(message.id)?.resolve(message);
|
|
85
|
-
pending.delete(message.id);
|
|
86
|
-
} catch {
|
|
87
|
-
/* not a JSON-RPC line */
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
// A call can stall on a live server (a stuck upstream request), so each one has its own deadline; past
|
|
92
|
-
// it, it answers like an error reply. A stalled poll is retried; a stalled start ends the wait.
|
|
93
|
-
const rpc = (method, params) =>
|
|
94
|
-
new Promise((resolve, reject) => {
|
|
95
|
-
if (dead) return reject(dead);
|
|
96
|
-
const id = (nextId += 1);
|
|
97
|
-
const timer = setTimeout(() => {
|
|
98
|
-
pending.delete(id);
|
|
99
|
-
resolve({ error: { message: `no reply to ${method} in 60 s` } });
|
|
100
|
-
}, 60_000);
|
|
101
|
-
const settle = (fn) => (value) => {
|
|
102
|
-
clearTimeout(timer);
|
|
103
|
-
fn(value);
|
|
104
|
-
};
|
|
105
|
-
pending.set(id, { resolve: settle(resolve), reject: settle(reject) });
|
|
106
|
-
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
107
|
-
});
|
|
108
|
-
const ready = rpc('initialize', { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'headless-wait', version: '1' } })
|
|
109
|
-
.then((reply) => {
|
|
110
|
-
if (reply.error) throw new Error(`the Hostinger MCP server didn't start: ${reply.error.message}`);
|
|
111
|
-
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' })}\n`);
|
|
112
|
-
});
|
|
113
|
-
// The server keeps "HTTP <status>" in its error text. A 409 while the setup runs, a 429 or a 5xx is a
|
|
114
|
-
// poll that didn't answer; any other 4xx (expired sign-in) or an unknown domain won't fix itself by waiting.
|
|
115
|
-
const execute = async (operation, params) => {
|
|
116
|
-
await ready;
|
|
117
|
-
const reply = await rpc('tools/call', { name: 'execute', arguments: { operation, params } });
|
|
118
|
-
const text = reply.result?.content?.[0]?.text ?? reply.error?.message ?? 'unknown error';
|
|
119
|
-
if (reply.error || reply.result?.isError) {
|
|
120
|
-
const status = Number(text.match(/HTTP (\d{3})/)?.[1]);
|
|
121
|
-
const terminal = (status >= 400 && status < 500 && ![408, 409, 425, 429].includes(status)) || /No website found/.test(text);
|
|
122
|
-
return { error: text.slice(0, 300), terminal };
|
|
123
|
-
}
|
|
124
|
-
try {
|
|
125
|
-
return { data: JSON.parse(text) };
|
|
126
|
-
} catch {
|
|
127
|
-
return { error: text.slice(0, 300), terminal: false };
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
return { execute, close: () => child.kill() };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
46
|
async function httpStatus(url) {
|
|
134
47
|
try {
|
|
135
48
|
const response = await fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(30_000) });
|
|
@@ -157,6 +70,10 @@ async function poll(label, timeoutMs, check) {
|
|
|
157
70
|
}
|
|
158
71
|
}
|
|
159
72
|
|
|
73
|
+
// A 409 while the setup runs, a 429 or a 5xx is a poll that didn't answer; any other 4xx (expired
|
|
74
|
+
// sign-in) or an unknown domain won't fix itself by waiting.
|
|
75
|
+
const isTerminal = ({ error, status }) => (status >= 400 && status < 500 && ![408, 409, 425, 429].includes(status)) || /No website found/.test(error);
|
|
76
|
+
|
|
160
77
|
// List operations answer an array, or an object holding it in `data`; their domain filter is loose.
|
|
161
78
|
const rowsFor = (data, domain) =>
|
|
162
79
|
(Array.isArray(data) ? data : data?.data ?? []).filter((r) => r.domain?.toLowerCase() === domain.toLowerCase());
|
|
@@ -174,8 +91,9 @@ const KINDS = {
|
|
|
174
91
|
fallback: 'hosting_websites_list-setups',
|
|
175
92
|
run: (mcp, { domain }, timeoutMs) =>
|
|
176
93
|
poll('setup', timeoutMs, async () => {
|
|
177
|
-
const
|
|
178
|
-
|
|
94
|
+
const reply = await mcp.execute('hosting_websites_list-setups', { domain });
|
|
95
|
+
const { data, error } = reply;
|
|
96
|
+
if (error) return { status: `list-setups: ${error}`, terminal: isTerminal(reply) };
|
|
179
97
|
const [row] = rowsFor(data, domain);
|
|
180
98
|
if (row?.status === 'completed') return { done: { ok: true, setup: row } };
|
|
181
99
|
if (row?.status === 'failed') return { done: { ok: false, setup: row } };
|
|
@@ -190,8 +108,9 @@ const KINDS = {
|
|
|
190
108
|
// The list can lag a few seconds behind the install finishing and answer [], so an empty list is a wait.
|
|
191
109
|
run: (mcp, { domain, username }, timeoutMs) =>
|
|
192
110
|
poll('cms', timeoutMs, async () => {
|
|
193
|
-
const
|
|
194
|
-
|
|
111
|
+
const reply = await mcp.execute('wordpress_installations_list', { username, domain, ownership: 'all' });
|
|
112
|
+
const { data, error } = reply;
|
|
113
|
+
if (error) return { status: `installations: ${error}`, terminal: isTerminal(reply) };
|
|
195
114
|
const rows = rowsFor(data, domain).filter((r) => r.directory === 'cms');
|
|
196
115
|
const valid = rows.find((r) => r.is_valid ?? r.valid);
|
|
197
116
|
if (valid) return { done: { ok: true, install: valid } };
|
|
@@ -206,8 +125,9 @@ const KINDS = {
|
|
|
206
125
|
run: async (mcp, { domain, buildUuid }, timeoutMs) => {
|
|
207
126
|
const started = Date.now();
|
|
208
127
|
const build = await poll('build', timeoutMs, async () => {
|
|
209
|
-
const
|
|
210
|
-
|
|
128
|
+
const reply = await mcp.execute('hosting_get-deployment', { domain, buildUuid });
|
|
129
|
+
const { data, error } = reply;
|
|
130
|
+
if (error) return { status: `get-deployment: ${error}`, terminal: isTerminal(reply) };
|
|
211
131
|
const state = data?.build?.state;
|
|
212
132
|
if (state === 'failed') {
|
|
213
133
|
const logTail = String(data.logs?.logs ?? '').split('\n').slice(-40).join('\n');
|
|
@@ -240,7 +160,7 @@ if (!spec || !domain || rest.length < spec.args.length) fail(`usage: ${usage} [-
|
|
|
240
160
|
const params = { domain, ...Object.fromEntries(spec.args.map((a, i) => [a, rest[i]])) };
|
|
241
161
|
const timeoutMs = duration(flags.timeout ?? spec.timeout);
|
|
242
162
|
fallback = spec.fallback ?? null;
|
|
243
|
-
const mcp = spec.fallback ? connect() : null;
|
|
163
|
+
const mcp = spec.fallback ? connect('headless-wait') : null;
|
|
244
164
|
const result = await spec.run(mcp, params, timeoutMs).catch((e) => fail(e.message));
|
|
245
165
|
mcp?.close();
|
|
246
166
|
finish(result.ok ? 0 : 1, { wait: kind, domain, ...result });
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// The site's own WP MCP (the Hostinger AI Assistant plugin): streamable HTTP, session-based, with the
|
|
2
|
+
// installation token on every request. Used by push-content.mjs.
|
|
3
|
+
|
|
4
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
|
|
6
|
+
// A reply is plain JSON or an event stream whose data lines hold it.
|
|
7
|
+
function parseReply(text, id) {
|
|
8
|
+
if (text.trimStart().startsWith('{')) return JSON.parse(text);
|
|
9
|
+
for (const line of text.split('\n')) {
|
|
10
|
+
if (!line.startsWith('data:')) continue;
|
|
11
|
+
try {
|
|
12
|
+
const message = JSON.parse(line.slice(5));
|
|
13
|
+
if (message.id === id) return message;
|
|
14
|
+
} catch {
|
|
15
|
+
/* not a JSON data line */
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`no JSON-RPC reply in: ${text.slice(0, 200)}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// A tool result holds { ability, result } (structuredContent, or JSON text). A WordPress error comes back
|
|
22
|
+
// as a normal result carrying { code, message, data: { status } }; a term_exists error still names the id.
|
|
23
|
+
function unwrap(result) {
|
|
24
|
+
let body = result?.structuredContent;
|
|
25
|
+
const text = result?.content?.[0]?.text;
|
|
26
|
+
if (body === undefined) {
|
|
27
|
+
try {
|
|
28
|
+
body = JSON.parse(text);
|
|
29
|
+
} catch {
|
|
30
|
+
body = text;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const value = body?.result ?? body;
|
|
34
|
+
if (result?.isError || typeof value !== 'object' || value === null) return { error: String(text ?? value).slice(0, 300) };
|
|
35
|
+
if (value.success === false || (value.code && value.data?.status >= 400)) {
|
|
36
|
+
return { error: `${value.code ?? 'error'}: ${value.message ?? ''}`.slice(0, 300), id: value.data?.term_id ?? value.data?.resource_id };
|
|
37
|
+
}
|
|
38
|
+
return { data: value, id: value.id ?? value.data?.id };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const listOf = (data) => (Array.isArray(data) ? data : data?.data ?? []);
|
|
42
|
+
|
|
43
|
+
// Opens the session and resolves the abilities. `mint` returns { token, url }; it is called again only
|
|
44
|
+
// when the token expires. Returns { has(ability), run(ability, params) → { data, id } | { error, id? } }.
|
|
45
|
+
export async function openSite(mint) {
|
|
46
|
+
let { token, url } = await mint();
|
|
47
|
+
let session = null;
|
|
48
|
+
let nextId = 0;
|
|
49
|
+
const send = async (method, params, { notify = false } = {}) => {
|
|
50
|
+
const message = notify ? { jsonrpc: '2.0', method, params } : { jsonrpc: '2.0', id: (nextId += 1), method, params };
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: {
|
|
54
|
+
'content-type': 'application/json',
|
|
55
|
+
accept: 'application/json, text/event-stream',
|
|
56
|
+
'X-Hostinger-JWT-Token': token,
|
|
57
|
+
...(session ? { 'Mcp-Session-Id': session } : {}),
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify(message),
|
|
60
|
+
signal: AbortSignal.timeout(120_000),
|
|
61
|
+
});
|
|
62
|
+
session = response.headers.get('mcp-session-id') ?? session;
|
|
63
|
+
const text = await response.text();
|
|
64
|
+
// The initialized notification can answer 404 with no body; that's harmless.
|
|
65
|
+
if (notify) return null;
|
|
66
|
+
if (!response.ok) throw Object.assign(new Error(`HTTP ${response.status}: ${text.slice(0, 200)}`), { status: response.status });
|
|
67
|
+
const reply = parseReply(text, message.id);
|
|
68
|
+
if (reply.error) throw new Error(`${method}: ${reply.error.message}`);
|
|
69
|
+
return reply.result;
|
|
70
|
+
};
|
|
71
|
+
const open = async () => {
|
|
72
|
+
session = null;
|
|
73
|
+
await send('initialize', { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'headless-push-content', version: '1' } });
|
|
74
|
+
await send('notifications/initialized', undefined, { notify: true }).catch(() => {});
|
|
75
|
+
};
|
|
76
|
+
// A 429, a 5xx or a dropped connection is retried, but a create only on a 429: it may have gone
|
|
77
|
+
// through, and the next run's lookup finds it. An expired token is re-minted once; a lost session is
|
|
78
|
+
// reopened.
|
|
79
|
+
const call = async (method, params, { retry = true } = {}) => {
|
|
80
|
+
let reminted = false;
|
|
81
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
82
|
+
try {
|
|
83
|
+
return await send(method, params);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if ((e.status === 401 || e.status === 403) && !reminted) {
|
|
86
|
+
reminted = true;
|
|
87
|
+
({ token } = await mint());
|
|
88
|
+
await open();
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const sessionLost = e.status === 404 || /Mcp-Session-Id/i.test(e.message);
|
|
92
|
+
const transient = e.status === 429 || e.status >= 500 || e.status === undefined;
|
|
93
|
+
if (attempt >= 3 || !(sessionLost || (transient && (retry || e.status === 429)))) throw e;
|
|
94
|
+
if (sessionLost) await open();
|
|
95
|
+
else await sleep(2_000 * 2 ** attempt);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
await open();
|
|
100
|
+
|
|
101
|
+
// Every ability as its own tool, or three meta-tools (discover → get-info → execute). Names carry a
|
|
102
|
+
// `hostinger-ai/` prefix (`hostinger-ai-` as a tool name); match on the rest.
|
|
103
|
+
const { tools = [] } = await call('tools/list', {});
|
|
104
|
+
const meta = (suffix) => tools.find((t) => t.name.endsWith(suffix))?.name;
|
|
105
|
+
const execute = meta('execute-ability');
|
|
106
|
+
let names = tools.map((t) => t.name);
|
|
107
|
+
if (execute) {
|
|
108
|
+
const listed = unwrap(await call('tools/call', { name: meta('discover-abilities'), arguments: {} }));
|
|
109
|
+
if (listed.error) throw new Error(`discover-abilities: ${listed.error}`);
|
|
110
|
+
names = (listed.data.abilities ?? []).map((a) => a.name);
|
|
111
|
+
}
|
|
112
|
+
const byShort = new Map(names.map((n) => [n.replace(/^hostinger[-_]ai[/_-]+/, ''), n]));
|
|
113
|
+
const run = async (ability, params) => {
|
|
114
|
+
const name = byShort.get(ability);
|
|
115
|
+
if (!name) return { error: `the site's MCP has no ${ability} ability` };
|
|
116
|
+
const retry = !/-(create|upload-from-url)$/.test(ability);
|
|
117
|
+
try {
|
|
118
|
+
const request = execute ? { name: execute, arguments: { name, parameters: params } } : { name, arguments: params };
|
|
119
|
+
return unwrap(await call('tools/call', request, { retry }));
|
|
120
|
+
} catch (e) {
|
|
121
|
+
return { error: e.message.slice(0, 300) };
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
return { has: (ability) => byShort.has(ability), run };
|
|
125
|
+
}
|