feat: generate JSON schemas for all manifest versions
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'
This commit is contained in:
parent
faafd4523a
commit
b5fa7df6eb
1 changed files with 1491 additions and 16 deletions
|
|
@ -1,33 +1,49 @@
|
|||
import {
|
||||
McpbManifestSchema,
|
||||
McpbManifestSchema as McpbManifestSchemaLatest,
|
||||
McpbSignatureInfoSchema,
|
||||
} from "../dist/schemas/latest.js";
|
||||
import { McpbManifestSchema as McpbManifestSchema_v0_1 } from "../dist/schemas/0.1.js";
|
||||
import { McpbManifestSchema as McpbManifestSchema_v0_2 } from "../dist/schemas/0.2.js";
|
||||
import { McpbManifestSchema as McpbManifestSchema_v0_3 } from "../dist/schemas/0.3.js";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
const schemasToWrite = {
|
||||
"mcpb-manifest": McpbManifestSchema,
|
||||
"mcpb-signature-info": McpbSignatureInfoSchema,
|
||||
};
|
||||
|
||||
const distDir = path.join(import.meta.dirname, "../dist");
|
||||
const schemasDir = path.join(import.meta.dirname, "../schemas");
|
||||
|
||||
// Versioned manifest schemas
|
||||
const versionedManifestSchemas = {
|
||||
"mcpb-manifest-v0.1": McpbManifestSchema_v0_1,
|
||||
"mcpb-manifest-v0.2": McpbManifestSchema_v0_2,
|
||||
"mcpb-manifest-v0.3": McpbManifestSchema_v0_3,
|
||||
"mcpb-manifest-latest": McpbManifestSchemaLatest,
|
||||
"mcpb-manifest": McpbManifestSchemaLatest, // Alias for latest
|
||||
};
|
||||
|
||||
// Other schemas
|
||||
const otherSchemas = {
|
||||
"mcpb-signature-info": McpbSignatureInfoSchema,
|
||||
};
|
||||
|
||||
const allSchemas = { ...versionedManifestSchemas, ...otherSchemas };
|
||||
|
||||
// Generate all schemas to dist/
|
||||
await fs.mkdir(distDir, { recursive: true });
|
||||
for (const key in schemasToWrite) {
|
||||
const schema = zodToJsonSchema(schemasToWrite[key]);
|
||||
for (const [key, schema] of Object.entries(allSchemas)) {
|
||||
const jsonSchema = zodToJsonSchema(schema);
|
||||
const filePath = path.join(distDir, `${key}.schema.json`);
|
||||
await fs.writeFile(filePath, JSON.stringify(schema, null, 2), {
|
||||
await fs.writeFile(filePath, JSON.stringify(jsonSchema, null, 2), {
|
||||
encoding: "utf8",
|
||||
});
|
||||
}
|
||||
|
||||
// Generate only manifest schema to schemas/
|
||||
// Generate all versioned manifest schemas to schemas/
|
||||
await fs.mkdir(schemasDir, { recursive: true });
|
||||
const manifestSchema = zodToJsonSchema(McpbManifestSchema);
|
||||
const manifestPath = path.join(schemasDir, "mcpb-manifest.schema.json");
|
||||
await fs.writeFile(manifestPath, JSON.stringify(manifestSchema, null, 2), {
|
||||
encoding: "utf8",
|
||||
});
|
||||
for (const [key, schema] of Object.entries(versionedManifestSchemas)) {
|
||||
const jsonSchema = zodToJsonSchema(schema);
|
||||
const filePath = path.join(schemasDir, `${key}.schema.json`);
|
||||
await fs.writeFile(filePath, JSON.stringify(jsonSchema, null, 2), {
|
||||
encoding: "utf8",
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue