Skip to content

Commit 54c18d7

Browse files
committed
Bundle workerd JSON schema validator in server shim
1 parent bd67be3 commit 54c18d7

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server": patch
3+
---
4+
5+
Bundle the workerd/browser JSON Schema validator dependency into the server package's workerd shim output. Workers consumers no longer need to install `@cfworker/json-schema` separately when conditional exports select the edge-safe shim, while Node consumers continue to resolve the Node shim and do not add the validator to the Node runtime path.

packages/server/test/server/barrelClean.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { beforeAll, describe, expect, test } from 'vitest';
88
const pkgDir = join(dirname(fileURLToPath(import.meta.url)), '../..');
99
const distDir = join(pkgDir, 'dist');
1010
const NODE_ONLY = /\b(child_process|cross-spawn|node:stream|node:child_process)\b/;
11+
const CFWORKER_JSON_SCHEMA_IMPORT = /from\s+["']@cfworker\/json-schema["']/;
1112

1213
function chunkImportsOf(entryPath: string): string[] {
1314
const visited = new Set<string>();
@@ -53,4 +54,15 @@ describe('@modelcontextprotocol/server root entry is browser-safe', () => {
5354
const stdio = readFileSync(join(distDir, 'stdio.mjs'), 'utf8');
5455
expect(stdio).toMatch(/\bStdioServerTransport\b/);
5556
});
57+
58+
test('workerd shim vendors @cfworker/json-schema instead of requiring consumers to install it', () => {
59+
const workerdShim = readFileSync(join(distDir, 'shimsWorkerd.mjs'), 'utf8');
60+
expect(workerdShim).not.toMatch(CFWORKER_JSON_SCHEMA_IMPORT);
61+
62+
for (const chunk of chunkImportsOf(join(distDir, 'shimsWorkerd.mjs'))) {
63+
expect({ chunk, content: readFileSync(chunk, 'utf8') }).not.toEqual(
64+
expect.objectContaining({ content: expect.stringMatching(CFWORKER_JSON_SCHEMA_IMPORT) })
65+
);
66+
}
67+
});
5668
});

packages/server/tsdown.config.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ export default defineConfig({
3131
}
3232
}
3333
},
34-
// 5. Vendoring Strategy - Bundle the code for this specific package into the output,
35-
// but treat all other dependencies as external (require/import).
36-
noExternal: ['@modelcontextprotocol/core'],
34+
// 5. Vendoring Strategy - Bundle this package's core implementation into the output,
35+
// but treat most dependencies as external (require/import).
36+
//
37+
// The workerd/browser `_shims` entry defaults JSON Schema validation to
38+
// CfWorkerJsonSchemaValidator. Bundle @cfworker/json-schema into that shim's chunk so
39+
// Workers consumers get the edge-safe default automatically when conditional exports select
40+
// the workerd/browser shim. Node consumers still resolve `_shims` to shimsNode and the root
41+
// entry only imports `_shims` as a self-reference, so this does not add @cfworker/json-schema
42+
// to the Node runtime path.
43+
noExternal: ['@modelcontextprotocol/core', '@cfworker/json-schema'],
3744

3845
// 6. External packages - keep self-reference imports external for runtime resolution
3946
external: ['@modelcontextprotocol/server/_shims']

0 commit comments

Comments
 (0)