Files
spellforge/Tools/godot-mcp-pro/server/build/utils/zod-coerce.js
T
joywayerandClaude Opus 4.8 e65066a8fb chore: 重命名 Tools/godot-mcp-pro-v1.15.1 → Tools/godot-mcp-pro,更新 .mcp.json
- 去掉版本号后缀,路径更稳定(后续更新工具不必再改 .mcp.json)
- .mcp.json 指向新路径 server/build/index.js
- server 依赖已 npm install 就绪;node_modules 由 .gitignore 忽略,未入库

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 15:37:18 +08:00

35 lines
1.0 KiB
JavaScript

import { z } from "zod";
/**
* Coerce a value that might be a JSON string into a string array.
* LLMs sometimes pass arrays as stringified JSON (e.g. '["a","b"]' instead of ["a","b"]).
*/
export function coerceStringArray() {
return z.preprocess((val) => {
if (typeof val === "string") {
try {
const parsed = JSON.parse(val);
if (Array.isArray(parsed))
return parsed;
}
catch {
// not JSON, return as-is for zod to validate
}
}
return val;
}, z.array(z.string()));
}
/**
* Coerce a value that might be a numeric string into a number.
* LLMs sometimes pass numbers as strings (e.g. "30" instead of 30).
*/
export function coerceNumber() {
return z.preprocess((val) => {
if (typeof val === "string") {
const n = Number(val);
if (!isNaN(n))
return n;
}
return val;
}, z.number());
}
//# sourceMappingURL=zod-coerce.js.map