fix(mcp): advertise input patterns without look-around
trace_dylib_resolution roots and capture_process_scenario environment names still advertised negative look-ahead patterns. RE2 and Rust schema validators reject look-around, so a client using one refuses the whole tools request, as #1282 reported for the NUL escape. Spell both constraints as equivalent look-around-free patterns and assert that no advertised pattern uses look-around or backreferences. Closes #1282 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
99f257bbf0
commit
a8701eaf48
@@ -5,10 +5,31 @@ import { z } from "zod";
|
||||
const positiveBudget = z.number().int().safe().positive();
|
||||
const timedEventBase = { at_ms: z.number().int().safe().nonnegative() };
|
||||
const reservedRunIdEnvironmentName = "REA_PROCESS_RUN_ID";
|
||||
const ENVIRONMENT_NAME_CHARACTER = "[^=\\u0000]";
|
||||
|
||||
/**
|
||||
* Nonempty environment names other than the reserved run identifier. The
|
||||
* exclusion is spelled as a complement instead of a negative look-ahead,
|
||||
* because RE2 and Rust schema validators reject look-around and would refuse
|
||||
* every tool in the advertised catalog.
|
||||
*/
|
||||
const environmentNamePattern = (reserved: string): RegExp => {
|
||||
// After the complete reserved name, at least one more character is needed.
|
||||
let rest = `${ENVIRONMENT_NAME_CHARACTER}+`;
|
||||
for (let index = reserved.length - 1; index >= 0; index -= 1) {
|
||||
const character = reserved[index] ?? "";
|
||||
// Diverge here, match the next reserved character, or (after a nonempty
|
||||
// prefix) end the name early.
|
||||
const choice = `[^=\\u0000${character}]${ENVIRONMENT_NAME_CHARACTER}*|${character}${rest}`;
|
||||
rest = index === 0 ? choice : `(?:${choice})?`;
|
||||
}
|
||||
return new RegExp(`^(?:${rest})$`, "u");
|
||||
};
|
||||
|
||||
const environmentName = z
|
||||
.string()
|
||||
.min(1, "Environment names must not be empty")
|
||||
.regex(/^(?!REA_PROCESS_RUN_ID(?![\s\S]))[^=\u0000]+$/u, {
|
||||
.regex(environmentNamePattern(reservedRunIdEnvironmentName), {
|
||||
error: (issue) =>
|
||||
issue.input === reservedRunIdEnvironmentName
|
||||
? `${reservedRunIdEnvironmentName} is reserved by the process adapter`
|
||||
|
||||
Reference in New Issue
Block a user