perf: add preloadSchemas() and warm wire schemas eagerly on workerd (#2483)

This commit is contained in:
Felix Weinberger 2026-07-13 17:27:22 +01:00 • committed by GitHub
commit 3f07a325c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 550 additions and 14 deletions

View file

@ -106,5 +106,11 @@ export { fromJsonSchema } from './fromJsonSchema';
export type { InputRequiredOptions } from '@modelcontextprotocol/core-internal';
export { withInputRequired } from '@modelcontextprotocol/core-internal';
// Explicit opt-in to eager wire-schema construction, for platforms that bill
// request CPU but not module evaluation (isolate-based edge/serverless
// runtimes). The package's workerd build calls it automatically at module
// scope; other builds stay lazy unless the application calls it itself.
export { preloadSchemas } from '@modelcontextprotocol/core-internal';
// re-export curated public API from core
export * from '@modelcontextprotocol/core-internal/public';

View file

@ -3,8 +3,17 @@
*
* This file is selected via package.json export conditions when running in workerd.
*/
import { preloadSchemas } from '@modelcontextprotocol/core-internal';
export { CfWorkerJsonSchemaValidator as DefaultJsonSchemaValidator } from '@modelcontextprotocol/core-internal/validators/cfWorker';
// Platform asymmetry: isolate platforms like workerd evaluate module scope
// during deployment/isolate warm-up, outside any request's billed CPU, while
// lazy construction would land inside the first request each fresh isolate
// serves. Node and browser shims stay lazy — there, module evaluation is
// process/page startup and boot latency is the cost that matters.
preloadSchemas();
/**
* Whether `fetch()` may throw `TypeError` due to CORS. CORS is a browser-only concept —
* in Cloudflare Workers, a `TypeError` from `fetch` is always a real network/configuration