From 9849e046a9ad7dfab11d2c233ed39343fbdd6ab1 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Thu, 3 Jul 2025 15:45:39 -0700 Subject: [PATCH] feat: emit json schema in npm package --- examples/chrome-applescript/manifest.json | 1 + examples/file-manager-python/manifest.json | 1 + examples/hello-world-node/manifest.json | 1 + package.json | 6 ++++-- scripts/build-dxt-schema.js | 14 ++++++++++++++ src/schemas.ts | 10 +++++++--- src/types.ts | 2 +- yarn.lock | 2 +- 8 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 scripts/build-dxt-schema.js diff --git a/examples/chrome-applescript/manifest.json b/examples/chrome-applescript/manifest.json index aebeafe..b9fbcdd 100644 --- a/examples/chrome-applescript/manifest.json +++ b/examples/chrome-applescript/manifest.json @@ -1,4 +1,5 @@ { + "$schema": "../../dist/dxt-manifest.schema.json", "dxt_version": "0.1", "name": "chrome-applescript", "display_name": "Control Chrome with AppleScript", diff --git a/examples/file-manager-python/manifest.json b/examples/file-manager-python/manifest.json index 3a44e6c..1c9f610 100644 --- a/examples/file-manager-python/manifest.json +++ b/examples/file-manager-python/manifest.json @@ -1,4 +1,5 @@ { + "$schema": "../../dist/dxt-manifest.schema.json", "dxt_version": "0.1", "name": "file-manager-python", "display_name": "Python File Manager MCP", diff --git a/examples/hello-world-node/manifest.json b/examples/hello-world-node/manifest.json index fc7d040..557f67c 100644 --- a/examples/hello-world-node/manifest.json +++ b/examples/hello-world-node/manifest.json @@ -1,4 +1,5 @@ { + "$schema": "../../dist/dxt-manifest.schema.json", "dxt_version": "0.1", "name": "hello-world-node", "display_name": "Hello World MCP Server (Reference Extension)", diff --git a/package.json b/package.json index 94689bb..d87e6c2 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,9 @@ "dist" ], "scripts": { - "build": "tsc", + "build": "yarn run build:code && yarn run build:schema", + "build:code": "tsc", + "build:schema": "node --experimental-strip-types ./scripts/build-dxt-schema.js", "dev": "tsc --watch", "test": "jest", "test:watch": "jest --watch", @@ -68,7 +70,7 @@ "commander": "^13.1.0", "fflate": "^0.8.2", "node-forge": "^1.3.1", - "zod": "^3.24.4" + "zod": "^3.25.67" }, "resolutions": { "@babel/helpers": "7.27.1", diff --git a/scripts/build-dxt-schema.js b/scripts/build-dxt-schema.js new file mode 100644 index 0000000..e21b0ef --- /dev/null +++ b/scripts/build-dxt-schema.js @@ -0,0 +1,14 @@ +import { DxtManifestSchema } from "../src/schemas.ts"; +import * as z from "zod/v4"; +import fs from "node:fs/promises"; +import path from "node:path"; + +const schema = z.toJSONSchema(DxtManifestSchema); +await fs.mkdir(path.join(import.meta.dirname, "../dist"), { recursive: true }); +await fs.writeFile( + path.join(import.meta.dirname, "../dist", "dxt-manifest.schema.json"), + JSON.stringify(schema, null, 2), + { + encoding: "utf8", + }, +); diff --git a/src/schemas.ts b/src/schemas.ts index 8c42091..9281a97 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -1,9 +1,9 @@ -import { z } from "zod"; +import * as z from "zod/v4"; export const McpServerConfigSchema = z.object({ command: z.string(), args: z.array(z.string()).optional(), - env: z.record(z.string()).optional(), + env: z.record(z.string(), z.string()).optional(), }); export const DxtManifestAuthorSchema = z.object({ @@ -72,10 +72,12 @@ export const DxtUserConfigurationOptionSchema = z.object({ }); export const DxtUserConfigValuesSchema = z.record( + z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]), ); export const DxtManifestSchema = z.object({ + $schema: z.string().optional(), dxt_version: z.string(), name: z.string(), display_name: z.string().optional(), @@ -97,5 +99,7 @@ export const DxtManifestSchema = z.object({ keywords: z.array(z.string()).optional(), license: z.string().optional(), compatibility: DxtManifestCompatibilitySchema.optional(), - user_config: z.record(DxtUserConfigurationOptionSchema).optional(), + user_config: z + .record(z.string(), DxtUserConfigurationOptionSchema) + .optional(), }); diff --git a/src/types.ts b/src/types.ts index 8a6f908..cdddffa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import type { z } from "zod"; +import type * as z from "zod/v4"; import type { DxtManifestAuthorSchema, diff --git a/yarn.lock b/yarn.lock index 30a58ad..67d7ee7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4277,7 +4277,7 @@ yoctocolors-cjs@^2.1.2: resolved "https://registry.yarnpkg.com/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz#f4b905a840a37506813a7acaa28febe97767a242" integrity sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA== -zod@^3.24.4: +zod@^3.25.67: version "3.25.67" resolved "https://registry.yarnpkg.com/zod/-/zod-3.25.67.tgz#62987e4078e2ab0f63b491ef0c4f33df24236da8" integrity sha512-idA2YXwpCdqUSKRCACDE6ItZD9TZzy3OZMtpfLoh6oPR47lipysRrJfjzMqFxQ3uJuUPyUeWe1r9vLH33xO/Qw==