Skip to content

Commit cb0fa43

Browse files
fix: handle empty path array in getParseErrorMessage
Zod sets path: [] for root-level errors; ![] is false so the early-return never fired. Match main's standardSchema.ts:167 approach with ?.length. Also add changeset.
1 parent 68091ab commit cb0fa43

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/sdk': patch
3+
---
4+
5+
Prioritize `error.issues[].message` over `error.message` in `getParseErrorMessage` so custom Zod error messages surface correctly. In Zod v4, `error.message` is a JSON blob of all issues, not a readable string.

src/server/zod-compat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export function getParseErrorMessage(error: unknown): string {
214214
if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) {
215215
return error.issues
216216
.map((i: { message: string; path?: (string | number)[] }) => {
217-
if (!i.path) {
217+
if (!i.path?.length) {
218218
return i.message;
219219
}
220220
return `${i.message} at ${getDotPath(i.path)}`;

0 commit comments

Comments
 (0)