@innflows/ai-readiness-audit 0.2.0 → 0.3.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/README.md +65 -39
- package/bin/cli.mjs +916 -121
- package/package.json +6 -4
- package/server.json +3 -3
package/bin/cli.mjs
CHANGED
|
@@ -19,7 +19,19 @@ export const AI_CRAWLERS = [
|
|
|
19
19
|
"Applebot-Extended",
|
|
20
20
|
];
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
export const PROBE_USER_AGENTS = {
|
|
23
|
+
"Browser-Baseline":
|
|
24
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
|
|
25
|
+
"OAI-SearchBot": "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; OAI-SearchBot/1.0; +https://openai.com/searchbot",
|
|
26
|
+
GPTBot: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; GPTBot/1.1; +https://openai.com/gptbot",
|
|
27
|
+
"ChatGPT-User": "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; ChatGPT-User/1.0; +https://openai.com/bot",
|
|
28
|
+
ClaudeBot: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)",
|
|
29
|
+
PerplexityBot: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; PerplexityBot/1.0; +https://perplexity.ai/perplexitybot)",
|
|
30
|
+
"Google-Extended": "Mozilla/5.0 (compatible; Google-Extended/1.0; +http://www.google.com/bot.html)",
|
|
31
|
+
"Applebot-Extended": "Mozilla/5.0 (Applebot-Extended/0.3; +http://www.apple.com/go/applebot)",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const PKG_VERSION = "0.3.0";
|
|
23
35
|
|
|
24
36
|
function isPrivateIp(ip) {
|
|
25
37
|
if (net.isIPv4(ip)) {
|
|
@@ -65,6 +77,22 @@ async function assertPublicHost(hostname) {
|
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
79
|
|
|
80
|
+
function normalizeUrlInput(targetUrl) {
|
|
81
|
+
const normalized = String(targetUrl || "").trim();
|
|
82
|
+
if (!normalized) throw new Error("Empty URL");
|
|
83
|
+
const withProto = normalized.includes("://") ? normalized : `https://${normalized}`;
|
|
84
|
+
const parsed = new URL(withProto);
|
|
85
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
86
|
+
throw new Error(`Unsupported URL protocol: ${parsed.protocol}`);
|
|
87
|
+
}
|
|
88
|
+
if (!parsed.pathname) parsed.pathname = "/";
|
|
89
|
+
return {
|
|
90
|
+
parsed,
|
|
91
|
+
origin: `${parsed.protocol}//${parsed.host}`,
|
|
92
|
+
pageUrl: parsed.toString(),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
68
96
|
export function parseRobotsRules(robotsTxt) {
|
|
69
97
|
const groups = [];
|
|
70
98
|
let currentAgents = [];
|
|
@@ -113,7 +141,18 @@ function extractAttr(tagHtml, attrName) {
|
|
|
113
141
|
return m ? (m[1] ?? m[2] ?? m[3] ?? "").trim() : "";
|
|
114
142
|
}
|
|
115
143
|
|
|
116
|
-
|
|
144
|
+
function stripVisibleText(html) {
|
|
145
|
+
return String(html || "")
|
|
146
|
+
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, " ")
|
|
147
|
+
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ")
|
|
148
|
+
.replace(/<noscript\b[^>]*>[\s\S]*?<\/noscript>/gi, " ")
|
|
149
|
+
.replace(/<!--[\s\S]*?-->/g, " ")
|
|
150
|
+
.replace(/<[^>]+>/g, " ")
|
|
151
|
+
.replace(/\s+/g, " ")
|
|
152
|
+
.trim();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function extractSchemaGraphFromHtml(html) {
|
|
117
156
|
const src = String(html || "");
|
|
118
157
|
const jsonLdBlocks = [];
|
|
119
158
|
const ldRegex = /<script\b[^>]*type\s*=\s*["']?application\/ld\+json["']?[^>]*>([\s\S]*?)<\/script>/gi;
|
|
@@ -122,6 +161,91 @@ export function inspectHtmlDocument(html) {
|
|
|
122
161
|
if (m[1] && m[1].trim()) jsonLdBlocks.push(m[1].trim());
|
|
123
162
|
}
|
|
124
163
|
|
|
164
|
+
const entities = [];
|
|
165
|
+
const definedIds = new Set();
|
|
166
|
+
const referencedIds = new Set();
|
|
167
|
+
const sameAsUrls = new Set();
|
|
168
|
+
let parseErrors = 0;
|
|
169
|
+
|
|
170
|
+
function walk(node, isTopEntity = true) {
|
|
171
|
+
if (!node) return;
|
|
172
|
+
if (Array.isArray(node)) {
|
|
173
|
+
for (const sub of node) walk(sub, isTopEntity);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (typeof node !== "object") return;
|
|
177
|
+
|
|
178
|
+
if (Array.isArray(node["@graph"])) {
|
|
179
|
+
for (const sub of node["@graph"]) walk(sub, true);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const rawType = node["@type"];
|
|
183
|
+
const types = typeof rawType === "string" ? [rawType] : Array.isArray(rawType) ? rawType.map(String) : [];
|
|
184
|
+
const nodeId = typeof node["@id"] === "string" ? node["@id"].trim() : "";
|
|
185
|
+
|
|
186
|
+
// Pure @id reference object (no @type and few keys)
|
|
187
|
+
if (nodeId && types.length === 0 && Object.keys(node).length <= 2) {
|
|
188
|
+
referencedIds.add(nodeId);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (nodeId) definedIds.add(nodeId);
|
|
193
|
+
|
|
194
|
+
if (types.length > 0) {
|
|
195
|
+
const sameAsRaw = node.sameAs;
|
|
196
|
+
const nodeSameAs = [];
|
|
197
|
+
if (typeof sameAsRaw === "string" && sameAsRaw.trim()) {
|
|
198
|
+
nodeSameAs.push(sameAsRaw.trim());
|
|
199
|
+
} else if (Array.isArray(sameAsRaw)) {
|
|
200
|
+
for (const u of sameAsRaw) {
|
|
201
|
+
if (typeof u === "string" && u.trim()) nodeSameAs.push(u.trim());
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const u of nodeSameAs) sameAsUrls.add(u);
|
|
205
|
+
|
|
206
|
+
entities.push({
|
|
207
|
+
types,
|
|
208
|
+
id: nodeId || null,
|
|
209
|
+
name: typeof node.name === "string" ? node.name : typeof node.headline === "string" ? node.headline : null,
|
|
210
|
+
url: typeof node.url === "string" ? node.url : null,
|
|
211
|
+
sameAsCount: nodeSameAs.length,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
for (const [k, v] of Object.entries(node)) {
|
|
216
|
+
if (k === "@graph" || k === "@context" || k === "@type" || k === "@id") continue;
|
|
217
|
+
if (v && typeof v === "object") {
|
|
218
|
+
walk(v, false);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
for (const block of jsonLdBlocks) {
|
|
224
|
+
try {
|
|
225
|
+
walk(JSON.parse(block), true);
|
|
226
|
+
} catch {
|
|
227
|
+
parseErrors += 1;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const allTypes = entities.flatMap((e) => e.types);
|
|
232
|
+
const danglingIds = [...referencedIds].filter((ref) => ref.includes("#") && !definedIds.has(ref));
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
blocks_count: jsonLdBlocks.length,
|
|
236
|
+
parse_errors: parseErrors,
|
|
237
|
+
entities,
|
|
238
|
+
schema_types: allTypes,
|
|
239
|
+
unique_types: [...new Set(allTypes)],
|
|
240
|
+
defined_ids: [...definedIds],
|
|
241
|
+
referenced_ids: [...referencedIds],
|
|
242
|
+
dangling_ids: danglingIds,
|
|
243
|
+
same_as_urls: [...sameAsUrls],
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function inspectHtmlDocument(html) {
|
|
248
|
+
const src = String(html || "");
|
|
125
249
|
const titleMatch = src.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
126
250
|
const title = titleMatch ? titleMatch[1].replace(/\s+/g, " ").trim() : "";
|
|
127
251
|
|
|
@@ -146,40 +270,8 @@ export function inspectHtmlDocument(html) {
|
|
|
146
270
|
}
|
|
147
271
|
}
|
|
148
272
|
|
|
149
|
-
const stripped = src
|
|
150
|
-
|
|
151
|
-
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ")
|
|
152
|
-
.replace(/<noscript\b[^>]*>[\s\S]*?<\/noscript>/gi, " ")
|
|
153
|
-
.replace(/<!--[\s\S]*?-->/g, " ")
|
|
154
|
-
.replace(/<[^>]+>/g, " ")
|
|
155
|
-
.replace(/\s+/g, " ")
|
|
156
|
-
.trim();
|
|
157
|
-
|
|
158
|
-
const schemaTypes = [];
|
|
159
|
-
const schemaIds = [];
|
|
160
|
-
function collectSchema(node) {
|
|
161
|
-
if (!node) return;
|
|
162
|
-
if (Array.isArray(node)) {
|
|
163
|
-
for (const sub of node) collectSchema(sub);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (typeof node === "object") {
|
|
167
|
-
const t = node["@type"];
|
|
168
|
-
if (typeof t === "string") schemaTypes.push(t);
|
|
169
|
-
else if (Array.isArray(t)) schemaTypes.push(...t.map(String));
|
|
170
|
-
if (typeof node["@id"] === "string") schemaIds.push(node["@id"]);
|
|
171
|
-
if (Array.isArray(node["@graph"])) {
|
|
172
|
-
for (const sub of node["@graph"]) collectSchema(sub);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
for (const block of jsonLdBlocks) {
|
|
177
|
-
try {
|
|
178
|
-
collectSchema(JSON.parse(block));
|
|
179
|
-
} catch {
|
|
180
|
-
// Ignore malformed JSON-LD blocks
|
|
181
|
-
}
|
|
182
|
-
}
|
|
273
|
+
const stripped = stripVisibleText(src);
|
|
274
|
+
const graph = extractSchemaGraphFromHtml(src);
|
|
183
275
|
|
|
184
276
|
return {
|
|
185
277
|
title,
|
|
@@ -187,12 +279,97 @@ export function inspectHtmlDocument(html) {
|
|
|
187
279
|
meta_robots: metaRobots,
|
|
188
280
|
canonical,
|
|
189
281
|
visible_text_chars: stripped.length,
|
|
190
|
-
schema_types:
|
|
191
|
-
schema_ids:
|
|
282
|
+
schema_types: graph.schema_types,
|
|
283
|
+
schema_ids: graph.defined_ids,
|
|
192
284
|
};
|
|
193
285
|
}
|
|
194
286
|
|
|
195
|
-
|
|
287
|
+
export function parseLlmsTxtDocument(content) {
|
|
288
|
+
const raw = String(content || "");
|
|
289
|
+
const trimmed = raw.trim();
|
|
290
|
+
const looksLikeHtml = /^<!doctype\s+html/i.test(trimmed) || /^<html\b/i.test(trimmed);
|
|
291
|
+
const lines = raw.split(/\r?\n/);
|
|
292
|
+
|
|
293
|
+
let h1Title = "";
|
|
294
|
+
let blockquoteSummary = "";
|
|
295
|
+
const sections = [];
|
|
296
|
+
const links = [];
|
|
297
|
+
|
|
298
|
+
let currentSection = "Root";
|
|
299
|
+
const mdLinkRe = /^\s*[-*]\s+\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)(?:\s*(?::|—|–|-)\s*(.*))?$/;
|
|
300
|
+
const bareLinkRe = /^\s*[-*]\s+([^:\n]+?):\s+(https?:\/\/[^\s)]+)(?:\s*(?:—|–|-)\s*(.*))?$/;
|
|
301
|
+
|
|
302
|
+
for (const line of lines) {
|
|
303
|
+
const t = line.trim();
|
|
304
|
+
if (!h1Title && /^#\s+/.test(t) && !/^##/.test(t)) {
|
|
305
|
+
h1Title = t.replace(/^#\s+/, "").trim();
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (!blockquoteSummary && /^>\s+/.test(t)) {
|
|
309
|
+
blockquoteSummary = t.replace(/^>\s+/, "").trim();
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (/^##\s+/.test(t)) {
|
|
313
|
+
currentSection = t.replace(/^##\s+/, "").trim();
|
|
314
|
+
sections.push(currentSection);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const lm = line.match(mdLinkRe) || line.match(bareLinkRe);
|
|
318
|
+
if (lm) {
|
|
319
|
+
links.push({
|
|
320
|
+
section: currentSection,
|
|
321
|
+
title: lm[1].replace(/^\*\*|\*\*$/g, "").trim(),
|
|
322
|
+
url: lm[2].trim(),
|
|
323
|
+
description: (lm[3] || "").trim(),
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const issues = [];
|
|
329
|
+
if (!trimmed) issues.push("Empty /llms.txt body");
|
|
330
|
+
if (looksLikeHtml) issues.push("Response is an HTML document (SPA soft-200 fallback) instead of plain Markdown");
|
|
331
|
+
if (!looksLikeHtml && trimmed) {
|
|
332
|
+
if (!h1Title) issues.push("Missing required top-level '# Title' H1 heading");
|
|
333
|
+
if (!blockquoteSummary) issues.push("Missing recommended '> Summary' blockquote description");
|
|
334
|
+
if (sections.length === 0) issues.push("No '## Section' headings found");
|
|
335
|
+
if (links.length === 0) issues.push("No Markdown list links ('- [Title](https://...): description') found");
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
valid_spec: !looksLikeHtml && Boolean(h1Title) && links.length > 0,
|
|
340
|
+
is_html_fallback: looksLikeHtml,
|
|
341
|
+
char_length: raw.length,
|
|
342
|
+
h1_title: h1Title || null,
|
|
343
|
+
blockquote_summary: blockquoteSummary || null,
|
|
344
|
+
sections,
|
|
345
|
+
links_count: links.length,
|
|
346
|
+
links,
|
|
347
|
+
issues,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export function detectWafChallenge(status, headers, body) {
|
|
352
|
+
const lower = String(body || "").slice(0, 8000).toLowerCase();
|
|
353
|
+
const cfMitigated = (headers["cf-mitigated"] || "").toLowerCase();
|
|
354
|
+
if (cfMitigated.includes("challenge")) return "cloudflare_challenge_header";
|
|
355
|
+
if (
|
|
356
|
+
(status === 403 || status === 429 || status === 503) &&
|
|
357
|
+
(lower.includes("just a moment...") ||
|
|
358
|
+
lower.includes("cf-browser-verification") ||
|
|
359
|
+
lower.includes("challenge-platform") ||
|
|
360
|
+
lower.includes("attention required! | cloudflare") ||
|
|
361
|
+
lower.includes("access denied") ||
|
|
362
|
+
lower.includes("bot verification"))
|
|
363
|
+
) {
|
|
364
|
+
return "waf_or_bot_challenge";
|
|
365
|
+
}
|
|
366
|
+
if (status === 403) return "http_403_forbidden";
|
|
367
|
+
if (status === 429) return "http_429_rate_limited";
|
|
368
|
+
if (status === 401) return "http_401_unauthorized";
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
async function fetchResource(urlStr, timeoutSec = 12, customUserAgent = null) {
|
|
196
373
|
const parsed = new URL(urlStr);
|
|
197
374
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
198
375
|
throw new Error(`Unsupported URL protocol: ${parsed.protocol}`);
|
|
@@ -205,7 +382,7 @@ async function fetchResource(urlStr, timeoutSec = 12) {
|
|
|
205
382
|
signal: controller.signal,
|
|
206
383
|
redirect: "follow",
|
|
207
384
|
headers: {
|
|
208
|
-
"User-Agent": `Innflows-AI-Readiness-Audit/${PKG_VERSION} (+https://www.innflows.com)`,
|
|
385
|
+
"User-Agent": customUserAgent || `Innflows-AI-Readiness-Audit/${PKG_VERSION} (+https://www.innflows.com)`,
|
|
209
386
|
Accept: "text/html,text/plain,application/xml;q=0.9,*/*;q=0.8",
|
|
210
387
|
},
|
|
211
388
|
});
|
|
@@ -218,20 +395,16 @@ async function fetchResource(urlStr, timeoutSec = 12) {
|
|
|
218
395
|
const buf = await resp.arrayBuffer();
|
|
219
396
|
const slice = buf.byteLength > 1_500_000 ? buf.slice(0, 1_500_000) : buf;
|
|
220
397
|
const body = new TextDecoder("utf-8", { fatal: false }).decode(slice);
|
|
221
|
-
return { status: resp.status, headers, body };
|
|
398
|
+
return { status: resp.status, finalUrl: finalUrl.toString(), headers, body };
|
|
222
399
|
} catch {
|
|
223
|
-
return { status: 0, headers: {}, body: "" };
|
|
400
|
+
return { status: 0, finalUrl: urlStr, headers: {}, body: "" };
|
|
224
401
|
} finally {
|
|
225
402
|
clearTimeout(timer);
|
|
226
403
|
}
|
|
227
404
|
}
|
|
228
405
|
|
|
229
406
|
export async function runAudit(targetUrl, timeoutSec = 12) {
|
|
230
|
-
const
|
|
231
|
-
const parsed = new URL(normalized);
|
|
232
|
-
const origin = `${parsed.protocol}//${parsed.host}`;
|
|
233
|
-
if (!parsed.pathname) parsed.pathname = "/";
|
|
234
|
-
const pageUrl = parsed.toString();
|
|
407
|
+
const { origin, pageUrl } = normalizeUrlInput(targetUrl);
|
|
235
408
|
|
|
236
409
|
const checks = [];
|
|
237
410
|
const page = await fetchResource(pageUrl, timeoutSec);
|
|
@@ -363,12 +536,22 @@ export async function runAudit(targetUrl, timeoutSec = 12) {
|
|
|
363
536
|
}
|
|
364
537
|
|
|
365
538
|
if (llmsRes.status === 200 && llmsRes.body.trim().length > 80) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
539
|
+
const parsedLlms = parseLlmsTxtDocument(llmsRes.body);
|
|
540
|
+
if (parsedLlms.is_html_fallback) {
|
|
541
|
+
checks.push({
|
|
542
|
+
id: "llms_txt",
|
|
543
|
+
name: "llms.txt Machine Summary",
|
|
544
|
+
status: "warn",
|
|
545
|
+
detail: "/llms.txt returns HTML fallback instead of plain Markdown",
|
|
546
|
+
});
|
|
547
|
+
} else {
|
|
548
|
+
checks.push({
|
|
549
|
+
id: "llms_txt",
|
|
550
|
+
name: "llms.txt Machine Summary",
|
|
551
|
+
status: "pass",
|
|
552
|
+
detail: `/llms.txt present (${llmsRes.body.length} chars, ${parsedLlms.links_count} links)`,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
372
555
|
} else {
|
|
373
556
|
checks.push({
|
|
374
557
|
id: "llms_txt",
|
|
@@ -408,6 +591,326 @@ export async function runAudit(targetUrl, timeoutSec = 12) {
|
|
|
408
591
|
};
|
|
409
592
|
}
|
|
410
593
|
|
|
594
|
+
export async function probeCrawlerAccess(targetUrl, timeoutSec = 12) {
|
|
595
|
+
const { origin, pageUrl } = normalizeUrlInput(targetUrl);
|
|
596
|
+
const robotsRes = await fetchResource(`${origin}/robots.txt`, timeoutSec);
|
|
597
|
+
const robotsPosture = robotsRes.status === 200 && robotsRes.body ? parseRobotsRules(robotsRes.body) : {};
|
|
598
|
+
|
|
599
|
+
const entries = Object.entries(PROBE_USER_AGENTS);
|
|
600
|
+
const probeResults = await Promise.all(
|
|
601
|
+
entries.map(async ([botName, ua]) => {
|
|
602
|
+
const res = await fetchResource(pageUrl, timeoutSec, ua);
|
|
603
|
+
const visibleChars = res.body ? stripVisibleText(res.body).length : 0;
|
|
604
|
+
const wafReason = detectWafChallenge(res.status, res.headers, res.body);
|
|
605
|
+
const robotsRule = botName === "Browser-Baseline" ? "n/a" : robotsPosture[botName] || "unknown";
|
|
606
|
+
const silentBlock =
|
|
607
|
+
botName !== "Browser-Baseline" &&
|
|
608
|
+
robotsRule !== "blocked" &&
|
|
609
|
+
(res.status !== 200 || Boolean(wafReason));
|
|
610
|
+
|
|
611
|
+
return {
|
|
612
|
+
agent: botName,
|
|
613
|
+
robots_txt_posture: robotsRule,
|
|
614
|
+
http_status: res.status,
|
|
615
|
+
visible_text_chars: visibleChars,
|
|
616
|
+
server_header: res.headers["server"] || null,
|
|
617
|
+
waf_diagnosis: wafReason,
|
|
618
|
+
silent_waf_block: silentBlock,
|
|
619
|
+
};
|
|
620
|
+
})
|
|
621
|
+
);
|
|
622
|
+
|
|
623
|
+
const baseline = probeResults.find((r) => r.agent === "Browser-Baseline");
|
|
624
|
+
const silentBlockedAgents = probeResults.filter((r) => r.silent_waf_block).map((r) => r.agent);
|
|
625
|
+
|
|
626
|
+
return {
|
|
627
|
+
url: pageUrl,
|
|
628
|
+
origin,
|
|
629
|
+
robots_txt_status: robotsRes.status,
|
|
630
|
+
baseline_status: baseline ? baseline.http_status : 0,
|
|
631
|
+
baseline_visible_chars: baseline ? baseline.visible_text_chars : 0,
|
|
632
|
+
silent_waf_blocks_detected: silentBlockedAgents.length > 0,
|
|
633
|
+
silent_blocked_agents: silentBlockedAgents,
|
|
634
|
+
probes: probeResults,
|
|
635
|
+
platform: "https://www.innflows.com/platform/website-ai-audit",
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function classifyPathSection(pathname) {
|
|
640
|
+
const seg = pathname.split("/").filter(Boolean)[0]?.toLowerCase() || "";
|
|
641
|
+
if (!seg) return "Core Pages";
|
|
642
|
+
if (["docs", "documentation", "guide", "guides", "reference", "api", "developers"].includes(seg)) return "Documentation";
|
|
643
|
+
if (["platform", "product", "products", "features", "solutions", "integrations", "pricing"].includes(seg)) return "Product & Pricing";
|
|
644
|
+
if (["blog", "research", "articles", "news", "insights", "resources"].includes(seg)) return "Research & Blog";
|
|
645
|
+
return "Key Pages";
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
export async function inspectOrGenerateLlmsTxt(targetUrl, options = {}) {
|
|
649
|
+
const mode = options.mode === "generate" ? "generate" : "validate";
|
|
650
|
+
const maxLinks = Math.min(Math.max(Number(options.maxLinks || 20), 5), 50);
|
|
651
|
+
const timeoutSec = Number(options.timeoutSec || 12);
|
|
652
|
+
const { parsed, origin, pageUrl } = normalizeUrlInput(targetUrl);
|
|
653
|
+
|
|
654
|
+
if (mode === "validate") {
|
|
655
|
+
const llmsUrl = parsed.pathname.endsWith(".txt") ? pageUrl : `${origin}/llms.txt`;
|
|
656
|
+
const [llmsRes, fullRes] = await Promise.all([
|
|
657
|
+
fetchResource(llmsUrl, timeoutSec),
|
|
658
|
+
fetchResource(`${origin}/llms-full.txt`, timeoutSec),
|
|
659
|
+
]);
|
|
660
|
+
|
|
661
|
+
if (llmsRes.status !== 200 || !llmsRes.body) {
|
|
662
|
+
return {
|
|
663
|
+
mode: "validate",
|
|
664
|
+
url: llmsUrl,
|
|
665
|
+
origin,
|
|
666
|
+
http_status: llmsRes.status,
|
|
667
|
+
has_llms_full_txt: fullRes.status === 200 && fullRes.body.length > 80,
|
|
668
|
+
valid_spec: false,
|
|
669
|
+
issues: [`${llmsUrl} returned HTTP ${llmsRes.status}`],
|
|
670
|
+
hint: "Run with mode='generate' (or CLI --generate) to synthesize a starter /llms.txt from your homepage and sitemap.xml.",
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const report = parseLlmsTxtDocument(llmsRes.body);
|
|
675
|
+
const sampleLinks = report.links.slice(0, 8);
|
|
676
|
+
const linkChecks = await Promise.all(
|
|
677
|
+
sampleLinks.map(async (item) => {
|
|
678
|
+
const r = await fetchResource(item.url, Math.min(timeoutSec, 8));
|
|
679
|
+
return { url: item.url, title: item.title, http_status: r.status, ok: r.status >= 200 && r.status < 400 };
|
|
680
|
+
})
|
|
681
|
+
);
|
|
682
|
+
const brokenLinks = linkChecks.filter((c) => !c.ok);
|
|
683
|
+
if (brokenLinks.length > 0) {
|
|
684
|
+
report.issues.push(`${brokenLinks.length}/${linkChecks.length} sampled links returned non-2xx/3xx status`);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
return {
|
|
688
|
+
mode: "validate",
|
|
689
|
+
url: llmsUrl,
|
|
690
|
+
origin,
|
|
691
|
+
http_status: llmsRes.status,
|
|
692
|
+
has_llms_full_txt: fullRes.status === 200 && fullRes.body.length > 80 && !parseLlmsTxtDocument(fullRes.body).is_html_fallback,
|
|
693
|
+
...report,
|
|
694
|
+
sampled_link_checks: linkChecks,
|
|
695
|
+
platform: "https://www.innflows.com/platform/website-ai-audit",
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// mode === "generate"
|
|
700
|
+
const [homeRes, sitemapRes] = await Promise.all([
|
|
701
|
+
fetchResource(pageUrl, timeoutSec),
|
|
702
|
+
fetchResource(`${origin}/sitemap.xml`, timeoutSec),
|
|
703
|
+
]);
|
|
704
|
+
|
|
705
|
+
const homeInfo = homeRes.body ? inspectHtmlDocument(homeRes.body) : { title: parsed.hostname, meta_description: "" };
|
|
706
|
+
const candidateUrls = new Set([`${origin}/`]);
|
|
707
|
+
|
|
708
|
+
if (sitemapRes.status === 200 && sitemapRes.body) {
|
|
709
|
+
for (const m of sitemapRes.body.matchAll(/<loc>\s*([^<\s]+)\s*<\/loc>/gi)) {
|
|
710
|
+
try {
|
|
711
|
+
const u = new URL(m[1].trim());
|
|
712
|
+
if (u.origin === origin && !u.pathname.endsWith(".xml")) {
|
|
713
|
+
candidateUrls.add(u.toString());
|
|
714
|
+
}
|
|
715
|
+
} catch {
|
|
716
|
+
// ignore invalid URL
|
|
717
|
+
}
|
|
718
|
+
if (candidateUrls.size >= maxLinks * 3) break;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
if (homeRes.body && candidateUrls.size < maxLinks) {
|
|
723
|
+
for (const m of homeRes.body.matchAll(/<a\b[^>]*href\s*=\s*["']([^"'#]+)["']/gi)) {
|
|
724
|
+
try {
|
|
725
|
+
const u = new URL(m[1].trim(), origin);
|
|
726
|
+
if (u.origin === origin && (u.protocol === "https:" || u.protocol === "http:")) {
|
|
727
|
+
candidateUrls.add(u.toString());
|
|
728
|
+
}
|
|
729
|
+
} catch {
|
|
730
|
+
// ignore
|
|
731
|
+
}
|
|
732
|
+
if (candidateUrls.size >= maxLinks * 2) break;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
const selectedUrls = [...candidateUrls].slice(0, maxLinks);
|
|
737
|
+
const pageSummaries = await Promise.all(
|
|
738
|
+
selectedUrls.map(async (u) => {
|
|
739
|
+
if (u === pageUrl && homeRes.body) {
|
|
740
|
+
return {
|
|
741
|
+
url: u,
|
|
742
|
+
pathname: new URL(u).pathname,
|
|
743
|
+
title: homeInfo.title || parsed.hostname,
|
|
744
|
+
description: homeInfo.meta_description || "Official homepage",
|
|
745
|
+
ok: homeRes.status === 200,
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
const r = await fetchResource(u, Math.min(timeoutSec, 8));
|
|
749
|
+
if (r.status !== 200 || !r.body) return { url: u, pathname: new URL(u).pathname, ok: false };
|
|
750
|
+
const inf = inspectHtmlDocument(r.body);
|
|
751
|
+
return {
|
|
752
|
+
url: u,
|
|
753
|
+
pathname: new URL(u).pathname,
|
|
754
|
+
title: inf.title || new URL(u).pathname,
|
|
755
|
+
description: inf.meta_description || "",
|
|
756
|
+
ok: true,
|
|
757
|
+
};
|
|
758
|
+
})
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
const validPages = pageSummaries.filter((p) => p.ok);
|
|
762
|
+
const grouped = new Map();
|
|
763
|
+
for (const p of validPages) {
|
|
764
|
+
const sec = classifyPathSection(p.pathname);
|
|
765
|
+
if (!grouped.has(sec)) grouped.set(sec, []);
|
|
766
|
+
grouped.get(sec).push(p);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
const siteTitle = homeInfo.title ? homeInfo.title.split(/\s+[|\-–—]\s+/)[0].trim() : parsed.hostname;
|
|
770
|
+
const summaryLine =
|
|
771
|
+
homeInfo.meta_description || `Machine-readable index of ${siteTitle} (${origin}) for AI search engines and LLM agents.`;
|
|
772
|
+
|
|
773
|
+
const mdLines = [`# ${siteTitle}`, "", `> ${summaryLine}`, ""];
|
|
774
|
+
for (const [sec, items] of grouped.entries()) {
|
|
775
|
+
mdLines.push(`## ${sec}`, "");
|
|
776
|
+
for (const item of items) {
|
|
777
|
+
const descSuffix = item.description ? `: ${item.description.replace(/\s+/g, " ").slice(0, 160)}` : "";
|
|
778
|
+
mdLines.push(`- [${item.title}](${item.url})${descSuffix}`);
|
|
779
|
+
}
|
|
780
|
+
mdLines.push("");
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
return {
|
|
784
|
+
mode: "generate",
|
|
785
|
+
origin,
|
|
786
|
+
pages_indexed: validPages.length,
|
|
787
|
+
generated_markdown: mdLines.join("\n").trim() + "\n",
|
|
788
|
+
platform: "https://www.innflows.com/platform/website-ai-audit",
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
export async function inspectSchemaEntityGraph(targetUrl, timeoutSec = 12) {
|
|
793
|
+
const { origin, pageUrl } = normalizeUrlInput(targetUrl);
|
|
794
|
+
const page = await fetchResource(pageUrl, timeoutSec);
|
|
795
|
+
if (page.status !== 200 || !page.body) {
|
|
796
|
+
return {
|
|
797
|
+
url: pageUrl,
|
|
798
|
+
origin,
|
|
799
|
+
http_status: page.status,
|
|
800
|
+
error: `Target URL returned HTTP ${page.status}`,
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
const info = inspectHtmlDocument(page.body);
|
|
805
|
+
const graph = extractSchemaGraphFromHtml(page.body);
|
|
806
|
+
|
|
807
|
+
const recommended = ["Organization", "WebSite"];
|
|
808
|
+
const typeSet = new Set(graph.unique_types);
|
|
809
|
+
const hasAppOrProductOrArticle =
|
|
810
|
+
typeSet.has("SoftwareApplication") ||
|
|
811
|
+
typeSet.has("WebApplication") ||
|
|
812
|
+
typeSet.has("Product") ||
|
|
813
|
+
typeSet.has("Article") ||
|
|
814
|
+
typeSet.has("BlogPosting") ||
|
|
815
|
+
typeSet.has("TechArticle");
|
|
816
|
+
|
|
817
|
+
const missingCore = recommended.filter((t) => !typeSet.has(t));
|
|
818
|
+
if (!hasAppOrProductOrArticle) {
|
|
819
|
+
missingCore.push("SoftwareApplication | Product | Article");
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
const sampleSameAs = graph.same_as_urls.slice(0, 8);
|
|
823
|
+
const sameAsChecks = await Promise.all(
|
|
824
|
+
sampleSameAs.map(async (u) => {
|
|
825
|
+
try {
|
|
826
|
+
const r = await fetchResource(u, Math.min(timeoutSec, 8));
|
|
827
|
+
return { url: u, http_status: r.status, reachable: r.status >= 200 && r.status < 405 };
|
|
828
|
+
} catch {
|
|
829
|
+
return { url: u, http_status: 0, reachable: false };
|
|
830
|
+
}
|
|
831
|
+
})
|
|
832
|
+
);
|
|
833
|
+
|
|
834
|
+
const starterTemplate =
|
|
835
|
+
missingCore.length > 0
|
|
836
|
+
? {
|
|
837
|
+
"@context": "https://schema.org",
|
|
838
|
+
"@graph": [
|
|
839
|
+
{
|
|
840
|
+
"@type": "Organization",
|
|
841
|
+
"@id": `${origin}/#organization`,
|
|
842
|
+
name: info.title ? info.title.split(/\s+[|\-–—]\s+/)[0].trim() : new URL(origin).hostname,
|
|
843
|
+
url: origin,
|
|
844
|
+
sameAs: graph.same_as_urls.length > 0 ? graph.same_as_urls : [`https://github.com/YOUR_ORG`],
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
"@type": "WebSite",
|
|
848
|
+
"@id": `${origin}/#website`,
|
|
849
|
+
url: origin,
|
|
850
|
+
name: info.title || new URL(origin).hostname,
|
|
851
|
+
publisher: { "@id": `${origin}/#organization` },
|
|
852
|
+
},
|
|
853
|
+
],
|
|
854
|
+
}
|
|
855
|
+
: null;
|
|
856
|
+
|
|
857
|
+
return {
|
|
858
|
+
url: pageUrl,
|
|
859
|
+
origin,
|
|
860
|
+
http_status: page.status,
|
|
861
|
+
blocks_count: graph.blocks_count,
|
|
862
|
+
parse_errors: graph.parse_errors,
|
|
863
|
+
unique_types: graph.unique_types,
|
|
864
|
+
defined_ids: graph.defined_ids,
|
|
865
|
+
dangling_id_references: graph.dangling_ids,
|
|
866
|
+
entities: graph.entities,
|
|
867
|
+
same_as_count: graph.same_as_urls.length,
|
|
868
|
+
sampled_same_as_checks: sameAsChecks,
|
|
869
|
+
missing_recommended_types: missingCore,
|
|
870
|
+
suggested_json_ld_template: starterTemplate,
|
|
871
|
+
platform: "https://www.innflows.com/platform/website-ai-audit",
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
export async function compareWebsites(urls, timeoutSec = 12) {
|
|
876
|
+
if (!Array.isArray(urls) || urls.length < 2) {
|
|
877
|
+
throw new Error("Please provide at least 2 URLs to compare.");
|
|
878
|
+
}
|
|
879
|
+
const capped = urls.slice(0, 5);
|
|
880
|
+
const reports = await Promise.all(capped.map((u) => runAudit(u, timeoutSec)));
|
|
881
|
+
|
|
882
|
+
const rows = reports.map((r) => {
|
|
883
|
+
const byId = Object.fromEntries((r.checks || []).map((c) => [c.id, c]));
|
|
884
|
+
return {
|
|
885
|
+
url: r.url,
|
|
886
|
+
score: r.score ?? 0,
|
|
887
|
+
passed: `${r.passed ?? 0}/${r.total ?? 0}`,
|
|
888
|
+
ssr_status: byId.ssr_text?.detail || "n/a",
|
|
889
|
+
json_ld: byId.json_ld?.detail || "n/a",
|
|
890
|
+
ai_crawlers: byId.ai_crawlers?.detail || "n/a",
|
|
891
|
+
llms_txt: byId.llms_txt?.detail || "n/a",
|
|
892
|
+
sitemap_xml: byId.sitemap_xml?.detail || "n/a",
|
|
893
|
+
};
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
const mdLines = [
|
|
897
|
+
"| Website | Score | Passed | SSR HTML Text | Schema.org JSON-LD | AI Crawlers (robots.txt) | /llms.txt | /sitemap.xml |",
|
|
898
|
+
"| :--- | :---: | :---: | :--- | :--- | :--- | :--- | :--- |",
|
|
899
|
+
...rows.map(
|
|
900
|
+
(r) =>
|
|
901
|
+
`| ${r.url} | **${r.score}/100** | ${r.passed} | ${r.ssr_status} | ${r.json_ld} | ${r.ai_crawlers} | ${r.llms_txt} | ${r.sitemap_xml} |`
|
|
902
|
+
),
|
|
903
|
+
];
|
|
904
|
+
|
|
905
|
+
return {
|
|
906
|
+
compared_count: rows.length,
|
|
907
|
+
markdown_table: mdLines.join("\n"),
|
|
908
|
+
results: rows,
|
|
909
|
+
raw_reports: reports,
|
|
910
|
+
platform: "https://www.innflows.com/platform/website-ai-audit",
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
|
|
411
914
|
export function formatReportText(report) {
|
|
412
915
|
const icons = { pass: "[PASS]", warn: "[WARN]", fail: "[FAIL]" };
|
|
413
916
|
const lines = [
|
|
@@ -427,6 +930,184 @@ export function formatReportText(report) {
|
|
|
427
930
|
return lines.join("\n");
|
|
428
931
|
}
|
|
429
932
|
|
|
933
|
+
export function formatProbeText(probeReport) {
|
|
934
|
+
const lines = [
|
|
935
|
+
"",
|
|
936
|
+
`AI Crawler Live HTTP & WAF Probe — ${probeReport.url}`,
|
|
937
|
+
"=".repeat(78),
|
|
938
|
+
`${"Agent".padEnd(20)} | ${"robots.txt".padEnd(15)} | ${"HTTP".padEnd(6)} | ${"SSR Chars".padEnd(10)} | Diagnosis`,
|
|
939
|
+
"-".repeat(78),
|
|
940
|
+
];
|
|
941
|
+
for (const p of probeReport.probes) {
|
|
942
|
+
const diag = p.silent_waf_block
|
|
943
|
+
? `SILENT WAF BLOCK (${p.waf_diagnosis || `HTTP ${p.http_status}`})`
|
|
944
|
+
: p.waf_diagnosis || "OK";
|
|
945
|
+
lines.push(
|
|
946
|
+
`${p.agent.padEnd(20)} | ${String(p.robots_txt_posture).padEnd(15)} | ${String(p.http_status).padEnd(6)} | ${String(p.visible_text_chars).padEnd(10)} | ${diag}`
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
lines.push("-".repeat(78));
|
|
950
|
+
lines.push(
|
|
951
|
+
probeReport.silent_waf_blocks_detected
|
|
952
|
+
? `Result: WARN — Silent WAF/CDN blocks detected for: ${probeReport.silent_blocked_agents.join(", ")}`
|
|
953
|
+
: "Result: PASS — Live HTTP responses match /robots.txt posture across all probed AI crawlers."
|
|
954
|
+
);
|
|
955
|
+
lines.push("");
|
|
956
|
+
return lines.join("\n");
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
export const MCP_TOOLS = [
|
|
960
|
+
{
|
|
961
|
+
name: "audit_website_ai_readiness",
|
|
962
|
+
description:
|
|
963
|
+
"Run a comprehensive 9-check Generative Engine Optimization (GEO / AEO) technical readiness audit on a single public webpage URL. Use this first for an overall 0-100 readiness score covering HTTP reachability, noindex directives, initial SSR HTML text extractability, canonical/meta tags, Schema.org JSON-LD presence, /robots.txt AI crawler rules, /llms.txt, and /sitemap.xml. For live WAF/Cloudflare bot-blocking tests, deep llms.txt generation, or multi-site comparisons, use the specialized tools in this server.",
|
|
964
|
+
inputSchema: {
|
|
965
|
+
type: "object",
|
|
966
|
+
properties: {
|
|
967
|
+
url: {
|
|
968
|
+
type: "string",
|
|
969
|
+
description: "Public webpage URL to audit (e.g. https://www.innflows.com/platform).",
|
|
970
|
+
},
|
|
971
|
+
timeout_seconds: {
|
|
972
|
+
type: "number",
|
|
973
|
+
description: "Per-request HTTP timeout in seconds (default: 12, range: 3-30).",
|
|
974
|
+
default: 12,
|
|
975
|
+
},
|
|
976
|
+
},
|
|
977
|
+
required: ["url"],
|
|
978
|
+
},
|
|
979
|
+
annotations: {
|
|
980
|
+
title: "Audit Website AI Readiness",
|
|
981
|
+
readOnlyHint: true,
|
|
982
|
+
destructiveHint: false,
|
|
983
|
+
idempotentHint: true,
|
|
984
|
+
openWorldHint: true,
|
|
985
|
+
},
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
name: "probe_ai_crawler_access",
|
|
989
|
+
description:
|
|
990
|
+
"Simulate live HTTP requests with real AI search crawler User-Agent headers (OAI-SearchBot, GPTBot, ChatGPT-User, ClaudeBot, PerplexityBot, Google-Extended, Applebot-Extended) alongside a browser baseline to detect silent WAF, CDN, or Cloudflare bot challenges that block AI retrievers even when /robots.txt allows them. Use this when diagnosing why AI search engines fail to fetch or cite an otherwise indexable page.",
|
|
991
|
+
inputSchema: {
|
|
992
|
+
type: "object",
|
|
993
|
+
properties: {
|
|
994
|
+
url: {
|
|
995
|
+
type: "string",
|
|
996
|
+
description: "Public webpage URL to probe across AI crawler User-Agents (e.g. https://www.innflows.com).",
|
|
997
|
+
},
|
|
998
|
+
timeout_seconds: {
|
|
999
|
+
type: "number",
|
|
1000
|
+
description: "Per-request HTTP timeout in seconds (default: 12).",
|
|
1001
|
+
default: 12,
|
|
1002
|
+
},
|
|
1003
|
+
},
|
|
1004
|
+
required: ["url"],
|
|
1005
|
+
},
|
|
1006
|
+
annotations: {
|
|
1007
|
+
title: "Probe Live AI Crawler & WAF Access",
|
|
1008
|
+
readOnlyHint: true,
|
|
1009
|
+
destructiveHint: false,
|
|
1010
|
+
idempotentHint: true,
|
|
1011
|
+
openWorldHint: true,
|
|
1012
|
+
},
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
name: "inspect_or_generate_llms_txt",
|
|
1016
|
+
description:
|
|
1017
|
+
"Validate an existing /llms.txt machine-readable index against the llmstxt.org Markdown specification (checking H1 title, summary blockquote, section headings, SPA HTML soft-200 fallbacks, and dead links) OR synthesize a ready-to-publish /llms.txt file from a website's homepage and /sitemap.xml. Set mode='validate' to audit a live /llms.txt, or mode='generate' to draft one.",
|
|
1018
|
+
inputSchema: {
|
|
1019
|
+
type: "object",
|
|
1020
|
+
properties: {
|
|
1021
|
+
url: {
|
|
1022
|
+
type: "string",
|
|
1023
|
+
description: "Website root URL or direct /llms.txt URL (e.g. https://www.innflows.com).",
|
|
1024
|
+
},
|
|
1025
|
+
mode: {
|
|
1026
|
+
type: "string",
|
|
1027
|
+
enum: ["validate", "generate"],
|
|
1028
|
+
description: "Operation mode: 'validate' inspects the live /llms.txt and samples link health; 'generate' crawls sitemap.xml and homepage metadata to draft a compliant Markdown /llms.txt.",
|
|
1029
|
+
default: "validate",
|
|
1030
|
+
},
|
|
1031
|
+
max_links: {
|
|
1032
|
+
type: "number",
|
|
1033
|
+
description: "Maximum same-origin URLs to include when mode='generate' (default: 20, max: 50).",
|
|
1034
|
+
default: 20,
|
|
1035
|
+
},
|
|
1036
|
+
timeout_seconds: {
|
|
1037
|
+
type: "number",
|
|
1038
|
+
description: "Per-request HTTP timeout in seconds (default: 12).",
|
|
1039
|
+
default: 12,
|
|
1040
|
+
},
|
|
1041
|
+
},
|
|
1042
|
+
required: ["url"],
|
|
1043
|
+
},
|
|
1044
|
+
annotations: {
|
|
1045
|
+
title: "Validate or Generate llms.txt",
|
|
1046
|
+
readOnlyHint: true,
|
|
1047
|
+
destructiveHint: false,
|
|
1048
|
+
idempotentHint: true,
|
|
1049
|
+
openWorldHint: true,
|
|
1050
|
+
},
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
name: "inspect_schema_entity_graph",
|
|
1054
|
+
description:
|
|
1055
|
+
"Deeply inspect all Schema.org JSON-LD blocks on a webpage, extracting @type entities, @id node anchors, dangling internal #fragment @id references, and Organization.sameAs authority links (with live HTTP reachability checks). Also generates a starter @graph JSON-LD snippet when core GEO entities (Organization, WebSite, SoftwareApplication/Product/Article) are missing.",
|
|
1056
|
+
inputSchema: {
|
|
1057
|
+
type: "object",
|
|
1058
|
+
properties: {
|
|
1059
|
+
url: {
|
|
1060
|
+
type: "string",
|
|
1061
|
+
description: "Public webpage URL whose Schema.org JSON-LD entity graph should be analyzed.",
|
|
1062
|
+
},
|
|
1063
|
+
timeout_seconds: {
|
|
1064
|
+
type: "number",
|
|
1065
|
+
description: "Per-request HTTP timeout in seconds (default: 12).",
|
|
1066
|
+
default: 12,
|
|
1067
|
+
},
|
|
1068
|
+
},
|
|
1069
|
+
required: ["url"],
|
|
1070
|
+
},
|
|
1071
|
+
annotations: {
|
|
1072
|
+
title: "Inspect Schema.org JSON-LD Entity Graph",
|
|
1073
|
+
readOnlyHint: true,
|
|
1074
|
+
destructiveHint: false,
|
|
1075
|
+
idempotentHint: true,
|
|
1076
|
+
openWorldHint: true,
|
|
1077
|
+
},
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
name: "compare_websites_ai_readiness",
|
|
1081
|
+
description:
|
|
1082
|
+
"Benchmark 2 to 5 public websites side by side across all GEO/AEO AI-readiness dimensions (overall score, SSR visible HTML characters, Schema.org JSON-LD types, /robots.txt AI crawler rules, /llms.txt, and /sitemap.xml) and return both a ready-to-share Markdown comparison table and structured JSON results. Use this for competitive GEO benchmarking.",
|
|
1083
|
+
inputSchema: {
|
|
1084
|
+
type: "object",
|
|
1085
|
+
properties: {
|
|
1086
|
+
urls: {
|
|
1087
|
+
type: "array",
|
|
1088
|
+
items: { type: "string" },
|
|
1089
|
+
minItems: 2,
|
|
1090
|
+
maxItems: 5,
|
|
1091
|
+
description: "List of 2 to 5 public webpage URLs to benchmark side by side.",
|
|
1092
|
+
},
|
|
1093
|
+
timeout_seconds: {
|
|
1094
|
+
type: "number",
|
|
1095
|
+
description: "Per-request HTTP timeout in seconds (default: 12).",
|
|
1096
|
+
default: 12,
|
|
1097
|
+
},
|
|
1098
|
+
},
|
|
1099
|
+
required: ["urls"],
|
|
1100
|
+
},
|
|
1101
|
+
annotations: {
|
|
1102
|
+
title: "Compare Websites AI Readiness",
|
|
1103
|
+
readOnlyHint: true,
|
|
1104
|
+
destructiveHint: false,
|
|
1105
|
+
idempotentHint: true,
|
|
1106
|
+
openWorldHint: true,
|
|
1107
|
+
},
|
|
1108
|
+
},
|
|
1109
|
+
];
|
|
1110
|
+
|
|
430
1111
|
export async function handleMcpRequest(msg, auditFn = runAudit) {
|
|
431
1112
|
if (!msg || typeof msg !== "object") return null;
|
|
432
1113
|
const { id, method, params } = msg;
|
|
@@ -456,74 +1137,111 @@ export async function handleMcpRequest(msg, auditFn = runAudit) {
|
|
|
456
1137
|
jsonrpc: "2.0",
|
|
457
1138
|
id,
|
|
458
1139
|
result: {
|
|
459
|
-
tools:
|
|
460
|
-
{
|
|
461
|
-
name: "audit_website_ai_readiness",
|
|
462
|
-
description:
|
|
463
|
-
"Run a Generative Engine Optimization (GEO) technical AI-readiness audit on a public webpage URL. Inspects HTTP reachability, indexability directives, initial SSR HTML text extractability, canonical/meta tags, Schema.org JSON-LD (@type and @id), /robots.txt AI crawler access (OAI-SearchBot, GPTBot, Google-Extended, ClaudeBot, PerplexityBot), /llms.txt, and /sitemap.xml.",
|
|
464
|
-
inputSchema: {
|
|
465
|
-
type: "object",
|
|
466
|
-
properties: {
|
|
467
|
-
url: {
|
|
468
|
-
type: "string",
|
|
469
|
-
description: "Public webpage URL to audit (e.g. https://www.innflows.com/platform)",
|
|
470
|
-
},
|
|
471
|
-
timeout_seconds: {
|
|
472
|
-
type: "number",
|
|
473
|
-
description: "Per-request timeout in seconds (default: 12)",
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
required: ["url"],
|
|
477
|
-
},
|
|
478
|
-
annotations: {
|
|
479
|
-
readOnlyHint: true,
|
|
480
|
-
openWorldHint: true,
|
|
481
|
-
},
|
|
482
|
-
},
|
|
483
|
-
],
|
|
1140
|
+
tools: MCP_TOOLS,
|
|
484
1141
|
},
|
|
485
1142
|
};
|
|
486
1143
|
}
|
|
487
1144
|
|
|
488
1145
|
if (method === "tools/call") {
|
|
489
1146
|
const toolName = params?.name;
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
id,
|
|
494
|
-
error: { code: -32601, message: `Unknown tool: ${toolName}` },
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
const targetUrl = params?.arguments?.url;
|
|
498
|
-
const timeoutSec = Number(params?.arguments?.timeout_seconds || 12);
|
|
499
|
-
if (!targetUrl || typeof targetUrl !== "string") {
|
|
500
|
-
return {
|
|
501
|
-
jsonrpc: "2.0",
|
|
502
|
-
id,
|
|
503
|
-
error: { code: -32602, message: "Missing required string parameter: url" },
|
|
504
|
-
};
|
|
505
|
-
}
|
|
1147
|
+
const args = params?.arguments || {};
|
|
1148
|
+
const timeoutSec = Number(args.timeout_seconds || 12);
|
|
1149
|
+
|
|
506
1150
|
try {
|
|
507
|
-
|
|
1151
|
+
if (toolName === "audit_website_ai_readiness") {
|
|
1152
|
+
if (!args.url || typeof args.url !== "string") {
|
|
1153
|
+
return { jsonrpc: "2.0", id, error: { code: -32602, message: "Missing required string parameter: url" } };
|
|
1154
|
+
}
|
|
1155
|
+
const report = await auditFn(args.url, timeoutSec);
|
|
1156
|
+
return {
|
|
1157
|
+
jsonrpc: "2.0",
|
|
1158
|
+
id,
|
|
1159
|
+
result: {
|
|
1160
|
+
content: [{ type: "text", text: `${formatReportText(report)}\n${JSON.stringify(report, null, 2)}` }],
|
|
1161
|
+
isError: false,
|
|
1162
|
+
},
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
if (toolName === "probe_ai_crawler_access") {
|
|
1167
|
+
if (!args.url || typeof args.url !== "string") {
|
|
1168
|
+
return { jsonrpc: "2.0", id, error: { code: -32602, message: "Missing required string parameter: url" } };
|
|
1169
|
+
}
|
|
1170
|
+
const report = await probeCrawlerAccess(args.url, timeoutSec);
|
|
1171
|
+
return {
|
|
1172
|
+
jsonrpc: "2.0",
|
|
1173
|
+
id,
|
|
1174
|
+
result: {
|
|
1175
|
+
content: [{ type: "text", text: `${formatProbeText(report)}\n${JSON.stringify(report, null, 2)}` }],
|
|
1176
|
+
isError: false,
|
|
1177
|
+
},
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
if (toolName === "inspect_or_generate_llms_txt") {
|
|
1182
|
+
if (!args.url || typeof args.url !== "string") {
|
|
1183
|
+
return { jsonrpc: "2.0", id, error: { code: -32602, message: "Missing required string parameter: url" } };
|
|
1184
|
+
}
|
|
1185
|
+
const report = await inspectOrGenerateLlmsTxt(args.url, {
|
|
1186
|
+
mode: args.mode || "validate",
|
|
1187
|
+
maxLinks: args.max_links || 20,
|
|
1188
|
+
timeoutSec,
|
|
1189
|
+
});
|
|
1190
|
+
const textOut =
|
|
1191
|
+
report.mode === "generate" && report.generated_markdown
|
|
1192
|
+
? `${report.generated_markdown}\n---\n${JSON.stringify({ origin: report.origin, pages_indexed: report.pages_indexed }, null, 2)}`
|
|
1193
|
+
: JSON.stringify(report, null, 2);
|
|
1194
|
+
return {
|
|
1195
|
+
jsonrpc: "2.0",
|
|
1196
|
+
id,
|
|
1197
|
+
result: {
|
|
1198
|
+
content: [{ type: "text", text: textOut }],
|
|
1199
|
+
isError: false,
|
|
1200
|
+
},
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
if (toolName === "inspect_schema_entity_graph") {
|
|
1205
|
+
if (!args.url || typeof args.url !== "string") {
|
|
1206
|
+
return { jsonrpc: "2.0", id, error: { code: -32602, message: "Missing required string parameter: url" } };
|
|
1207
|
+
}
|
|
1208
|
+
const report = await inspectSchemaEntityGraph(args.url, timeoutSec);
|
|
1209
|
+
return {
|
|
1210
|
+
jsonrpc: "2.0",
|
|
1211
|
+
id,
|
|
1212
|
+
result: {
|
|
1213
|
+
content: [{ type: "text", text: JSON.stringify(report, null, 2) }],
|
|
1214
|
+
isError: false,
|
|
1215
|
+
},
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
if (toolName === "compare_websites_ai_readiness") {
|
|
1220
|
+
if (!Array.isArray(args.urls) || args.urls.length < 2) {
|
|
1221
|
+
return { jsonrpc: "2.0", id, error: { code: -32602, message: "Parameter 'urls' must be an array of 2 to 5 URLs" } };
|
|
1222
|
+
}
|
|
1223
|
+
const report = await compareWebsites(args.urls, timeoutSec);
|
|
1224
|
+
return {
|
|
1225
|
+
jsonrpc: "2.0",
|
|
1226
|
+
id,
|
|
1227
|
+
result: {
|
|
1228
|
+
content: [{ type: "text", text: `${report.markdown_table}\n\n${JSON.stringify(report.results, null, 2)}` }],
|
|
1229
|
+
isError: false,
|
|
1230
|
+
},
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
|
|
508
1234
|
return {
|
|
509
1235
|
jsonrpc: "2.0",
|
|
510
1236
|
id,
|
|
511
|
-
|
|
512
|
-
content: [
|
|
513
|
-
{
|
|
514
|
-
type: "text",
|
|
515
|
-
text: `${formatReportText(report)}\n${JSON.stringify(report, null, 2)}`,
|
|
516
|
-
},
|
|
517
|
-
],
|
|
518
|
-
isError: false,
|
|
519
|
-
},
|
|
1237
|
+
error: { code: -32601, message: `Unknown tool: ${toolName}` },
|
|
520
1238
|
};
|
|
521
1239
|
} catch (err) {
|
|
522
1240
|
return {
|
|
523
1241
|
jsonrpc: "2.0",
|
|
524
1242
|
id,
|
|
525
1243
|
result: {
|
|
526
|
-
content: [{ type: "text", text: `
|
|
1244
|
+
content: [{ type: "text", text: `Tool execution error: ${err.message || String(err)}` }],
|
|
527
1245
|
isError: true,
|
|
528
1246
|
},
|
|
529
1247
|
};
|
|
@@ -556,6 +1274,24 @@ function startMcpStdioServer() {
|
|
|
556
1274
|
});
|
|
557
1275
|
}
|
|
558
1276
|
|
|
1277
|
+
function printHelp() {
|
|
1278
|
+
console.log(
|
|
1279
|
+
[
|
|
1280
|
+
`@innflows/ai-readiness-audit v${PKG_VERSION} — GEO & AEO Website AI-Readiness Toolkit`,
|
|
1281
|
+
"",
|
|
1282
|
+
"Usage:",
|
|
1283
|
+
" npx @innflows/ai-readiness-audit <url> [--json] [--fail-under 80] [--timeout 12]",
|
|
1284
|
+
" npx @innflows/ai-readiness-audit probe-crawlers <url> [--json]",
|
|
1285
|
+
" npx @innflows/ai-readiness-audit llms-txt <url> [--generate] [--max-links 20] [--json]",
|
|
1286
|
+
" npx @innflows/ai-readiness-audit schema-graph <url> [--json]",
|
|
1287
|
+
" npx @innflows/ai-readiness-audit compare <url1> <url2> [url3...] [--json]",
|
|
1288
|
+
" npx -y @innflows/ai-readiness-audit --mcp # Start 5-tool MCP stdio server",
|
|
1289
|
+
"",
|
|
1290
|
+
"Maintained by Innflows GEO (https://www.innflows.com/platform/website-ai-audit)",
|
|
1291
|
+
].join("\n")
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
559
1295
|
async function main() {
|
|
560
1296
|
const argv = process.argv.slice(2);
|
|
561
1297
|
const invokedAsMcp = (process.argv[1] || "").endsWith("ai-readiness-audit-mcp");
|
|
@@ -564,37 +1300,96 @@ async function main() {
|
|
|
564
1300
|
return;
|
|
565
1301
|
}
|
|
566
1302
|
|
|
1303
|
+
if (argv.includes("-v") || argv.includes("--version")) {
|
|
1304
|
+
console.log(PKG_VERSION);
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
567
1308
|
if (argv.includes("-h") || argv.includes("--help") || argv.length === 0) {
|
|
568
|
-
|
|
569
|
-
[
|
|
570
|
-
"Usage:",
|
|
571
|
-
" npx @innflows/ai-readiness-audit <url> [--json] [--timeout 12]",
|
|
572
|
-
" npx -y @innflows/ai-readiness-audit --mcp # Start MCP stdio server",
|
|
573
|
-
"",
|
|
574
|
-
"Maintained by Innflows GEO (https://www.innflows.com/platform/website-ai-audit)",
|
|
575
|
-
].join("\n")
|
|
576
|
-
);
|
|
1309
|
+
printHelp();
|
|
577
1310
|
process.exit(argv.length === 0 ? 1 : 0);
|
|
578
1311
|
}
|
|
579
1312
|
|
|
580
1313
|
const jsonOut = argv.includes("--json");
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
1314
|
+
const getNumFlag = (flag, fallback) => {
|
|
1315
|
+
const idx = argv.indexOf(flag);
|
|
1316
|
+
return idx !== -1 && argv[idx + 1] ? Number(argv[idx + 1]) : fallback;
|
|
1317
|
+
};
|
|
1318
|
+
const timeoutSec = getNumFlag("--timeout", 12) || 12;
|
|
1319
|
+
const failUnder = getNumFlag("--fail-under", null);
|
|
1320
|
+
const maxLinks = getNumFlag("--max-links", 20) || 20;
|
|
1321
|
+
|
|
1322
|
+
const valuedFlags = new Set(["--timeout", "--fail-under", "--max-links"]);
|
|
1323
|
+
const positional = [];
|
|
1324
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
1325
|
+
const a = argv[i];
|
|
1326
|
+
if (valuedFlags.has(a)) {
|
|
1327
|
+
i += 1;
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
if (!a.startsWith("-")) positional.push(a);
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
const subcommands = new Set(["audit", "probe-crawlers", "llms-txt", "schema-graph", "compare"]);
|
|
1334
|
+
const cmd = subcommands.has(positional[0]) ? positional[0] : "audit";
|
|
1335
|
+
const targets = subcommands.has(positional[0]) ? positional.slice(1) : positional;
|
|
1336
|
+
|
|
1337
|
+
if (cmd === "compare") {
|
|
1338
|
+
if (targets.length < 2) {
|
|
1339
|
+
console.error("Error: 'compare' requires 2 to 5 URLs.");
|
|
1340
|
+
process.exit(1);
|
|
1341
|
+
}
|
|
1342
|
+
const cmp = await compareWebsites(targets, timeoutSec);
|
|
1343
|
+
console.log(jsonOut ? JSON.stringify(cmp, null, 2) : `\n${cmp.markdown_table}\n`);
|
|
1344
|
+
return;
|
|
585
1345
|
}
|
|
586
|
-
|
|
587
|
-
|
|
1346
|
+
|
|
1347
|
+
const targetUrl = targets[0];
|
|
1348
|
+
if (!targetUrl) {
|
|
588
1349
|
console.error("Error: missing <url> argument.");
|
|
589
1350
|
process.exit(1);
|
|
590
1351
|
}
|
|
591
1352
|
|
|
592
|
-
|
|
1353
|
+
if (cmd === "probe-crawlers") {
|
|
1354
|
+
const res = await probeCrawlerAccess(targetUrl, timeoutSec);
|
|
1355
|
+
console.log(jsonOut ? JSON.stringify(res, null, 2) : formatProbeText(res));
|
|
1356
|
+
if (failUnder !== null && res.silent_waf_blocks_detected) process.exit(2);
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
if (cmd === "llms-txt") {
|
|
1361
|
+
const generate = argv.includes("--generate");
|
|
1362
|
+
const res = await inspectOrGenerateLlmsTxt(targetUrl, {
|
|
1363
|
+
mode: generate ? "generate" : "validate",
|
|
1364
|
+
maxLinks,
|
|
1365
|
+
timeoutSec,
|
|
1366
|
+
});
|
|
1367
|
+
if (jsonOut) {
|
|
1368
|
+
console.log(JSON.stringify(res, null, 2));
|
|
1369
|
+
} else if (generate) {
|
|
1370
|
+
process.stdout.write(res.generated_markdown);
|
|
1371
|
+
} else {
|
|
1372
|
+
console.log(JSON.stringify(res, null, 2));
|
|
1373
|
+
}
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
if (cmd === "schema-graph") {
|
|
1378
|
+
const res = await inspectSchemaEntityGraph(targetUrl, timeoutSec);
|
|
1379
|
+
console.log(JSON.stringify(res, null, 2));
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
const report = await runAudit(targetUrl, timeoutSec);
|
|
593
1384
|
if (jsonOut) {
|
|
594
1385
|
console.log(JSON.stringify(report, null, 2));
|
|
595
1386
|
} else {
|
|
596
1387
|
console.log(formatReportText(report));
|
|
597
1388
|
}
|
|
1389
|
+
if (failUnder !== null && !Number.isNaN(failUnder) && report.score < failUnder) {
|
|
1390
|
+
console.error(`CI Gate Failed: score ${report.score}/100 is below --fail-under ${failUnder}.`);
|
|
1391
|
+
process.exit(2);
|
|
1392
|
+
}
|
|
598
1393
|
}
|
|
599
1394
|
|
|
600
1395
|
const isDirectRun =
|