Skip to content

[Bug] MCP tool schemas use \0 octal escapes and an unescaped [ inside a character class — strict validators reject every request #1282

Closed

Description

@HOPEmyheart

Summary

Several tool inputSchema.pattern values emitted over MCP use two regex constructs that stricter schema validators reject:

  1. octal escape \0
  2. an unescaped [ inside a character class, e.g. [^\s[\]]

Because tool schemas are attached to every request, a client talking to a provider whose validator rejects them fails on every single turn — the session becomes unusable, and the user cannot even ask the client to help fix it.

Environment

  • rea-agents 6.1.0 (latest on npm at time of writing, published 2026-10-09T01:16Z)
  • invoked as an MCP server: node .../rea-agents/scripts/rea.mjs mcp
  • client: a strict-schema MCP client
  • backend: a model API whose schema validator rejects these patterns

Symptom

Every request returns HTTP 400:

API Error: 400 Invalid schema for function 'mcp__rea__analyze_javascript_application':
"^[^\0]*$" is not a "regex"

API Error: 400 Invalid schema for function 'mcp__rea__observe_native_calls':
"^[^\s[\]]+$" is not a "regex"

No tool call is ever reached — the request never gets that far. The error surfaces on the client's request and names a tool the user never invoked, which makes it hard to self-diagnose.

Why these are rejected

They are valid JavaScript. Under the /u flag a lone \0 is a legal NUL escape, and a bare [ inside a class is a literal — Node accepts all of them, so it never shows up in the CLI or in a Node-side test.

But a JSON Schema pattern is consumed by whatever validator the consumer uses, and that is not always an ECMAScript engine. Validators built on stricter engines reject them outright. I have not inspected the validator's source, but the measured behaviour is consistent with the Rust regex crate, which has no octal escape support and requires [ to be escaped inside a character class.

Measured against the actual validator that produced the error above — the only difference between pass and fail is those two constructs:

pattern result
^[^\0]*$ 400 is not a "regex"
^[^\s[\]]+$ 400 is not a "regex"
^[^\x00]*$ 200
^[^\s\[\]]+$ 200
^[a-z]+$ (control) 200

Minimal reproduction

One tool is enough:

POST /v1/messages
{
  "model": "<any>",
  "max_tokens": 1,
  "messages": [{"role": "user", "content": "hi"}],
  "tools": [{
    "name": "probe_tool",
    "description": "probe",
    "input_schema": {
      "type": "object",
      "properties": {"x": {"type": "string", "pattern": "^[^\\0]*$"}}
    }
  }]
}

→ 400 Invalid schema for function 'probe_tool': "^[^\\0]*$" is not a "regex"

Affected patterns

Grepping the published dist/ for the two constructs finds 16 occurrences across 11 files:

dist/artifacts/apple/InterfaceBuilderAnalysis.js     \0+$                 -> \x00+$
dist/artifacts/apple/NibArchive.js                   \0+$                 -> \x00+$
dist/artifacts/apple/NibViewHierarchy.js             \0+$       (x2)      -> \x00+$
dist/browser/CdpEndpoint.js                          [.*+?^${}()|[\]\\]   -> [.*+?^${}()|\[\]\\]
dist/contracts/native/nativeToolContracts.js         ^[^\0]*$             -> ^[^\x00]*$
dist/domain/apple/dylibResolution.js                 ...[^\\\0]+$         -> ...[^\\\x00]+$
dist/domain/javascript/electronActiveObservation.js  ^[^\0]*$             -> ^[^\x00]*$
dist/domain/localPath.js                             ^[^\0]*$             -> ^[^\x00]*$
dist/domain/native/nativeCallObservation.js          ^[^=\0]+$            -> ^[^=\x00]+$
                                                     ^[^\0]*$   (x2)      -> ^[^\x00]*$
                                                     ^[^\s[\]]+$          -> ^[^\s\[\]]+$
dist/domain/process/processScenario.js               ...(?![\s\S]))[^=\0]+$ -> ...[^=\x00]+$
                                                     ^[^\0]*$             -> ^[^\x00]*$
dist/native/AppleMachoSelection.js                   \0.*$                -> \x00.*$

Tool schemas confirmed to carry these over MCP include at least analyze_javascript_application and observe_native_calls; the same helpers are used across the native / browser / process tool families, so the blast radius is wider than the two tool names the provider happened to report first.

Suggested fix

Two purely mechanical substitutions at the source of the contracts:

  • octal \0 → \x00 (and generally \0nn → \xNN)
  • inside a character class, a bare [ → \[

Both are semantics-preserving. I verified this exhaustively over 232 code points (all of Latin-1 plus representative Unicode) across all 16 sites: old and new patterns match an identical character set for every code point, and every rewritten file still passes node --check.

A more durable option: keep pattern values to the strictest common denominator, or drop pattern entirely and express the constraint with minLength/maxLength plus the existing zod validation — zod already runs server-side and can return a much better message than a schema rejection at the transport layer.

Impact

Any client whose provider validates tool.inputSchema strictly is completely unusable while rea is registered — not degraded, unusable — because the invalid schema rides along with every request.

A PR applying the substitution should be straightforward.

Activity

  1. kaoru0822-kitauji commented on Oct 9, 2026

    @kaoru0822-kitauji
    Collaborator

    On main, #1220 already removed both constructs from this report (\0 → \u0000, and the escaped [). Compiling every advertised pattern with the Rust regex engine (ripgrep, which reproduces your table exactly) still rejected two look-ahead input patterns: trace_dylib_resolution roots and capture_process_scenario environment names. Either one would still make a strict client refuse every request. #1299 rewrites both without look-around, with equivalence tests against the old regexes, and adds a catalog-wide assertion. With it, all 92 advertised patterns compile under that engine.

  2. added
    bug
    area: mcp
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: mcpbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions