Skip to content

Commit cb7c4e5

Browse files
docs: update prose now that Protocol is concrete and public
1 parent a8605ca commit cb7c4e5

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The SDK is organized into three main layers:
6767
The SDK has a two-layer export structure to separate internal code from the public API:
6868

6969
- **`@modelcontextprotocol/core`** (main entry, `packages/core/src/index.ts`) — Internal barrel. Exports everything (including Zod schemas, Protocol class, stdio utils). Only consumed by sibling packages within the monorepo (`private: true`).
70-
- **`@modelcontextprotocol/core/public`** (`packages/core/src/exports/public/index.ts`) — Curated public API. Exports only TypeScript types, error classes, constants, and guards. Re-exported by client and server packages.
70+
- **`@modelcontextprotocol/core/public`** (`packages/core/src/exports/public/index.ts`) — Curated public API. Exports TypeScript types, error classes, constants, guards, and the `Protocol` class. Re-exported by client and server packages.
7171
- **`@modelcontextprotocol/client`** and **`@modelcontextprotocol/server`** (`packages/*/src/index.ts`) — Final public surface. Package-specific exports (named explicitly) plus re-exports from `core/public`.
7272

7373
When modifying exports:

packages/core/src/exports/public/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* This module defines the stable, public-facing API surface. Client and server
55
* packages re-export from here so that end users only see supported symbols.
66
*
7-
* Internal utilities (Protocol class, stdio parsing, schema helpers, etc.)
8-
* remain available via the internal barrel (@modelcontextprotocol/core) for
9-
* use by client/server packages.
7+
* Internal utilities (stdio parsing, schema helpers, etc.) remain available via
8+
* the internal barrel (@modelcontextprotocol/core) for use by client/server
9+
* packages.
1010
*/
1111

1212
// Auth error classes
@@ -38,7 +38,7 @@ export { checkResourceAllowed, resourceUrlFromServerUrl } from '../../shared/aut
3838
// Metadata utilities
3939
export { getDisplayName } from '../../shared/metadataUtils.js';
4040

41-
// Protocol class (abstract — subclass for custom vocabularies) + types. NOT mergeCapabilities.
41+
// Protocol class (concrete; subclass for custom vocabularies via SpecT) + types. NOT mergeCapabilities.
4242
export type {
4343
BaseContext,
4444
ClientContext,

packages/core/src/shared/protocol.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ type TimeoutInfo = {
310310
*
311311
* Supplying a concrete `ProtocolSpec` as `Protocol`'s second type argument gives method-name
312312
* autocomplete and params/result correlation on the typed overloads of `setRequestHandler`
313-
* and `setNotificationHandler`. The default leaves them string-keyed and untyped.
313+
* and `setNotificationHandler`. `Protocol` defaults to {@linkcode McpSpec}; using the bare
314+
* `ProtocolSpec` type leaves methods string-keyed and untyped.
314315
*/
315316
export type ProtocolSpec = {
316317
requests?: Record<string, { params?: unknown; result: unknown }>;
@@ -1082,8 +1083,9 @@ export abstract class Protocol<ContextT extends BaseContext = BaseContext, SpecT
10821083
* Any method string; the supplied schema validates incoming `params`. Absent or undefined
10831084
* `params` are normalized to `{}` (after stripping `_meta`) before validation, so for
10841085
* no-params methods use `z.object({})`. `paramsSchema` may be any Standard Schema (Zod,
1085-
* Valibot, ArkType, etc.). When `method` is listed in this instance's
1086-
* {@linkcode ProtocolSpec}, params and result types are inferred from `SpecT`.
1086+
* Valibot, ArkType, etc.). The handler's `params` type is inferred from the passed
1087+
* `paramsSchema`; when `method` is listed in this instance's {@linkcode ProtocolSpec},
1088+
* `paramsSchema`'s input and the handler's result type are constrained by `SpecT`.
10871089
* - **Zod schema** — `setRequestHandler(RequestZodSchema, (request, ctx) => …)`. The method
10881090
* name is read from the schema's `method` literal; the handler receives the parsed request.
10891091
*/
@@ -1193,8 +1195,9 @@ export abstract class Protocol<ContextT extends BaseContext = BaseContext, SpecT
11931195
* Mirrors {@linkcode setRequestHandler}: a two-arg spec-method form (handler receives the full
11941196
* notification object), a three-arg form with a `paramsSchema` (handler receives validated
11951197
* `params`), and a Zod-schema form (method read from the schema's `method` literal). When the
1196-
* three-arg form's `method` is listed in this instance's {@linkcode ProtocolSpec}, the params
1197-
* type is inferred from `SpecT`.
1198+
* three-arg form's `method` is listed in this instance's {@linkcode ProtocolSpec},
1199+
* `paramsSchema`'s input is constrained by `SpecT`; the handler's `params` type is always
1200+
* inferred from the passed schema.
11981201
*/
11991202
setNotificationHandler<K extends SpecNotifications<SpecT>, P extends StandardSchemaV1<_Notifications<SpecT>[K]['params']>>(
12001203
method: K,

0 commit comments

Comments
 (0)