Skip to content

feat: export versioned schemas in package.json#138

Merged
joan-anthropic merged 11 commits into
mainfrom
feat/export-versioned-schemas
Oct 30, 2025
Merged

feat: export versioned schemas in package.json#138
joan-anthropic merged 11 commits into
mainfrom
feat/export-versioned-schemas

Conversation

@joan-anthropic
Copy link
Copy Markdown
Contributor

@joan-anthropic joan-anthropic commented Oct 29, 2025

Summary

Add exports for versioned schemas (both Zod and JSON Schema) to allow consumers to import schemas cleanly. Bump version to 1.1.3.

All schema exports are now explicitly versioned with no legacy non-versioned files. Added a union schema (any) that validates manifests from any supported version.

Changes

1. Package Exports

Added export paths for:

Zod Schemas:

  • ./schemas - All versioned Zod schemas (v0_1, v0_2, v0_3, latest, any)
  • ./schemas/any - Union schema that accepts any version (v0.1, v0.2, v0.3)
  • ./schemas/* - Wildcard export for specific schema files (e.g., ./schemas/0.2)
  • ./schemas-loose - Loose validation schemas

JSON Schemas (all explicitly versioned):

  • ./mcpb-manifest-v0.1.schema.json - v0.1 JSON Schema
  • ./mcpb-manifest-v0.2.schema.json - v0.2 JSON Schema
  • ./mcpb-manifest-v0.3.schema.json - v0.3 JSON Schema
  • ./mcpb-manifest-latest.schema.json - Latest version JSON Schema

2. Union Schema (any)

Created src/schemas/any.ts:

export const McpbManifestSchema = z.union([
  v0_1.McpbManifestSchema,
  v0_2.McpbManifestSchema,
  v0_3.McpbManifestSchema,
]);

This schema accepts and validates manifests from any supported version (0.1, 0.2, 0.3).

3. JSON Schema Generation

Updated build script to generate JSON schemas for all versions:

  • All versioned schemas generated to both dist/ and schemas/ directories
  • Each version has strict constraints on version fields
  • Removed non-versioned mcpb-manifest.schema.json (all schemas now explicitly versioned)

4. Version Bump

  • Updated package version from 1.1.2 to 1.1.3

Usage Examples

Zod Schema Imports

Import union schema (recommended for validating any version):

import { McpbManifestSchema } from '@anthropic-ai/mcpb/schemas/any';
// ✅ Validates v0.1, v0.2, or v0.3 manifests

Import specific version:

import { McpbManifestSchema } from '@anthropic-ai/mcpb/schemas/0.2';
// ✅ Only validates v0.2 manifests

Import all versions as namespace:

import * as schemas from '@anthropic-ai/mcpb/schemas';
// Access: schemas.v0_1, schemas.v0_2, schemas.v0_3, schemas.latest, schemas.any

// Use the union:
schemas.any.McpbManifestSchema.parse(manifest);

// Or create custom union:
import { z } from 'zod';
const CustomSchema = z.union([
  schemas.v0_1.McpbManifestSchema,
  schemas.v0_2.McpbManifestSchema,
]);

Import latest:

import { McpbManifestSchema } from '@anthropic-ai/mcpb/schemas/latest';
// or
import { McpbManifestSchema } from '@anthropic-ai/mcpb';
// Both validate v0.3 (current latest)

JSON Schema Imports

// Import specific version JSON schema
import schemaV02 from '@anthropic-ai/mcpb/mcpb-manifest-v0.2.schema.json'

// Import latest version (recommended)
import latestSchema from '@anthropic-ai/mcpb/mcpb-manifest-latest.schema.json'

// Use in validation tools
import Ajv from 'ajv'
const ajv = new Ajv()
const validate = ajv.compile(schemaV02)

Before

Consumers had to reach into dist folder:

// @ts-ignore
import * as v0_1 from '@anthropic-ai/mcpb/dist/schemas/0.1.js'

// Ambiguous non-versioned schema
import schema from '@anthropic-ai/mcpb/mcpb-manifest.schema.json'

// No union schema available - had to create manually

After

Clean, properly exported imports with explicit versioning:

// Union schema for any version
import { McpbManifestSchema } from '@anthropic-ai/mcpb/schemas/any'

// Specific versions
import * as v0_1 from '@anthropic-ai/mcpb/schemas/0.1'

// Versioned JSON schemas
import schemaV01 from '@anthropic-ai/mcpb/mcpb-manifest-v0.1.schema.json'
import latestSchema from '@anthropic-ai/mcpb/mcpb-manifest-latest.schema.json'

Files Structure

dist/ (npm package distribution):

  • schemas/any.js - Union of all versions (NEW)
  • schemas/0.1.js, 0.2.js, 0.3.js - Specific versions
  • schemas/latest.js - Latest version
  • schemas/index.js - All exports
  • mcpb-manifest-v0.1.schema.json
  • mcpb-manifest-v0.2.schema.json
  • mcpb-manifest-v0.3.schema.json
  • mcpb-manifest-latest.schema.json
  • mcpb-signature-info.schema.json

schemas/ (source schemas, included in package):

  • mcpb-manifest-v0.1.schema.json
  • mcpb-manifest-v0.2.schema.json
  • mcpb-manifest-v0.3.schema.json
  • mcpb-manifest-latest.schema.json

Testing

  • ✅ Built the package successfully
  • ✅ All tests pass (99 tests)
  • ✅ Lint clean (0 errors, 0 warnings)
  • ✅ Verified union schema exports correctly
  • ✅ Verified all Zod schema files exported from dist/
  • ✅ Verified only versioned JSON schemas (no legacy files)
  • ✅ Verified JSON schemas have correct version constraints

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Add exports for versioned schemas to allow consumers to import:
- ./schemas: All versioned schemas (v0_1, v0_2, v0_3, latest)
- ./schemas/*: Specific schema versions (./schemas/0.1, ./schemas/any, etc.)
- ./schemas-loose: Loose validation schemas

This enables cleaner imports like:
import { McpbManifestSchema } from '@anthropic-ai/mcpb/schemas/any'
import * as v0_2 from '@anthropic-ai/mcpb/schemas/0.2'
import * as schemas from '@anthropic-ai/mcpb/schemas'
Changed McpbManifest type from a single version to a discriminated union
of all historical manifest versions (0.1, 0.2, 0.3).

This allows the type system to properly handle manifests from any version
while maintaining type safety through the manifest_version/dxt_version
discriminator field.

Benefits:
- Type-safe handling of multiple manifest versions
- TypeScript can narrow types based on version field
- No need for type assertions when working with versioned manifests
- Maintains backward compatibility with all historical versions
@joan-anthropic joan-anthropic added the enhancement New feature or request label Oct 29, 2025
Updated build script to generate JSON schemas for all historical manifest
versions (v0.1, v0.2, v0.3) in addition to the latest version.

Changes:
- Generate mcpb-manifest-v0.1.schema.json
- Generate mcpb-manifest-v0.2.schema.json
- Generate mcpb-manifest-v0.3.schema.json
- Generate mcpb-manifest-latest.schema.json
- Keep mcpb-manifest.schema.json as alias for latest
- All schemas generated to both dist/ and schemas/ directories
- Added exports in package.json for all versioned schemas

Benefits:
- Tools can validate against specific manifest versions
- Backwards compatibility for all historical versions
- Latest schema always available at predictable path
- JSON schema files match the Zod schema versions

Usage:
import manifestSchema from '@anthropic-ai/mcpb/mcpb-manifest-v0.2.schema.json'
import latestSchema from '@anthropic-ai/mcpb/mcpb-manifest-latest.schema.json'
Remove the generic mcpb-manifest.schema.json export from package.json
in favor of explicit versioned exports.

Changes:
- Removed ./mcpb-manifest.schema.json from package exports
- Stop generating mcpb-manifest.schema.json in dist/
- Keep mcpb-manifest.schema.json in schemas/ for backward compatibility

Consumers should now use:
- mcpb-manifest-latest.schema.json (for latest version)
- mcpb-manifest-v0.1.schema.json (for specific version)
- etc.

This makes versioning explicit and prevents ambiguity about which
schema version is being used.
- Remove unused McpbManifestSchema import from types.ts
- Run prettier on modified files
Reverted the discriminated union type change. McpbManifest now uses
the latest schema as before. Consumers can use versioned schemas
directly if they need to validate specific versions.
Removed the non-versioned mcpb-manifest.schema.json from schemas/
directory. All schemas are now explicitly versioned.

Available schemas:
- mcpb-manifest-v0.1.schema.json
- mcpb-manifest-v0.2.schema.json
- mcpb-manifest-v0.3.schema.json
- mcpb-manifest-latest.schema.json

Consumers should use -latest or specific version to be explicit
about which schema version they're validating against.
Copy link
Copy Markdown
Contributor

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving for now, we should have a script that ensures the JSON files haven't drifted tho (ez follow up)

@joan-anthropic joan-anthropic merged commit 11d1397 into main Oct 30, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants