Skip to content

fix(templates): invalid MCP declarations report only "Invalid input" - #198598

Merged
obviyus merged 4 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-198554-template-mcp-diagnostics
Nov 15, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-198554-template-mcp-diagnostics

Conversation

@LiuwqGit

@LiuwqGit LiuwqGit commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted: yes

Fixes #198554. Original fix by @LiuwqGit; reported by @anmol0b.

What Problem This Solves

openclaw templates validate loses Zod's nested field diagnostics when a Template MCP entry matches neither the stdio nor remote shape. Authors only see $.mcpServers.<name>: Invalid input.

Fix

Forward the existing issues from the uniquely closest union branch, including their full field paths. Keep the existing union diagnostic on a tie. No schema, accepted values, defaults, or message text changes. Other Template artifact diagnostic forwarding (#198556) stays out of scope.

The simplification removes both added helpers and intermediate located-issue objects. Against the merge base: production +23/-7 (net +16); tests +25/-32 (net -7), consolidating the existing MCP cases while retaining the reported regressions and adding an equally-close control.

Risk

Two-way door: reverting restores the old diagnostics. No persisted state or published API changes. Blast radius is malformed Template MCP validation diagnostics; valid declarations retain their existing behavior.

Evidence

Observed before/after receipts: four contributor regressions red on main merge-base and green on the contributor head; final focused suites 61/61. Source CLI cases and valid controls ran twice on each side. Final full declaration build and packed CLI smoke passed. All ran through ocx on macOS arm64 with isolated CLI HOME/state/profile paths.

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR exposes existing field-level validation errors for malformed Template MCP declarations while preserving ambiguous-union diagnostics.

Example: Validate a Template containing mcpServers.sample = { command: "node", args: [8080] }.

  • Before: $.mcpServers.sample: Invalid input
  • After: $.mcpServers.sample.args[0]: Invalid input: expected string, received number

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused implementation, useful regression coverage, and shipped CLI evidence support merging once current-head CI completes.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied macOS arm64 CLI receipts exercise real Template projects through templates validate, show corrected nested paths and unchanged failure statuses, preserve ambiguous and valid controls, and repeat the affected scenarios at the reviewed merged head; packed-entry proof covers the preceding head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Template authors cannot identify the malformed field when MCP validation reports only Invalid input.
Reason: The change restores actionable diagnostics for the reported cases without introducing options, changing accepted inputs, or adding another owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete authoring problem with a focused, proven change; no actionable defects were found, and current-head CI remains pending.

Priority: P2
Reviewed head: 02baa3b6df5d07f3c063945de3d075524af52344

Before merge

None.

Findings

None.

Agent review details

How this fits together

Template validation reads CLAW.md, parses its manifest with Zod, and returns structured diagnostics to CLI and other Template consumers.

flowchart LR
A[Template project] --> B[CLI validate command]
B --> C[Project validator]
C --> D[Manifest reader]
D --> E[Manifest schema]
E --> F[Structured diagnostics]
F --> G[Text or JSON output]
Loading

Technical review

Best possible solution:

Merge the focused diagnostic change once the existing required checks pass.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the diagnostic-loss path, and the supplied before/after CLI receipts reproduce the reported inputs; this review executed no target code.

Is this the best way to solve the issue?

The existing diagnostic converter is the smallest appropriate owner: forward the uniquely closest branch's existing issues, preserve ties, and retain the current validation contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 387042f830d0.

Provenance checked

  • Template schema diagnostic conversion keeps the original intent (138d2a5: The original grouped Claw schema provided strict portable validation and stable diagnostics; the rename preserved this converter, with no recorded requirement to suppress nested union reasons.)
  • MCP validation tests keeps the original intent (Add grouped Claw schema and read-only add plan #101328: The schema tests protect portable MCP declarations and rejection of unsafe configurations; later refactors retained these contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +16, Tests -7. Total +9 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 23 7 +16
Tests 1 25 32 -7
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 48 39 +9

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on maintainer: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Malformed Template MCP declarations produce unhelpful authoring diagnostics, with limited impact and no change to valid declarations.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-14T03:06:23.260Z sha b553141 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-14T04:14:04.052Z sha b553141 :: blocked before merge. :: none
  • reviewed 2026-11-15T01:43:29.178Z sha f04c05b :: needs maintainer review before merge. :: none

Reviewed November 14, 2026, 9:00 PM ET / November 15, 2026, 02:00 UTC (Revision 4).

@LiuwqGit

Copy link
Copy Markdown
Contributor Author

Real behavior proof added for the two outstanding test items — the shipped CLI entry point with real argv, and a red/green run of the committed regressions. The ## Evidence section of the PR body is updated with the same numbers; no code changed (head is still b5531419e17).

1. Shipped CLI entry point, real argv (was: handler called directly)

The previous evidence imported runTemplatesValidateCommand and skipped argv. Every case below is now a separate OS process running the shipped entry module with real arguments:

node --import ./scripts/tsx.mjs src/entry.ts templates validate /tmp/mcp-cli-198554/<case> [--json]

src/entry.ts is the module tsdown bundles into dist/entry.js, which the openclaw bin (openclaw.mjs) imports, so argv parsing → commander routing (src/cli/templates-cli.ts:52-55) → action handler → project discovery → manifest validation → formatTemplateDiagnostics → text/JSON output → exit status are all shipped code. Fixtures are real Template projects on disk (package.json + CLAW.md), and the CLI ran against a throwaway OPENCLAW_STATE_DIR.

Verbatim stdout at head b5531419e17:

$ openclaw templates validate /tmp/mcp-cli-198554/non-string-arg
ERROR invalid_manifest $.mcpServers.s.args[0]: Invalid input: expected string, received number
[exit 1]

$ openclaw templates validate /tmp/mcp-cli-198554/transport-missing
ERROR invalid_manifest $.mcpServers.s.transport: Invalid option: expected one of "sse"|"streamable-http"
[exit 1]

$ openclaw templates validate /tmp/mcp-cli-198554/empty-decl
ERROR invalid_manifest $.mcpServers.s.command: Invalid input: expected string, received undefined
[exit 1]

$ openclaw templates validate /tmp/mcp-cli-198554/control-sse
Valid Template project: /tmp/mcp-cli-198554/control-sse
Package: [email protected]
[exit 0]

and the same case in --json mode:

{
  "schemaVersion": "openclaw.templateProject.v1",
  "stability": "experimental",
  "ok": false,
  "root": "/tmp/mcp-cli-198554/non-string-arg",
  "diagnostics": [
    {
      "level": "error",
      "code": "invalid_manifest",
      "phase": "schema",
      "path": "$.mcpServers.s.args[0]",
      "message": "Invalid input: expected string, received number"
    }
  ]
}

Both legs are the identical harness; only src/templates/schema.ts differs (base blob 287aa25a… = unmodified origin/main, head blob edcec60a…):

Case (mcpServers.s) unmodified origin/main head b5531419e17
{ url: "https://x.example/mcp" } $.mcpServers.s: Invalid input · exit 1 $.mcpServers.s.transport: Invalid option: expected one of "sse"|"streamable-http" · exit 1
{ url: …, transport: http } $.mcpServers.s: Invalid input · exit 1 $.mcpServers.s.transport: Invalid option: expected one of "sse"|"streamable-http" · exit 1
{ command: node, args: [8080] } $.mcpServers.s: Invalid input · exit 1 $.mcpServers.s.args[0]: Invalid input: expected string, received number · exit 1
{} $.mcpServers.s: Invalid input · exit 1 $.mcpServers.s.command: Invalid input: expected string, received undefined · exit 1
valid stdio / sse / streamable-http (controls) ok: true · exit 0 ok: true · exit 0 (unchanged)

All 14 invocations (7 fixtures × text/--json) are recorded with stdout and exit status in after-cli-entry-matrix.txt / before-cli-entry-matrix.txt. The [openclaw] log file append failed line in those transcripts is the throwaway state dir's file-log transport — 7 occurrences in each leg, so unrelated to this change.

2. Committed regressions: red on the base, green on the head

src/templates/schema.test.ts (unchanged between legs) run through the repo runner against both versions of src/templates/schema.ts:

base (schema.ts restored from origin/main, blob 287aa25a…):
  × parseTemplateManifest > names the malformed MCP field for {"server":{"url":"https://mcp.linear.app/mcp"}, …}
  × parseTemplateManifest > names the malformed MCP field for {"server":{"url":"https://mcp.linear.app/mcp","transport":"http"}, …}
  × parseTemplateManifest > names the malformed MCP field for {"server":{"command":"node","args":[8080]}, …}
  × parseTemplateManifest > names the malformed MCP field for {"server":{}, …}
  AssertionError: expected [ { level: 'error', …(4) } ] to deep equally contain ObjectContaining{…}
    - Expected: { path: "$.mcpServers.remote.transport", message: StringContaining "expected one of \"sse\"|\"streamable-http\"" }
    + Received: [ { code: "invalid_manifest", level: "error", message: "Invalid input",
                    path: "$.mcpServers.remote", phase: "schema" } ]
  Test Files 1 failed (1) | Tests 4 failed | 45 passed (49) | exit 1

head (b5531419e17, blob edcec60a…):
  ✓ the same four cases
  Test Files 1 passed (1) | Tests 49 passed (49) | exit 0

src/templates/schema.ts was restored to the head blob afterwards (git checkout HEAD -- src/templates/schema.ts, sha256 verified, git status clean).

The six suites that touch this surface also pass at head in one runner invocation — src/templates/{schema,schema-conformance,project,reader}.test.ts + src/cli/templates-cli{,.project}.test.ts:

|unit| Test Files 4 passed (4) | Tests 97 passed | 1 skipped (98) | 145.36s
|cli|  Test Files 2 passed (2) | Tests 28 passed (28)             | 35.90s
[test] passed 2 Vitest shards in 189.15s | exit 0

pnpm exec oxfmt --check on both changed files: All matched files use the correct format. (exit 0). pnpm exec oxlint on both changed files: exit 0.

Still not available locally (host limits, unchanged)

  • pnpm tsgo:core cannot run here: the native tsrs binary needs GLIBC_2.32/2.33/2.34, this host has glibc 2.31.
  • The repo lint wrapper node scripts/run-oxlint.mjs (CI's path) aborts in oxlint 1.89.0's Rust allocator pool on this 4.19 kernel (crates/oxc_allocator/src/pool/fixed_size.rs:112, exit 134) and reproduces identically on untouched files such as src/templates/project.ts, so it is environmental.
  • The bundled dist/entry.js artifact was not built (the local tsdown build is refused here: ≥4352MB heap, ~4.7GB peak). The proof above runs the exact module that build bundles, so the only unexercised layers are bundling itself and openclaw.mjs's Node-version/compile-cache gating — neither touched by this change.

CI status on this head

No CI job has run and failed on b5531419e17. Its workflow runs (CI, CodeQL, CodeQL Critical Quality, Workflow Sanity, OpenGrep — PR Diff, macOS Periphery Dead Code) are all action_required, awaiting maintainer approval for this fork PR, and openclaw/ci-gate reports failure until they are authorized and complete ("CI must complete successfully; review updates automatically"). That is the review's second "Before merge" item and needs a maintainer.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 14, 2026
@obviyus

obviyus commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Confirmed the fix through openclaw templates validate at f04c05b1809aad15d469cbafa1cd2aba72186cff.

The CLI routes through templates-cli.ts → runTemplatesValidateCommand → validateTemplateProject → readTemplateManifestFile → parseTemplateManifest. Only diagnostic formatting changes; every returned message is an existing Zod issue's message, unchanged.

Host isolation check: the merge-base diff touches only src/templates/schema.ts and src/templates/schema.test.ts; no package manifests, lock/workspace files, lifecycle scripts, scripts paths, patches, or hooks. All checks ran through ocx on macOS arm64, with task-owned HOME/state/profile paths for CLI runs. No live Gateway, credentials, or host hooks were used.

vitest-source: the contributor's unchanged four regressions fail on main merge-base d70395f0265c with the generic server-level error and pass on contributor head b5531419e171. After simplification, ocx test src/templates/schema.test.ts src/templates/schema-conformance.test.ts --no-memo passes 61/61 (44.40 s runner wall time). Focused oxlint exits 0.

source: real on-disk Template projects (package.json + CLAW.md), separate CLI processes, JSON output and exit statuses. Both base and final candidate ran twice, including controls. The following is identical in each repeat:

Entry                           Main merge-base                 Candidate
command: node, args: [8080]      $.mcpServers.sample:             $.mcpServers.sample.args[0]:
                                Invalid input                    Invalid input: expected string, received number
url: https://example.com/mcp,    $.mcpServers.sample:             $.mcpServers.sample.transport:
transport: http                 Invalid input                    Invalid option: expected one of "sse"|"streamable-http"
transport: http (no URL/command) $.mcpServers.sample:             $.mcpServers.sample:
                                Invalid input                    Invalid input
valid stdio                     ok: true, exit 0                 ok: true, exit 0
valid remote SSE                ok: true, exit 0                 ok: true, exit 0

All malformed cases exit 1. The equally-close case has two existing issues per branch and retains the original union message rather than guessing.

Simplified production from +48/-3 to +23/-7 (net +16), removing both added helpers and intermediate issue objects. Consolidated MCP tests retain the four regressions, existing rejection cases, OAuth acceptance, and a tie control: +25/-32, net -7, no allocation file. Contributor commit and credit are retained. Both added commits are authored/committed by Ayaan Zaidi; original author/committer is LiuwqGit. No agent identities or co-author trailers.

full: ocx build --dts succeeded on the final head (259 s). Packed with ocx run -- npm pack --ignore-scripts, unpacked into a disposable directory, and ran its openclaw.mjs with installed dependencies supplied from the worktree and bundled-entry source fallback disabled. All five CLI scenarios above produced the same paths/messages and expected exit statuses; valid stdio and remote controls passed. The first smoke harness incorrectly linked an existing dependency directory; that setup error was corrected before this successful run. The unpacked package and tarball were removed.

Commands: ocx src -- --profile p198598base templates validate <project> --json and the identical candidate command; each project contains only the synthetic package manifest and CLAW.md. No Gateway or model is needed for this validation path.

Message provenance was also checked directly against uncustomized Zod schemas (z.string(), z.enum(["sse", "streamable-http"]), and z.union(...)): they produce exactly Invalid input: expected string, received number, Invalid option: expected one of "sse"|"streamable-http", Invalid input: expected string, received undefined, and Invalid input. These are Zod's built-in messages, not newly authored error text.

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 15, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 15, 2026
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Merged current main 315ad24eb8aa (including #198800's automation-name/heartbeat bounds) into the contributor branch without rebasing or manual conflict resolution. New head: 02baa3b6df5d07f3c063945de3d075524af52344. No other code changes.

Requested post-merge checks, through host ocx:

  • vitest-source: ocx test src/templates/schema.test.ts src/templates/schema-conformance.test.ts --no-memo — 65/65 passed, 49.04 s runner wall time. Current main adds four heartbeat/automation cases to the previous 61.
  • source: one openclaw templates validate <project> --json process per existing MCP fixture, with isolated HOME/state/profile paths:
stdioBad:   $.mcpServers.sample.args[0]: Invalid input: expected string, received number
remoteBad:  $.mcpServers.sample.transport: Invalid option: expected one of "sse"|"streamable-http"
tie:        $.mcpServers.sample: Invalid input
stdioValid: PASS
remoteValid: PASS

Malformed cases exited 1; valid controls exited 0. These remain Zod's built-in messages, unchanged.

The host-isolation diff against the new merge base still contains only src/templates/schema.ts and src/templates/schema.test.ts; no package, lifecycle, scripts, hook, or dependency changes. No host hooks ran. Earlier full-build/packed receipts remain attached to the pre-merge head; this comment records the specifically requested merged-head schema and source validation.

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 15, 2026
@obviyus
obviyus merged commit ee41e9e into openclaw:main Nov 15, 2026
124 checks passed
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Landed in ee41e9e. Thanks @LiuwqGit.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…penclaw#198598)

fix(templates): report the closest MCP server shape's field errors

A Template MCP server entry must match either the stdio or the remote shape. An entry that matched neither reported only `$.mcpServers.<name>: Invalid input`, hiding which field was wrong. Validation now reports the existing field-level errors from the shape the entry most closely matches, and keeps "Invalid input" when no shape is clearly closer. The detailed messages are the schema library's built-in messages; no new text.

Evidence: source tier with `openclaw templates validate` on Template projects; base twice, candidate twice, rechecked after merging current main. A mostly-stdio entry with a number where a string belongs and a remote entry with `transport: http` reported only "Invalid input" on base; this change reports the field path with "Invalid input: expected string, received number" and "Invalid option: expected one of \"sse\"|\"streamable-http\"". An entry equally close to both shapes still reports "Invalid input", and valid stdio and remote entries pass on both. Vitest-source: the regression fails on base and all 65 schema tests pass here; full build and packed smoke pass. Net -7 test lines. Receipts: openclaw#198598 (comment) and openclaw#198598 (comment).

Fixes openclaw#198554. Thanks @LiuwqGit.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Invalid Template MCP declarations report only "Invalid input"

2 participants