Skip to content

Named project schemas shared by HTTP bodies and MCP tools, loadable from files offline (#845) - #907

Merged
jimhoyd merged 4 commits into
mainfrom
claude/shared-schemas
Sep 29, 2026
Merged

jimhoyd merged 4 commits into
mainfrom
claude/shared-schemas

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Closes #845's remaining acceptance items: "one source schema supplies HTTP and a declared MCP operation", and "consume one independently authored standard schema with local refs".

  • Declaring schemas: a top-level schemas: map in the entry urlcode.yaml. Each entry is a 2020-12 schema in the body profile, inline or {file: <path>}.
    • At most 64 entries. Names starting with Urlcode are reserved, and includes can't declare schemas.
  • Referencing a schema: by plain name, e.g. request.body.POST.schema: contact, or an mcp tool's inputSchema / outputSchema.
    • A name is used because a JSON Schema is never a string, so it can't be mistaken for one.
    • $ref keeps its standard meaning (local #/$defs only).
    • An unknown name fails at load and suggests the closest declared one.
  • Schema files:
    • Read offline by the artifact-inspect resolver rooted at the project, with limits: 256 KiB per file, 2 MiB and 64 files in all, 512 refs, depth 16.
    • Refused: remote refs, escapes, symlinks, missing targets, cycles and $anchor. Messages never echo ref text.
    • Relative refs are bundled into one self-contained schema, which is then checked against the profile. YAML files use the inert YAML profile (Installed-file record, bounded YAML for inert documents, and upgrading independent packages (#857) #901).
    • The file bytes feed version and projectSha256, so editing a schema needs re-review.
  • Where named schemas are used:
    • Compiled once and used by routes and by mcp tools; tools/list advertises the resolved schema.
    • OpenAPI writes each named schema once as a component.
    • The Cloudflare build creates one standalone validator per named schema.
  • Not carried by a shared schema: authorization, parameter coercion, display metadata and stored defaults. Documented in HTTP.md.
  • Store collections: not yet. They use default/readOnly, which the body profile refuses. Follow-up filed.

Evidence (macOS, Node 26)

  • test/named-schemas.test.ts (7 tests):
    • two routes sharing a schema give byte-identical 422s to the inline equivalent;
    • the load refusals;
    • a JSON file referencing a YAML file and another file's $defs bundles exactly;
    • the file refusals: remote, escape, symlink, oversize, cycle;
    • projectSha256 changes on an edit to a referenced file;
    • OpenAPI emits one component;
    • the Worker shares one validator.
  • packages/mcp/test/named-schemas.test.ts: one schema shared by a POST route and an MCP tool gives the same diagnostic pointers for three invalid inputs.
  • examples/body-validation adds schemas/lead.json → contact-point.yaml, shared by /leads and /referrals.
  • npm test 1181, npm run verify and test:package pass. npm run test:workerd is identical on all 43 responses.
  • Budget re-measured after Re-measure the core package budget after #900 and #901 (fixes main's CI) #903.

🤖 Generated with Claude Code

…tools, loaded from files offline (#845)

A top-level `schemas:` map in the entry urlcode.yaml declares JSON Schema
2020-12 documents in the request body profile, inline or `{file: <path>}`.
`request.body.<METHOD>.schema: <name>` and an mcp tool's `inputSchema` /
`outputSchema: <name>` name one; a string is never a JSON Schema, so the
reference cannot be confused with one and `$ref` keeps its standard local
meaning. Unknown names fail at load (route, method, did-you-mean) or at mcp
activation.

- Schema files (JSON, or YAML through the inert-document profile) are read by
  the bounded artifact-inspect resolver rooted at the project: relative $refs
  to project files are followed and bundled into one self-contained schema
  ($defs/<stem>, $defs/<stem>.<name>); remote refs, escapes, symlinks,
  missing targets, cycles and size limits refuse the load without echoing the
  reference. The result is admitted against the body profile.
- Every named schema compiles once; routes share it, the Cloudflare build
  writes one standalone validator per named schema, extensions receive the
  map as ExtensionActivation.schemas, and tools/list advertises it resolved.
- Schema content and each schema file's sha256 enter `version` and
  projectSha256, so an edited schema file needs re-review.
- The OpenAPI export writes each used named schema once as
  components.schemas.<name> and references it from every operation.
- A shared schema carries value shape only: authorization, parameter
  coercion, display metadata and stored defaults stay where they are. Store
  collections cannot name a project schema yet.

Docs: HTTP "Named schemas", SPECIFICATION, TOOLING OpenAPI, EXTENSIONS,
mcp README, RIM-SCHEMA-001, llms.txt, YAML reference; the body-validation
example gains a schema file with relative $refs shared by two routes, and the
workerd parity run covers it. Package budget raised with measurements (main
was already over).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: Adopt standard schemas and OpenAPI for provider interoperability

1 participant