notion-mcp-server
Version:
Notion MCP server with token auth: connect Claude Code, Claude Desktop, Cursor, VS Code, Codex and any MCP client to Notion. Search, create and edit pages, query databases, comment and upload files. Runs headless in CI and agents.
41 lines (40 loc) • 2.04 kB
JavaScript
import { emitJsonSchema } from "../schema/emit.js";
import { sliceJsonSchema, summarizeSchema } from "./schema-slice.js";
// Top-level .refine() failures (XOR rules etc.) carry the whole-payload
// example as actionable guidance — the full JSON schema would only add
// noise. Skip the schema for those and any other top-level-only issue
// where the example is self-explanatory.
function shouldIncludeSchema(issues) {
return issues.some((i) => i.path.length > 0);
}
export function buildValidationError(def, zodError) {
const issues = zodError.issues.map((i) => ({
path: i.path,
message: i.message,
}));
const firstPath = issues[0]?.path ?? [];
const firstMsg = issues[0]?.message ?? "Validation failed";
const includeSchema = shouldIncludeSchema(zodError.issues);
// Slice the schema down to the failing field's subtree and summarize any
// unions so the envelope stays small — the unsliced schema for ops like
// set_page_property or update_database is 5-13KB.
let schemaForError;
if (includeSchema) {
const fullSchema = emitJsonSchema(def.schema);
const sliced = firstPath.length > 0 ? sliceJsonSchema(fullSchema, firstPath) : fullSchema;
schemaForError = summarizeSchema(sliced);
}
return {
code: "validation_error",
operation: def.name,
message: `${firstMsg}${firstPath.length ? ` at ${firstPath.join(".")}` : ""}`,
path: firstPath.length ? firstPath : undefined,
issues,
...(includeSchema ? { schema: schemaForError } : {}),
example: def.example,
...(def.exampleBatch ? { example_batch: def.exampleBatch } : {}),
fix: includeSchema
? "Match the example shape. The schema above shows the failing field; call notion_describe for the full operation schema. For batch mode, wrap items in { items: [...] }."
: "A working example is included above. Match the example shape and retry. For batch mode, wrap items in { items: [...] }.",
};
}