refactor: move the schema source modules into @modelcontextprotocol/core (#2477)
This commit is contained in:
parent
7c49b47fb3
commit
8e1d2e92b1
3 changed files with 3597 additions and 2914 deletions
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
shape: how-to
|
||||
---
|
||||
|
||||
# Wire schemas
|
||||
|
||||
`@modelcontextprotocol/core` exports the **wire schemas** — the exact Zod constants the SDK validates protocol and OAuth payloads against — for code that holds raw JSON instead of SDK objects.
|
||||
|
|
@ -56,7 +57,7 @@ These are the `*Schema` constants v1 exported from `@modelcontextprotocol/sdk/ty
|
|||
|
||||
If you build with `McpServer` or `Client`, skip this package: [tools](../servers/tools.md) arrive in your handler already validated, and [tool calls](../clients/calling.md) come back as typed results. Reach for `@modelcontextprotocol/core` when nothing stands between you and the JSON — gateways, proxies, test harnesses, [worker fleets](./gateway.md).
|
||||
|
||||
Install it separately (`npm install @modelcontextprotocol/core`) — `@modelcontextprotocol/server` and `@modelcontextprotocol/client` keep a Zod-free public surface and never depend on it. The package is runtime-neutral; `zod` is its only dependency.
|
||||
`@modelcontextprotocol/server` and `@modelcontextprotocol/client` keep a Zod-free public surface, but they resolve their shared schema graph from this package at runtime, so it already arrives transitively in your tree. Add it to your own `dependencies` (`npm install @modelcontextprotocol/core`) when you import from it directly. The package is runtime-neutral; `zod` is its only dependency.
|
||||
|
||||
## Pick the schema for the message you hold
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ Four adapters exist: `@modelcontextprotocol/node` for Node's built-in `http` ser
|
|||
|
||||
## Reach for `core` only to validate raw wire JSON
|
||||
|
||||
`@modelcontextprotocol/core` exports the Zod schema constants the SDK validates protocol payloads against, for code that handles raw JSON-RPC payloads itself — gateways, proxies, log pipelines. Neither `server` nor `client` exports a Zod schema, and the matching TypeScript types ship with both, so if you only call `registerTool` and `callTool` you never install it. [Wire schemas](../advanced/wire-schemas.md) is the how-to.
|
||||
`@modelcontextprotocol/core` exports the Zod schema constants the SDK validates protocol payloads against, for code that handles raw JSON-RPC payloads itself — gateways, proxies, log pipelines. Neither `server` nor `client` exports a Zod schema, and the matching TypeScript types ship with both, so if you only call `registerTool` and `callTool` you never import it directly — it arrives transitively, since `server` and `client` resolve their shared schema graph from it at runtime. [Wire schemas](../advanced/wire-schemas.md) is the how-to.
|
||||
|
||||
## Leave `server-legacy` and `codemod` to the migration guide
|
||||
|
||||
|
|
|
|||
|
|
@ -848,7 +848,7 @@ hierarchy also exposes the same check as an explicit static guard
|
|||
TypeScript — use whichever style your codebase prefers; both read the same brand.
|
||||
Fine print (applies equally to `instanceof` and `isInstance`):
|
||||
|
||||
- **Version skew** — matching needs *both* copies at a brand-aware release; against an
|
||||
- **Version skew** — matching needs _both_ copies at a brand-aware release; against an
|
||||
older copy, behavior degrades to plain prototype `instanceof` (false across bundles).
|
||||
During mixed-version rollouts, recognize errors without class identity: match
|
||||
`error.name` plus the class's discriminant field (`code`, `status`), or reconstruct
|
||||
|
|
@ -1325,8 +1325,9 @@ if (CallToolResultSchema.safeParse(value).success) { ... }
|
|||
|
||||
`@modelcontextprotocol/core` is the canonical home for the spec's Zod schema constants
|
||||
(and the OAuth/OpenID metadata schemas). It is runtime-neutral (its only dependency is
|
||||
`zod`) and is **not** required by `client` / `server` — install it only if you import the
|
||||
raw schemas directly.
|
||||
`zod`) and arrives transitively as the shared runtime schema graph of `client` /
|
||||
`server` — add it to your own `dependencies` only when you import the raw schemas
|
||||
directly.
|
||||
|
||||
If you would rather keep your project Zod-free, the **`isSpecType` / `specTypeSchemas`**
|
||||
alternatives are exported from `@modelcontextprotocol/client` and `…/server`:
|
||||
|
|
|
|||
Loading…
Reference in a new issue