mcp-web-validator 1.3.57 → 1.3.58

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 (138) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +18 -0
  3. package/SECURITY.md +10 -0
  4. package/dist/audit-history.js +2 -0
  5. package/dist/audit-history.js.map +1 -1
  6. package/dist/index.js +8 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/language-subtags.js +2 -0
  9. package/dist/language-subtags.js.map +1 -1
  10. package/dist/mcp-bounds.js.map +1 -1
  11. package/dist/modules/browser-ux/axe-review.js +2 -0
  12. package/dist/modules/browser-ux/axe-review.js.map +1 -1
  13. package/dist/modules/browser-ux/lighthouse-lab-probe.js +2 -0
  14. package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -1
  15. package/dist/modules/browser-ux/lighthouse-lab.js +2 -0
  16. package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -1
  17. package/dist/modules/browser-ux/media-diagnostics.js +2 -0
  18. package/dist/modules/browser-ux/media-diagnostics.js.map +1 -1
  19. package/dist/modules/browser-ux/raw-rendered-diff.js +90 -40
  20. package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -1
  21. package/dist/modules/browser-ux/raw-rendered-probe.js +18 -0
  22. package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -1
  23. package/dist/modules/browser-ux/resource-failures-probe.js +2 -0
  24. package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -1
  25. package/dist/modules/browser-ux/resource-failures.js +2 -0
  26. package/dist/modules/browser-ux/resource-failures.js.map +1 -1
  27. package/dist/modules/browser-ux/viewport-parity-probe.js +2 -0
  28. package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -1
  29. package/dist/modules/browser-ux/viewport-parity.js +2 -0
  30. package/dist/modules/browser-ux/viewport-parity.js.map +1 -1
  31. package/dist/modules/browser-ux/wcag-interactions.js +2 -0
  32. package/dist/modules/browser-ux/wcag-interactions.js.map +1 -1
  33. package/dist/modules/change-regression/availability-history-store.js +2 -0
  34. package/dist/modules/change-regression/availability-history-store.js.map +1 -1
  35. package/dist/modules/change-regression/crawler-log-correlation.js +2 -0
  36. package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -1
  37. package/dist/modules/change-regression/google-common-crawler-ip.js +2 -0
  38. package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -1
  39. package/dist/modules/change-regression/historical-comparisons.js +2 -0
  40. package/dist/modules/change-regression/historical-comparisons.js.map +1 -1
  41. package/dist/modules/change-regression/production-change-comparison.js +2 -0
  42. package/dist/modules/change-regression/production-change-comparison.js.map +1 -1
  43. package/dist/modules/change-regression/regression-alerts.js.map +1 -1
  44. package/dist/modules/change-regression/strict-observation-time.js +2 -0
  45. package/dist/modules/change-regression/strict-observation-time.js.map +1 -1
  46. package/dist/modules/content-schema/citation-methodology-consistency.js +2 -0
  47. package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -1
  48. package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -1
  49. package/dist/modules/content-schema/empty-boilerplate-content.js +2 -0
  50. package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -1
  51. package/dist/modules/content-schema/extract-citation-methodology.js +2 -0
  52. package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -1
  53. package/dist/modules/content-schema/extract-competitor-intent.js +2 -0
  54. package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -1
  55. package/dist/modules/content-schema/extract-main-content.js +2 -0
  56. package/dist/modules/content-schema/extract-main-content.js.map +1 -1
  57. package/dist/modules/content-schema/extract-metadata-consistency.js +2 -0
  58. package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -1
  59. package/dist/modules/content-schema/extract-product-claims.js +4 -1
  60. package/dist/modules/content-schema/extract-product-claims.js.map +1 -1
  61. package/dist/modules/content-schema/extract-structured-data.js +2 -0
  62. package/dist/modules/content-schema/extract-structured-data.js.map +1 -1
  63. package/dist/modules/content-schema/metadata-consistency.js +2 -0
  64. package/dist/modules/content-schema/metadata-consistency.js.map +1 -1
  65. package/dist/modules/content-schema/product-claims.js.map +1 -1
  66. package/dist/modules/content-schema/same-language-duplicates.js.map +1 -1
  67. package/dist/modules/content-schema/structured-data-validation.js +2 -0
  68. package/dist/modules/content-schema/structured-data-validation.js.map +1 -1
  69. package/dist/modules/external-metrics/crux-field-probe.js +2 -0
  70. package/dist/modules/external-metrics/crux-field-probe.js.map +1 -1
  71. package/dist/modules/external-metrics/crux-field.js +2 -0
  72. package/dist/modules/external-metrics/crux-field.js.map +1 -1
  73. package/dist/modules/http-crawl/availability-observations.d.ts +0 -5
  74. package/dist/modules/http-crawl/availability-observations.js +8 -17
  75. package/dist/modules/http-crawl/availability-observations.js.map +1 -1
  76. package/dist/modules/http-crawl/availability-probe.js.map +1 -1
  77. package/dist/modules/http-crawl/crawler-access-probe.js +2 -0
  78. package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -1
  79. package/dist/modules/http-crawl/crawler-access.js +2 -0
  80. package/dist/modules/http-crawl/crawler-access.js.map +1 -1
  81. package/dist/modules/http-crawl/http-delivery-probe.js +2 -0
  82. package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -1
  83. package/dist/modules/http-crawl/http-delivery.js +4 -1
  84. package/dist/modules/http-crawl/http-delivery.js.map +1 -1
  85. package/dist/modules/http-crawl/https-security.js +2 -0
  86. package/dist/modules/http-crawl/https-security.js.map +1 -1
  87. package/dist/modules/http-crawl/non-html-directives.js +44 -14
  88. package/dist/modules/http-crawl/non-html-directives.js.map +1 -1
  89. package/dist/modules/http-crawl/redirect-canonical-chains.js +2 -0
  90. package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -1
  91. package/dist/modules/http-crawl/redirect-canonical-probe.js +2 -0
  92. package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -1
  93. package/dist/modules/http-crawl/sitemap-inventory-probe.js +2 -0
  94. package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -1
  95. package/dist/modules/http-crawl/sitemap-inventory.js +21 -2
  96. package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -1
  97. package/dist/modules/http-crawl/url-variants.js +2 -0
  98. package/dist/modules/http-crawl/url-variants.js.map +1 -1
  99. package/dist/modules/site-architecture/extract-internal-links.js +38 -4
  100. package/dist/modules/site-architecture/extract-internal-links.js.map +1 -1
  101. package/dist/modules/site-architecture/extract-multilingual-page.js +2 -0
  102. package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -1
  103. package/dist/modules/site-architecture/internal-link-graph-probe.js +2 -0
  104. package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -1
  105. package/dist/modules/site-architecture/internal-link-graph.js +2 -0
  106. package/dist/modules/site-architecture/internal-link-graph.js.map +1 -1
  107. package/dist/modules/site-architecture/internal-link-quality.js +2 -0
  108. package/dist/modules/site-architecture/internal-link-quality.js.map +1 -1
  109. package/dist/modules/site-architecture/multilingual-clusters.js +2 -0
  110. package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -1
  111. package/dist/network-protocol.d.ts +3 -0
  112. package/dist/network-protocol.js +9 -0
  113. package/dist/network-protocol.js.map +1 -0
  114. package/dist/network.js +12 -0
  115. package/dist/network.js.map +1 -1
  116. package/dist/nu-ephemeral.js +2 -0
  117. package/dist/nu-ephemeral.js.map +1 -1
  118. package/dist/presentation.js +3 -1
  119. package/dist/presentation.js.map +1 -1
  120. package/dist/report.js +4 -2
  121. package/dist/report.js.map +1 -1
  122. package/dist/screenshot-proxy.js +2 -0
  123. package/dist/screenshot-proxy.js.map +1 -1
  124. package/dist/screenshot.d.ts +1 -1
  125. package/dist/screenshot.js +3 -1
  126. package/dist/screenshot.js.map +1 -1
  127. package/dist/seo-auditor.js +20 -10
  128. package/dist/seo-auditor.js.map +1 -1
  129. package/dist/stylelint-validator.js +2 -0
  130. package/dist/stylelint-validator.js.map +1 -1
  131. package/dist/version.js +2 -0
  132. package/dist/version.js.map +1 -1
  133. package/dist/visual-diff.js +9 -1
  134. package/dist/visual-diff.js.map +1 -1
  135. package/dist/w3c-validator.js +2 -0
  136. package/dist/w3c-validator.js.map +1 -1
  137. package/package.json +4 -3
  138. package/scripts/deep-audit-optional.mjs +7 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to this project are documented here. The project follows [Se
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [1.3.58] - 2026-11-29
8
+
9
+ ### Security and compatibility
10
+
11
+ - Require HTTPS by default for public network requests, including link checks,
12
+ live probes and browser subresources. Set the operator-controlled
13
+ `MCP_WEB_VALIDATOR_ALLOW_INSECURE_HTTP=1` only for intentional HTTP diagnostics.
14
+ - Block HTTPS-to-HTTP redirect downgrades and preserve existing private-address,
15
+ credential and custom-port restrictions. Offline HTTP observations remain supported.
16
+ - Require explicit opt-in for the optional external SiteOne crawler's execution;
17
+ dry-run planning remains available. Hosted MCP requests require HTTPS.
18
+ - Add regression tests, scoped coverage evidence and reproducible build verification.
19
+
7
20
  ## [1.3.57] - 2026-11-23
8
21
 
9
22
  ### Validated optional engines
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/mcp-web-validator.svg)](https://www.npmjs.com/package/mcp-web-validator)
4
4
  [![CI](https://github.com/AKzar1el/mcp-web-validator/actions/workflows/ci.yml/badge.svg)](https://github.com/AKzar1el/mcp-web-validator/actions/workflows/ci.yml)
5
+ [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/17270/badge)](https://www.bestpractices.dev/projects/17270)
5
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
7
  [![Indexed on TensorBlock MCP Index](https://mcp-index.tensorblock.co/v1/servers/github-akzar1el-mcp-web-validator-4b38b48a/badge.svg)](https://tensorblock.co/mcp/servers/github-akzar1el-mcp-web-validator-4b38b48a)
7
8
  [![mcp-web-validator MCP server](https://glama.ai/mcp/servers/AKzar1el/mcp-web-validator/badges/score.svg)](https://glama.ai/mcp/servers/AKzar1el/mcp-web-validator)
@@ -10,6 +11,7 @@
10
11
  An MCP server for HTML and CSS validation, technical SEO and accessibility checks, JSON-LD syntax validation, broken-link checks, and responsive screenshots. It is part of the [DigestSEO](https://digestseo.com/) suite of open-source SEO tools.
11
12
 
12
13
  - Product: [digestseo.com/validator-mcp](https://digestseo.com/validator-mcp/)
14
+ - Hosted app: [Install Web Validator by DigestSEO in ChatGPT](https://chatgpt.com/plugins/plugin_asdk_app_6adce051b5588191bc0260f16f58ae08) (bounded public-page and supplied-markup audits; no local file access).
13
15
  - Engineering case study: [DigestSEO MCP Suite — AI visibility, Search Console, web validation, and trend intelligence](https://tomiseregi.si/projects/digestseo-mcp-suite)
14
16
  - Documentation: [this README](https://github.com/AKzar1el/mcp-web-validator#readme)
15
17
  - Support: [digestseo.com/support](https://digestseo.com/support/)
@@ -36,6 +38,16 @@ Hosted endpoint:
36
38
  https://web-validator-mcp.digestseo.com/mcp
37
39
  ```
38
40
 
41
+ ### Gemini CLI
42
+
43
+ Install the extension from the public repository:
44
+
45
+ ```bash
46
+ gemini extensions install https://github.com/AKzar1el/mcp-web-validator
47
+ ```
48
+
49
+ The extension launches the version-pinned local npm MCP server over stdio. It requires Node.js 22.12 or newer. It does not enable hooks or mark the MCP server trusted. The local server can read selected files, contact external W3C validators and authorized public link targets, and write explicitly requested screenshots or local history; see the surface table and Privacy documentation above. Use only authorized inputs, and do not send confidential markup to external validators.
50
+
39
51
  ## Requirements
40
52
 
41
53
  - Optional reliability upgrades for local Nu Checker fallback, offline
@@ -185,6 +197,12 @@ For tighter local-file validation scope, optionally set `MCP_WEB_VALIDATOR_WORKS
185
197
 
186
198
  See the published [privacy policy](https://digestseo.com/privacy/) for data-handling details and [SECURITY.md](SECURITY.md) for private vulnerability reporting.
187
199
 
200
+ ### Secure network defaults
201
+
202
+ Live outbound public network operations default to HTTPS. Plain HTTP targets, links and browser subresources are blocked unless the operator explicitly sets `MCP_WEB_VALIDATOR_ALLOW_INSECURE_HTTP=1` in the local server environment or the hosted Worker's deployment environment. The hosted service itself requires incoming HTTPS regardless of this setting. HTTPS-to-HTTP redirect downgrades are not followed by the guarded fetch clients, even with opt-in. Private destinations and custom ports remain blocked. HTTP URLs in supplied offline observations, markup, and diagnostic reports can still be analyzed without making a request.
203
+
204
+ Use the opt-in only to diagnose a deliberately authorized HTTP site, never for confidential inputs. Set the variable to `1` only for that diagnostic environment and remove it afterward. The optional external SiteOne crawler also requires this opt-in for actual execution because its internal requests are not controlled by the guarded transport; its dry-run planning remains available without the setting. The local browser proxy and synthetic offline lab use loopback-only interprocess communication; optional Nu loopback checking is explicitly configured by the user and never exposed as a public network listener.
205
+
188
206
  ## Configure a local client
189
207
 
190
208
  ### Claude Desktop
package/SECURITY.md CHANGED
@@ -33,3 +33,13 @@ The following are normally outside this project's vulnerability scope unless the
33
33
  - social-engineering reports without a technical vulnerability;
34
34
  - automated scanner output without a reproducible impact; and
35
35
  - denial-of-service testing against the production endpoint without prior written permission.
36
+
37
+ ## Vulnerability handling process
38
+
39
+ 1. Report suspected vulnerabilities privately using the channels above. Do not include secrets, private data, or live exploit traffic.
40
+ 2. The maintainer acknowledges the report, records the affected version and surface, and establishes whether the behavior crosses a documented trust boundary. Reproduce using authorized, isolated fixtures where feasible; do not require public exploit demonstrations.
41
+ 3. Prioritize confirmed findings by severity, exposure, and available mitigations. Coordinate a focused fix and regression test, run the relevant CI and static-analysis checks, and verify the actual outcome before closing the report.
42
+ 4. Keep the reporter informed, coordinate disclosure and release when appropriate, and document affected and fixed versions. Credit the reporter with their consent; respect requests for anonymity. Do not treat a merged source fix as a published release until the distribution channel is verified.
43
+ 5. Reopen or privately investigate any credible report of an incomplete fix or bypass. Keep records of non-exploitable findings and their reasoning rather than concealing or suppressing them.
44
+
45
+ See the [security assurance case](docs/security-assurance-case.md) for the project's intended protections, evidence, and limitations.
@@ -1,3 +1,5 @@
1
+ // Copyright (c) 2026 AKzar1el and Web Validator contributors
2
+ // SPDX-License-Identifier: MIT
1
3
  import * as fs from "node:fs/promises";
2
4
  import * as os from "node:os";
3
5
  import * as path from "node:path";
@@ -1 +1 @@
1
- {"version":3,"file":"audit-history.js","sourceRoot":"","sources":["../src/audit-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAC/C,MAAM,sBAAsB,GAAG,OAAO,CAAC;AACvC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAC3C,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAE1C,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;IACvD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC;eACzD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;eACrB,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI;eAC1D,CAAC,GAAG,CAAC,IAAI,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,EAAE,oEAAoE,CAAC,CAAC;AAEzE,MAAM,KA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I,CAAC;YAChB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/C,CAAC;IACJ,CAAC,CAAC;IACF,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC7C,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { z } from \"zod\";\n\nexport const MAX_AUDIT_HISTORY = 10;\nexport const MAX_AUDIT_SNAPSHOT_BYTES = 60_000;\nconst MAX_HISTORY_FILE_BYTES = 660_000;\nconst HISTORY_DIRECTORY = \".mcp-validator\";\nconst HISTORY_FILE = \"audit-history.json\";\n\nconst publicUrl = z.string().max(2_048).refine((value) => {\n try {\n const url = new URL(value);\n return (url.protocol === \"https:\" || url.protocol === \"http:\")\n && Boolean(url.hostname)\n && !url.username && !url.password && !url.search && !url.hash\n && !url.port;\n } catch {\n return false;\n }\n}, \"Only query-free, credential-free public HTTP(S) URLs may be saved.\");\n\nconst count = z.number().int().nonnegative();\nconst severity = z.enum([\"error\", \"warning\", \"info\"]);\nconst category = z.enum([\"HTML\", \"SEO\", \"Schema\", \"Accessibility\"]);\nconst finding = z.object({\n code: z.string().max(120).optional(),\n severity,\n category,\n message: z.string().max(300),\n});\nconst page = z.object({\n url: publicUrl,\n fetched_url: publicUrl.optional(),\n status: z.enum([\"passed\", \"needs_attention\", \"partial\", \"failed\", \"skipped\"]),\n http_status: z.number().int().min(200).max(299).optional(),\n redirects_followed: z.number().int().min(0).max(3).optional(),\n page_fetched: z.boolean(),\n html_validation_status: z.enum([\"completed\", \"timeout\", \"unavailable\", \"not_run\"]),\n html_errors: count,\n html_warnings: count,\n seo_errors: count,\n seo_warnings: count,\n schema_errors: count,\n schema_warnings: count,\n notes: count,\n health_score: z.number().int().min(0).max(100).optional(),\n failure_code: z.string().max(120).optional(),\n top_findings: z.array(finding).max(3),\n});\nconst issueGroup = finding.extend({\n affected_pages: count,\n example_urls: z.array(publicUrl).max(3),\n});\n\n/**\n * Keep only the fields used by compare_site_audits.\n * Rich page signals, raw HTML, widget state and unrelated user-supplied fields\n * are deliberately not persisted; the hosted app remains completely stateless.\n */\nexport const compactAuditSnapshotSchema = z.object({\n site_url: publicUrl,\n sitemap_url: publicUrl.optional(),\n discovery: z.enum([\"sitemap\", \"root_only\", \"partial\"]),\n discovery_error: z.enum([\"robots_unavailable\", \"sitemap_unavailable\", \"sitemap_invalid\", \"sitemap_query_unsupported\"]).optional(),\n pages_discovered: count,\n pages_selected: count,\n pages_audited: count,\n pages_partial: count,\n pages_failed: count,\n pages_skipped_robots: count,\n truncated: z.boolean(),\n next_page_offset: count.optional(),\n discovery_fingerprint: z.string().regex(/^[0-9a-f]{64}$/),\n audit_health_score: z.number().int().min(0).max(100).optional(),\n score_coverage_percent: z.number().int().min(0).max(100),\n pages: z.array(page).max(8),\n issue_groups: z.array(issueGroup).max(50),\n issue_groups_truncated: z.boolean(),\n});\n\nexport type CompactAuditSnapshot = z.infer<typeof compactAuditSnapshotSchema>;\n\nexport interface AuditHistoryItem {\n id: string;\n saved_at: string;\n site_url: string;\n}\n\ninterface PersistedItem extends AuditHistoryItem {\n snapshot: CompactAuditSnapshot;\n}\n\nconst historySchema = z.object({\n version: z.literal(1),\n items: z.array(z.object({\n id: z.string().uuid(),\n saved_at: z.string().datetime({ offset: true }),\n site_url: publicUrl,\n snapshot: compactAuditSnapshotSchema,\n })).max(MAX_AUDIT_HISTORY),\n});\n\nexport interface AuditHistoryResponse {\n count: number;\n items: AuditHistoryItem[];\n snapshot_json?: string;\n evicted_id?: string;\n}\n\nconst basePath = (): string => {\n const configured = process.env.MCP_WEB_VALIDATOR_WORKSPACE_ROOT;\n if (configured === undefined) return os.homedir();\n if (!path.isAbsolute(configured)) {\n throw new Error(\"MCP_WEB_VALIDATOR_WORKSPACE_ROOT must be an absolute directory path.\");\n }\n return configured;\n};\n\nasync function historyFile(rootDirectory: string, create: boolean): Promise<string> {\n const root = await fs.realpath(rootDirectory);\n const dir = path.join(root, HISTORY_DIRECTORY);\n if (create) await fs.mkdir(dir, { recursive: true, mode: 0o700 });\n const entry = await fs.lstat(dir).catch((error: NodeJS.ErrnoException) => {\n if (!create && error.code === \"ENOENT\") return undefined;\n throw error;\n });\n if (!entry) return path.join(dir, HISTORY_FILE);\n if (!entry.isDirectory() || entry.isSymbolicLink()) {\n throw new Error(\"The audit history directory must be a real directory, not a symbolic link.\");\n }\n const realDir = await fs.realpath(dir);\n if (path.dirname(realDir) !== root) {\n throw new Error(\"Audit history directory must stay inside the configured root.\");\n }\n return path.join(realDir, HISTORY_FILE);\n}\n\nasync function readHistory(rootDirectory: string): Promise<PersistedItem[]> {\n const file = await historyFile(rootDirectory, false);\n const info = await fs.lstat(file).catch((error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") return undefined;\n throw error;\n });\n if (!info) return [];\n if (!info.isFile() || info.isSymbolicLink() || info.nlink !== 1 || info.size > MAX_HISTORY_FILE_BYTES) {\n throw new Error(\"History must be a bounded regular file, not a link or oversized file.\");\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(await fs.readFile(file, \"utf8\"));\n } catch {\n throw new Error(\"Audit history is unreadable or corrupt; no stored versions were modified.\");\n }\n const result = historySchema.safeParse(parsed);\n if (!result.success) throw new Error(\"Audit history is invalid; no stored versions were modified.\");\n return result.data.items;\n}\n\nasync function writeHistory(rootDirectory: string, items: PersistedItem[]): Promise<void> {\n const file = await historyFile(rootDirectory, true);\n const contents = JSON.stringify({ version: 1, items });\n if (Buffer.byteLength(contents, \"utf8\") > MAX_HISTORY_FILE_BYTES) {\n throw new Error(\"The audit history file would exceed the configured size cap.\");\n }\n const tmp = path.join(path.dirname(file), `.${HISTORY_FILE}.${randomUUID()}.tmp`);\n let handle: fs.FileHandle | undefined;\n try {\n handle = await fs.open(tmp, \"wx\", 0o600);\n await handle.writeFile(contents, \"utf8\");\n await handle.sync();\n await handle.close();\n handle = undefined;\n await fs.rename(tmp, file);\n } finally {\n if (handle) await handle.close();\n await fs.rm(tmp, { force: true });\n }\n}\n\nfunction summary(items: PersistedItem[]): AuditHistoryResponse {\n return {\n count: items.length,\n items: items.slice().reverse().map(({ id, saved_at, site_url }) => ({ id, saved_at, site_url })),\n };\n}\n\n// The stdio MCP server normally has one process. Serialize saves in-process\n// so simultaneous client calls cannot overwrite one another's latest version.\nlet pendingSave: Promise<unknown> = Promise.resolve();\n\nexport function parseCompactAuditSnapshot(snapshotJson: string): CompactAuditSnapshot {\n if (Buffer.byteLength(snapshotJson, \"utf8\") > MAX_AUDIT_SNAPSHOT_BYTES) {\n throw new Error(\"Audit snapshot exceeds the 60 KB input limit.\");\n }\n let candidate: unknown;\n try {\n candidate = JSON.parse(snapshotJson);\n } catch {\n throw new Error(\"Audit snapshot must be valid JSON.\");\n }\n const parsed = compactAuditSnapshotSchema.safeParse(candidate);\n if (!parsed.success) {\n throw new Error(\"Audit snapshot must be a valid bounded audit_public_site structured result without secret-bearing URLs.\");\n }\n const compact = JSON.stringify(parsed.data);\n if (Buffer.byteLength(compact, \"utf8\") > MAX_AUDIT_SNAPSHOT_BYTES) {\n throw new Error(\"Compact audit snapshot exceeds the 60 KB storage limit.\");\n }\n return parsed.data;\n}\n\nexport async function listAuditHistory(rootDirectory = basePath()): Promise<AuditHistoryResponse> {\n return summary(await readHistory(rootDirectory));\n}\n\nexport async function getAuditHistorySnapshot(\n id: string,\n rootDirectory = basePath(),\n): Promise<AuditHistoryResponse> {\n const items = await readHistory(rootDirectory);\n const found = items.find((item) => item.id === id);\n if (!found) throw new Error(\"The requested audit history version was not found.\");\n return { ...summary(items), snapshot_json: JSON.stringify(found.snapshot) };\n}\n\n/**\n * P2-01: read selected immutable saved versions in *stored* chronological\n * order. A single guarded history read; no writes, ID discovery or archive\n * mutation. Reject evicted versions rather than silently substituting them.\n */\nexport async function getAuditHistoryVersions(\n ids: string[],\n rootDirectory = basePath(),\n): Promise<Array<{ saved_at: string; snapshot: CompactAuditSnapshot }>> {\n if (!Array.isArray(ids) || ids.length < 2 || ids.length > MAX_AUDIT_HISTORY\n || new Set(ids).size !== ids.length\n || ids.some((id) => !z.string().uuid().safeParse(id).success)) {\n throw new Error(\"Supply two to ten distinct saved audit version IDs, oldest first.\");\n }\n const history = await readHistory(rootDirectory);\n const byId = new Map(history.map((item, index) => [item.id, { item, index }]));\n let previousIndex = -1;\n const result: Array<{ saved_at: string; snapshot: CompactAuditSnapshot }> = [];\n for (const id of ids) {\n const entry = byId.get(id);\n if (!entry) throw new Error(\"A requested saved audit history version was not found or was evicted.\");\n if (entry.index <= previousIndex) {\n throw new Error(\"Saved audit version IDs must be ordered oldest to newest.\");\n }\n previousIndex = entry.index;\n result.push({ saved_at: entry.item.saved_at, snapshot: entry.item.snapshot });\n }\n return result;\n}\n\nexport function saveAuditHistorySnapshot(\n snapshotJson: string,\n rootDirectory = basePath(),\n): Promise<AuditHistoryResponse> {\n const snapshot = parseCompactAuditSnapshot(snapshotJson);\n const action = async (): Promise<AuditHistoryResponse> => {\n const items = await readHistory(rootDirectory);\n const newItem: PersistedItem = {\n id: randomUUID(),\n saved_at: new Date().toISOString(),\n site_url: snapshot.site_url,\n snapshot,\n };\n const next = [...items, newItem];\n const evicted = next.length > MAX_AUDIT_HISTORY ? next.shift() : undefined;\n await writeHistory(rootDirectory, next);\n return {\n ...summary(next),\n ...(evicted ? { evicted_id: evicted.id } : {}),\n };\n };\n const request = pendingSave.then(action, action);\n pendingSave = request.catch(() => undefined);\n return request;\n}\n"]}
1
+ {"version":3,"file":"audit-history.js","sourceRoot":"","sources":["../src/audit-history.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,+BAA+B;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,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC7C,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["// Copyright (c) 2026 AKzar1el and Web Validator contributors\n// SPDX-License-Identifier: MIT\nimport * as fs from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { z } from \"zod\";\n\nexport const MAX_AUDIT_HISTORY = 10;\nexport const MAX_AUDIT_SNAPSHOT_BYTES = 60_000;\nconst MAX_HISTORY_FILE_BYTES = 660_000;\nconst HISTORY_DIRECTORY = \".mcp-validator\";\nconst HISTORY_FILE = \"audit-history.json\";\n\nconst publicUrl = z.string().max(2_048).refine((value) => {\n try {\n const url = new URL(value);\n return (url.protocol === \"https:\" || url.protocol === \"http:\")\n && Boolean(url.hostname)\n && !url.username && !url.password && !url.search && !url.hash\n && !url.port;\n } catch {\n return false;\n }\n}, \"Only query-free, credential-free public HTTP(S) URLs may be saved.\");\n\nconst count = z.number().int().nonnegative();\nconst severity = z.enum([\"error\", \"warning\", \"info\"]);\nconst category = z.enum([\"HTML\", \"SEO\", \"Schema\", \"Accessibility\"]);\nconst finding = z.object({\n code: z.string().max(120).optional(),\n severity,\n category,\n message: z.string().max(300),\n});\nconst page = z.object({\n url: publicUrl,\n fetched_url: publicUrl.optional(),\n status: z.enum([\"passed\", \"needs_attention\", \"partial\", \"failed\", \"skipped\"]),\n http_status: z.number().int().min(200).max(299).optional(),\n redirects_followed: z.number().int().min(0).max(3).optional(),\n page_fetched: z.boolean(),\n html_validation_status: z.enum([\"completed\", \"timeout\", \"unavailable\", \"not_run\"]),\n html_errors: count,\n html_warnings: count,\n seo_errors: count,\n seo_warnings: count,\n schema_errors: count,\n schema_warnings: count,\n notes: count,\n health_score: z.number().int().min(0).max(100).optional(),\n failure_code: z.string().max(120).optional(),\n top_findings: z.array(finding).max(3),\n});\nconst issueGroup = finding.extend({\n affected_pages: count,\n example_urls: z.array(publicUrl).max(3),\n});\n\n/**\n * Keep only the fields used by compare_site_audits.\n * Rich page signals, raw HTML, widget state and unrelated user-supplied fields\n * are deliberately not persisted; the hosted app remains completely stateless.\n */\nexport const compactAuditSnapshotSchema = z.object({\n site_url: publicUrl,\n sitemap_url: publicUrl.optional(),\n discovery: z.enum([\"sitemap\", \"root_only\", \"partial\"]),\n discovery_error: z.enum([\"robots_unavailable\", \"sitemap_unavailable\", \"sitemap_invalid\", \"sitemap_query_unsupported\"]).optional(),\n pages_discovered: count,\n pages_selected: count,\n pages_audited: count,\n pages_partial: count,\n pages_failed: count,\n pages_skipped_robots: count,\n truncated: z.boolean(),\n next_page_offset: count.optional(),\n discovery_fingerprint: z.string().regex(/^[0-9a-f]{64}$/),\n audit_health_score: z.number().int().min(0).max(100).optional(),\n score_coverage_percent: z.number().int().min(0).max(100),\n pages: z.array(page).max(8),\n issue_groups: z.array(issueGroup).max(50),\n issue_groups_truncated: z.boolean(),\n});\n\nexport type CompactAuditSnapshot = z.infer<typeof compactAuditSnapshotSchema>;\n\nexport interface AuditHistoryItem {\n id: string;\n saved_at: string;\n site_url: string;\n}\n\ninterface PersistedItem extends AuditHistoryItem {\n snapshot: CompactAuditSnapshot;\n}\n\nconst historySchema = z.object({\n version: z.literal(1),\n items: z.array(z.object({\n id: z.string().uuid(),\n saved_at: z.string().datetime({ offset: true }),\n site_url: publicUrl,\n snapshot: compactAuditSnapshotSchema,\n })).max(MAX_AUDIT_HISTORY),\n});\n\nexport interface AuditHistoryResponse {\n count: number;\n items: AuditHistoryItem[];\n snapshot_json?: string;\n evicted_id?: string;\n}\n\nconst basePath = (): string => {\n const configured = process.env.MCP_WEB_VALIDATOR_WORKSPACE_ROOT;\n if (configured === undefined) return os.homedir();\n if (!path.isAbsolute(configured)) {\n throw new Error(\"MCP_WEB_VALIDATOR_WORKSPACE_ROOT must be an absolute directory path.\");\n }\n return configured;\n};\n\nasync function historyFile(rootDirectory: string, create: boolean): Promise<string> {\n const root = await fs.realpath(rootDirectory);\n const dir = path.join(root, HISTORY_DIRECTORY);\n if (create) await fs.mkdir(dir, { recursive: true, mode: 0o700 });\n const entry = await fs.lstat(dir).catch((error: NodeJS.ErrnoException) => {\n if (!create && error.code === \"ENOENT\") return undefined;\n throw error;\n });\n if (!entry) return path.join(dir, HISTORY_FILE);\n if (!entry.isDirectory() || entry.isSymbolicLink()) {\n throw new Error(\"The audit history directory must be a real directory, not a symbolic link.\");\n }\n const realDir = await fs.realpath(dir);\n if (path.dirname(realDir) !== root) {\n throw new Error(\"Audit history directory must stay inside the configured root.\");\n }\n return path.join(realDir, HISTORY_FILE);\n}\n\nasync function readHistory(rootDirectory: string): Promise<PersistedItem[]> {\n const file = await historyFile(rootDirectory, false);\n const info = await fs.lstat(file).catch((error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") return undefined;\n throw error;\n });\n if (!info) return [];\n if (!info.isFile() || info.isSymbolicLink() || info.nlink !== 1 || info.size > MAX_HISTORY_FILE_BYTES) {\n throw new Error(\"History must be a bounded regular file, not a link or oversized file.\");\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(await fs.readFile(file, \"utf8\"));\n } catch {\n throw new Error(\"Audit history is unreadable or corrupt; no stored versions were modified.\");\n }\n const result = historySchema.safeParse(parsed);\n if (!result.success) throw new Error(\"Audit history is invalid; no stored versions were modified.\");\n return result.data.items;\n}\n\nasync function writeHistory(rootDirectory: string, items: PersistedItem[]): Promise<void> {\n const file = await historyFile(rootDirectory, true);\n const contents = JSON.stringify({ version: 1, items });\n if (Buffer.byteLength(contents, \"utf8\") > MAX_HISTORY_FILE_BYTES) {\n throw new Error(\"The audit history file would exceed the configured size cap.\");\n }\n const tmp = path.join(path.dirname(file), `.${HISTORY_FILE}.${randomUUID()}.tmp`);\n let handle: fs.FileHandle | undefined;\n try {\n handle = await fs.open(tmp, \"wx\", 0o600);\n await handle.writeFile(contents, \"utf8\");\n await handle.sync();\n await handle.close();\n handle = undefined;\n await fs.rename(tmp, file);\n } finally {\n if (handle) await handle.close();\n await fs.rm(tmp, { force: true });\n }\n}\n\nfunction summary(items: PersistedItem[]): AuditHistoryResponse {\n return {\n count: items.length,\n items: items.slice().reverse().map(({ id, saved_at, site_url }) => ({ id, saved_at, site_url })),\n };\n}\n\n// The stdio MCP server normally has one process. Serialize saves in-process\n// so simultaneous client calls cannot overwrite one another's latest version.\nlet pendingSave: Promise<unknown> = Promise.resolve();\n\nexport function parseCompactAuditSnapshot(snapshotJson: string): CompactAuditSnapshot {\n if (Buffer.byteLength(snapshotJson, \"utf8\") > MAX_AUDIT_SNAPSHOT_BYTES) {\n throw new Error(\"Audit snapshot exceeds the 60 KB input limit.\");\n }\n let candidate: unknown;\n try {\n candidate = JSON.parse(snapshotJson);\n } catch {\n throw new Error(\"Audit snapshot must be valid JSON.\");\n }\n const parsed = compactAuditSnapshotSchema.safeParse(candidate);\n if (!parsed.success) {\n throw new Error(\"Audit snapshot must be a valid bounded audit_public_site structured result without secret-bearing URLs.\");\n }\n const compact = JSON.stringify(parsed.data);\n if (Buffer.byteLength(compact, \"utf8\") > MAX_AUDIT_SNAPSHOT_BYTES) {\n throw new Error(\"Compact audit snapshot exceeds the 60 KB storage limit.\");\n }\n return parsed.data;\n}\n\nexport async function listAuditHistory(rootDirectory = basePath()): Promise<AuditHistoryResponse> {\n return summary(await readHistory(rootDirectory));\n}\n\nexport async function getAuditHistorySnapshot(\n id: string,\n rootDirectory = basePath(),\n): Promise<AuditHistoryResponse> {\n const items = await readHistory(rootDirectory);\n const found = items.find((item) => item.id === id);\n if (!found) throw new Error(\"The requested audit history version was not found.\");\n return { ...summary(items), snapshot_json: JSON.stringify(found.snapshot) };\n}\n\n/**\n * P2-01: read selected immutable saved versions in *stored* chronological\n * order. A single guarded history read; no writes, ID discovery or archive\n * mutation. Reject evicted versions rather than silently substituting them.\n */\nexport async function getAuditHistoryVersions(\n ids: string[],\n rootDirectory = basePath(),\n): Promise<Array<{ saved_at: string; snapshot: CompactAuditSnapshot }>> {\n if (!Array.isArray(ids) || ids.length < 2 || ids.length > MAX_AUDIT_HISTORY\n || new Set(ids).size !== ids.length\n || ids.some((id) => !z.string().uuid().safeParse(id).success)) {\n throw new Error(\"Supply two to ten distinct saved audit version IDs, oldest first.\");\n }\n const history = await readHistory(rootDirectory);\n const byId = new Map(history.map((item, index) => [item.id, { item, index }]));\n let previousIndex = -1;\n const result: Array<{ saved_at: string; snapshot: CompactAuditSnapshot }> = [];\n for (const id of ids) {\n const entry = byId.get(id);\n if (!entry) throw new Error(\"A requested saved audit history version was not found or was evicted.\");\n if (entry.index <= previousIndex) {\n throw new Error(\"Saved audit version IDs must be ordered oldest to newest.\");\n }\n previousIndex = entry.index;\n result.push({ saved_at: entry.item.saved_at, snapshot: entry.item.snapshot });\n }\n return result;\n}\n\nexport function saveAuditHistorySnapshot(\n snapshotJson: string,\n rootDirectory = basePath(),\n): Promise<AuditHistoryResponse> {\n const snapshot = parseCompactAuditSnapshot(snapshotJson);\n const action = async (): Promise<AuditHistoryResponse> => {\n const items = await readHistory(rootDirectory);\n const newItem: PersistedItem = {\n id: randomUUID(),\n saved_at: new Date().toISOString(),\n site_url: snapshot.site_url,\n snapshot,\n };\n const next = [...items, newItem];\n const evicted = next.length > MAX_AUDIT_HISTORY ? next.shift() : undefined;\n await writeHistory(rootDirectory, next);\n return {\n ...summary(next),\n ...(evicted ? { evicted_id: evicted.id } : {}),\n };\n };\n const request = pendingSave.then(action, action);\n pendingSave = request.catch(() => undefined);\n return request;\n}\n"]}
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env node
2
+ // Copyright (c) 2026 AKzar1el and Web Validator contributors
3
+ // SPDX-License-Identifier: MIT
2
4
  import * as path from "node:path";
3
5
  import { pathToFileURL } from "node:url";
4
6
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -2583,10 +2585,14 @@ export function createServer() {
2583
2585
  page_url: page_url, raw_html: raw_html, rendered_html: rendered_html,
2584
2586
  })
2585
2587
  : await renderInlineHtml(raw_html, page_url);
2588
+ const sampled = review.raw.sample_truncated || review.rendered.sample_truncated;
2586
2589
  return result(review, "V07 source/render comparison: "
2587
2590
  + review.raw.main_words + " source and " + review.rendered.main_words
2588
- + " rendered main-text words; " + review.link_targets_removed + " source links removed, "
2589
- + review.link_targets_added + " rendered links added, "
2591
+ + (sampled ? " rendered main-text words (bounded sample); " : " rendered main-text words; ")
2592
+ + review.link_targets_removed
2593
+ + (sampled ? " source link targets absent from rendered sample, " : " source links removed, ")
2594
+ + review.link_targets_added
2595
+ + (sampled ? " rendered link targets absent from source sample, " : " rendered links added, ")
2590
2596
  + (review.title_changed ? "title changed; " : "title unchanged; ")
2591
2597
  + (review.canonical_changed ? "canonical declarations changed; " : "")
2592
2598
  + (review.noindex_changed ? "noindex declarations changed; " : "")