Skip to content

PDX-466: feat(mcp): add AJV JSON schema validation to provar_nitrox_validate#159

Merged
mrdailey99 merged 3 commits into
developfrom
feature/PDX-466-nitrox-ajv-schema-validation
May 12, 2026
Merged

PDX-466: feat(mcp): add AJV JSON schema validation to provar_nitrox_validate#159
mrdailey99 merged 3 commits into
developfrom
feature/PDX-466-nitrox-ajv-schema-validation

Conversation

@mrdailey99
Copy link
Copy Markdown
Collaborator

@mrdailey99 mrdailey99 commented May 11, 2026

Summary

  • Added ajv (v8, Draft 2020-12) as a runtime dependency
  • provar_nitrox_validate now runs two validation passes in parallel: existing hardcoded NX001–NX010 rules and structural JSON schema validation against the bundled FactComponent.schema.json
  • Schema violations are returned as NX_SCHEMA_<KEYWORD> issues (ERROR for type/required, WARNING for additionalProperties/pattern/enum)
  • Falls back gracefully to hardcoded-rules-only if the schema file cannot be loaded (e.g. not yet fetched by the PDX-464 prepack script)
  • Version bumped to 1.5.0-beta.19

Jira

https://provartesting.atlassian.net/browse/PDX-466

Test plan

  • yarn compile passes
  • yarn test:only passes (954 tests, 4 new NX_SCHEMA tests)
  • node scripts/mcp-smoke.cjs passes (54/54)
  • yarn lint passes

Changes

  • src/mcp/tools/nitroXTools.ts: added Ajv2020 import, lazy schema validator, ajvErrorToIssue(), updated validateNitroXContent() to accept optional override and run AJV pass; updated tool description
  • test/unit/mcp/nitroXTools.test.ts: added NX_SCHEMA_ rules (AJV schema override) test suite (4 tests)
  • docs/mcp.md: documented NX_SCHEMA_* rule IDs and updated provar_nitrox_validate section
  • package.json / server.json: added ajv dependency, bumped to 1.5.0-beta.19

…d NX rules

RCA: provar_nitrox_validate only ran hardcoded NX001–NX010 semantic rules; structural errors (wrong types, extra properties, enum violations) encoded in FactComponent.schema.json were never caught at validation time.
Fix: Added Ajv2020 as a runtime dependency; schema is lazily loaded from lib/mcp/rules/FactComponent.schema.json on first call and validated in parallel with existing rules. Violations are returned as NX_SCHEMA_<KEYWORD> issues (ERROR for type/required, WARNING for additionalProperties/pattern/enum). Falls back to hardcoded-rules-only when schema is unavailable.
…on import in NX_SCHEMA tests

RCA: ESLint no-explicit-any rule rejected the any parameter type used for the schemaOverride parameter in AJV schema override tests; the eslint-disable comment was positioned on the wrong line.
Fix: Added import type { ValidateFunction } from ajv/dist/2020.js and replaced all any usages with properly typed ValidateFunction and a narrow IssueShape type alias for the return value.
Copilot AI review requested due to automatic review settings May 11, 2026 21:39
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

Quality Orchestrator

🟢 LOW · 2 / 100 · All changed files have mapped tests.


🧪 Tests to Run · Running 1 of 43 tests

  • unit/mcp/nitroXTools.test.ts
▶ Run command
npx vitest run \
  unit/mcp/nitroXTools.test.ts

⚡ quality-orchestrator  ·  /qo stub <file>  ·  qo analyze-local

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds AJV-based JSON Schema validation to the provar_nitrox_validate MCP tool so NitroX .po.json files are checked both for existing semantic NX rules and for structural schema conformance, with schema issues surfaced as NX_SCHEMA_* rule IDs and reflected in scoring.

Changes:

  • Introduces a lazy, cached AJV 2020-12 schema validator (with graceful fallback when the schema file isn’t available).
  • Extends validateNitroXContent() to optionally run a schema-validation pass and translate AJV errors into NX_SCHEMA_* issues.
  • Adds unit tests for NX_SCHEMA_* behaviors and updates MCP docs + package version/dependency metadata.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/mcp/tools/nitroXTools.ts Adds AJV schema loading/caching, error-to-issue mapping, and integrates schema validation into NitroX content validation + tool description updates.
test/unit/mcp/nitroXTools.test.ts Adds tests covering NX_SCHEMA_* issue generation and severity behavior using schema overrides.
docs/mcp.md Documents NX_SCHEMA_* rule IDs and updates provar_nitrox_validate docs to describe the added schema pass.
package.json Adds ajv runtime dependency and bumps version to 1.5.0-beta.19.
server.json Bumps server/package version to 1.5.0-beta.19.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mcp/tools/nitroXTools.ts Outdated
'Validate a NitroX .po.json (Hybrid Model component page object) against schema rules.',
'Works for any NitroX-mapped component type: LWC, Screen Flow, Industry Components, Experience Cloud, HTML5.',
'Returns a quality score (0–100) and a list of issues with rule IDs (NX001–NX010), severity, and suggestions.',
'Runs two passes in parallel: hardcoded semantic rules (NX001–NX010) and JSON schema validation (NX_SCHEMA_* rule IDs).',
Comment thread src/mcp/tools/nitroXTools.ts Outdated
Comment on lines +71 to +73
const severity: 'ERROR' | 'WARNING' = ['REQUIRED', 'TYPE', 'MIN_ITEMS', 'MINIMUM', 'MAXIMUM'].includes(keyword)
? 'ERROR'
: 'WARNING';
Comment thread docs/mcp.md Outdated
Comment on lines +1646 to +1649
Validate a NitroX `.po.json` (Hybrid Model component page object) against the FACT schema rules. Returns a quality score (0–100) and a combined list of issues from two validation passes that run in parallel:

1. **Hardcoded semantic rules (NX001–NX010)** — always run
2. **JSON schema validation (NX*SCHEMA*\*)** — runs when the bundled `FactComponent.schema.json` is available; falls back to hardcoded-rules-only if the schema cannot be loaded
Comment thread docs/mcp.md Outdated
| NX009 | INFO | Interaction `name` contains characters outside `[A-Za-z0-9 ]` |
| NX010 | INFO | `bodyTagName` contains whitespace |

**JSON schema rules (NX*SCHEMA*\*):**
…ma-validation

RCA: Copilot flagged incorrect 'in parallel' wording (validation is synchronous/sequential), an overly broad ERROR severity mapping in ajvErrorToIssue (MIN_ITEMS/MINIMUM/MAXIMUM should be WARNING), and broken markdown rendering of NX_SCHEMA_* in docs (underscores parsed as italic markers).
Fix: Reworded tool description and docs to 'sequential' passes; narrowed ERROR set to REQUIRED and TYPE only; fixed NX_SCHEMA_* heading and inline text with backtick quoting; updated docs table to show MIN_ITEMS as WARNING.
@mrdailey99
Copy link
Copy Markdown
Collaborator Author

All four review comments addressed in commit 8b60e3d:

  1. 'in parallel' wording — reworded to 'two validation passes sequentially' in both the tool description and docs
  2. Severity mapping — narrowed ERROR set to ['REQUIRED', 'TYPE'] only; MIN_ITEMS, MINIMUM, MAXIMUM now fall through to WARNING
  3. docs.md 'in parallel' — updated to 'two sequential validation passes'
  4. NX_SCHEMA_ markdown rendering* — changed bare NX_SCHEMA_* in heading and inline list item to backtick-quoted form to prevent underscore italic parsing; also updated the docs table to show NX_SCHEMA_MIN_ITEMS as WARNING

@mrdailey99 mrdailey99 merged commit 8d483bb into develop May 12, 2026
4 checks passed
mrdailey99 added a commit that referenced this pull request May 12, 2026
* PDX-0: feat(mcp): add user-facing guide prompts, tool-guide resource, and git-workflow command

RCA: Users and AI agents lacked structured onboarding, troubleshooting, and tool selection guidance when connecting a Provar project via ProvarDX MCP, causing long friction loops and repeated tool selection mistakes that baked-in agent workflows would prevent.
Fix: Added three MCP prompts (provar.guide.onboarding, troubleshoot, orchestration), one resource (provar://docs/tool-guide), and a tracked /git-workflow slash command covering Jira ticket creation, branch naming, worktree setup with yarn install, and the full dev/PR lifecycle. Smoke test updated to 54 entries. Gitignore tightened to track .claude/commands/.

* PDX-0: chore(ci): update QualityOrchestrator to floating v1 tag

RCA: CI workflow pinned QualityOrchestrator at v1.0.0, requiring manual edits to pick up every subsequent patch or minor release, causing the action to drift behind the latest available version.
Fix: Created floating v1 tag on mrdailey99/QualityOrchestrator (currently at v1.0.2) and updated CI_Execution.yml to reference @v1, so the workflow automatically uses the latest v1.x release without any further changes needed.

* PDX-0: fix(mcp): address Copilot review comments on PR #153

RCA: Copilot flagged 14 issues — wrong tool schemas in guide prompts and docs, missing build copy step, hardcoded cloudId in a public repo file, broken gitignored file reference.

Fix: Add PROVAR_TOOL_GUIDE.md to package.json build copy; fix all wrong tool params in guide docs and prompts (properties_generate output_path, --plan-name, testrun_rca project_path, testcase_step_edit test_case_path, testplan add-instance hyphen, defect run_id); remove hardcoded cloudId; remove broken agents ref.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Bump package json version to 1.5.0-beta.18

* Bump version to 1.5.0-beta.18 in server.json

* PDX-463: feat(mcp): fetch NitroX component packages from factPackages repo at release time

RCA: NitroX component packages were statically bundled in the repo and not updated automatically; the source of truth is the ProvarTesting/factPackages GitHub repo (main branch), so packages would silently drift stale between releases.
Fix: Added scripts/fetch-nitrox-packages.cjs to the prepack hook; it downloads all component package files from factPackages@main, regenerates NITROX_COMPONENT_CATALOG.md, and writes NITROX_CATALOG_SOURCE.json with the commit SHA. On failure (no token, network error) it logs a warning and falls back to the committed catalog — the release is never blocked. A new provar://nitrox/catalog-source MCP resource exposes the bundled version so consumers can verify which factPackages commit is in use.

* PDX-463: fix(mcp): correct factPackages path layout and fix lint warnings

RCA: The factPackages repo stores component files under fact-*/src/components/ not fact-*/components/, so the path-matching regexes and catalog builder needed updating; additionally nine pre-existing unicorn/numeric-separators-style lint warnings in updateChecker.ts and its test file were left unaddressed.
Fix: Updated PKG_JSON_RE and COMPONENT_FILE_RE in fetch-nitrox-packages.cjs to match the fact-*/src/ layout and adjusted buildCatalogFromDir to navigate the src/ subdirectory; ran eslint --fix on updateChecker.ts and updateChecker.test.ts to resolve all numeric-separator warnings, leaving the project at 0 lint errors and 0 warnings.

* PDX-463: fix(mcp): address PR review comments on fetch-nitrox-packages

RCA: downloadRaw() used the branch name (main) in the raw URL rather than the resolved commit SHA, so files could be fetched from a different commit than the one the tree listing described; additionally both httpsGet and httpsGetBuffer had no timeout, meaning a stalled network connection would block prepack indefinitely.
Fix: Added REQUEST_TIMEOUT_MS (15s) to both http helpers via req.setTimeout/req.destroy so hangs fail fast and fall through to the graceful fallback; updated downloadRaw to accept and use the commitSha parameter so all downloads are pinned to the same commit as the tree.

* PDX-465: feat(mcp): add bin entry to enable zero-install npx MCP server startup (#158)

RCA: No bin entry in package.json forced users through a two-step sf CLI plugin install before connecting Claude Desktop, creating unnecessary onboarding friction.
Fix: Added provardx bin entry pointing to bin/mcp-start.js; lightweight ESM entrypoint parses mcp start flags, validates --allowed-paths as required, then delegates to the same server bootstrap used by the sf plugin path.

* PDX-464: fetch NitroX schemas from internal source at build time (#157)

* PDX-464: feat(mcp): fetch NitroX schemas from internal source at build time

RCA: FactComponent.schema and FactPackage.schema were bundled statically and never refreshed from the canonical internal source, risking stale schema validation in released packages.
Fix: Extended fetch-nitrox-packages.cjs to download both schemas from the same commit SHA as the component catalog, write to src/mcp/rules/ and root-level copies, and record schemasUpdated in NITROX_CATALOG_SOURCE.json. Falls back to bundled schemas with a warning on any failure.

* PDX-464: fix(mcp): address Copilot review — schema consumers, repo field, schemasUpdated normalisation

RCA: Four review issues: docs incorrectly named runtime tools as schema consumers; repo field exposed internal URL in MCP resource; readCatalogSource did not normalise missing schemasUpdated from older build artifacts; fallback object also contained the internal URL.
Fix: Corrected docs to describe IDE/SchemaStore as schema consumers; removed repo field from emitted JSON and fallback; normalised schemasUpdated to null in readCatalogSource try-path when field is absent; updated tests to cover the new normalisation and assert no repo field in fallback.

* PDX-466: feat(mcp): add AJV JSON schema validation to provar_nitrox_validate (#159)

* PDX-466: feat(mcp): add AJV JSON schema validation alongside hardcoded NX rules

RCA: provar_nitrox_validate only ran hardcoded NX001–NX010 semantic rules; structural errors (wrong types, extra properties, enum violations) encoded in FactComponent.schema.json were never caught at validation time.
Fix: Added Ajv2020 as a runtime dependency; schema is lazily loaded from lib/mcp/rules/FactComponent.schema.json on first call and validated in parallel with existing rules. Violations are returned as NX_SCHEMA_<KEYWORD> issues (ERROR for type/required, WARNING for additionalProperties/pattern/enum). Falls back to hardcoded-rules-only when schema is unavailable.

* PDX-466: fix(test): replace no-explicit-any with typed ValidateFunction import in NX_SCHEMA tests

RCA: ESLint no-explicit-any rule rejected the any parameter type used for the schemaOverride parameter in AJV schema override tests; the eslint-disable comment was positioned on the wrong line.
Fix: Added import type { ValidateFunction } from ajv/dist/2020.js and replaced all any usages with properly typed ValidateFunction and a narrow IssueShape type alias for the return value.

* PDX-466: fix(mcp): address Copilot review comments on nitrox-ajv-schema-validation

RCA: Copilot flagged incorrect 'in parallel' wording (validation is synchronous/sequential), an overly broad ERROR severity mapping in ajvErrorToIssue (MIN_ITEMS/MINIMUM/MAXIMUM should be WARNING), and broken markdown rendering of NX_SCHEMA_* in docs (underscores parsed as italic markers).
Fix: Reworded tool description and docs to 'sequential' passes; narrowed ERROR set to REQUIRED and TYPE only; fixed NX_SCHEMA_* heading and inline text with backtick quoting; updated docs table to show MIN_ITEMS as WARNING.

* PDX-467: chore(docs): bump version to 1.5.0 stable and remove @beta install tag (#160)

* PDX-467: chore(docs): bump version to 1.5.0 stable and remove @beta install tag

RCA: The 1.5.0 release is ready for stable promotion; all docs and install commands still referenced the @beta dist-tag and pre-release version string.
Fix: Updated package.json and server.json to 1.5.0, removed @beta from all install commands in README.md, docs/mcp.md, and docs/mcp-pilot-guide.md, and updated the stale-cache unit test to use the latest channel.

* PDX-467: test(mcp): make stale-cache test release-agnostic by deriving channel at runtime

RCA: Hardcoded version and channel values in the stale-cache test will fail once the branch version cycles back to a prerelease (beta/rc) after the 1.5.0 stable release.
Fix: Derive currentVersion and channel from the running version at test time, mirroring the pattern used in the fresh-cache test, so the test remains valid across any semver channel.
@mrdailey99 mrdailey99 deleted the feature/PDX-466-nitrox-ajv-schema-validation branch May 12, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants