Skip to content

Commit 7f8082b

Browse files
committed
public exports - no wildcard exports; header instructions; update CLAUDE.md
1 parent b2b1e72 commit 7f8082b

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

CLAUDE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ The SDK is organized into three main layers:
6262
- `Server` (`packages/server/src/server/server.ts`) - Server implementation extending Protocol with request handler registration
6363
- `McpServer` (`packages/server/src/server/mcp.ts`) - High-level server API with simplified resource/tool/prompt registration
6464

65+
### Public API Exports
66+
67+
The SDK has a two-layer export structure to separate internal code from the public API:
68+
69+
- **`@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.
71+
- **`@modelcontextprotocol/client`** and **`@modelcontextprotocol/server`** (`packages/*/src/index.ts`) — Final public surface. Package-specific exports (named explicitly) plus re-exports from `core/public`.
72+
73+
When modifying exports:
74+
- Use explicit named exports, not `export *`, in package `index.ts` files and `core/public`.
75+
- Adding a symbol to a package `index.ts` makes it public API — do so intentionally.
76+
- Internal helpers should stay in the core internal barrel and not be added to `core/public` or package index files.
77+
6578
### Transport System
6679

6780
Transports (`packages/core/src/shared/transport.ts`) provide the communication layer:

packages/client/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
// Client-specific exports
1+
// Public API for @modelcontextprotocol/client.
2+
//
3+
// This file defines the complete public surface. It consists of:
4+
// - Package-specific exports: listed explicitly below (named imports)
5+
// - Protocol-level types: re-exported from @modelcontextprotocol/core/public
6+
//
7+
// Any new export added here becomes public API. Use named exports, not wildcards.
8+
29
export type {
310
AddClientAuthentication,
411
AuthResult,
@@ -53,7 +60,7 @@ export { StreamableHTTPClientTransport } from './client/streamableHttp.js';
5360
export { WebSocketClientTransport } from './client/websocket.js';
5461

5562
// experimental exports
56-
export * from './experimental/index.js';
63+
export { ExperimentalClientTasks } from './experimental/tasks/client.js';
5764

5865
// re-export curated public API from core
5966
export * from '@modelcontextprotocol/core/public';

packages/core/src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Internal barrel — re-exports everything for use within the SDK packages.
2-
// External consumers should use exports/public/index.ts instead for a curated public API.
2+
// The public API is defined in @modelcontextprotocol/core/public (see exports/public/index.ts).
33
export * from './constants.js';
44
export * from './enums.js';
55
export * from './errors.js';

packages/server/src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
// Server-specific exports
1+
// Public API for @modelcontextprotocol/server.
2+
//
3+
// This file defines the complete public surface. It consists of:
4+
// - Package-specific exports: listed explicitly below (named imports)
5+
// - Protocol-level types: re-exported from @modelcontextprotocol/core/public
6+
//
7+
// Any new export added here becomes public API. Use named exports, not wildcards.
8+
29
export type { CompletableSchema, CompleteCallback } from './server/completable.js';
310
export { completable, isCompletable } from './server/completable.js';
411
export type {
@@ -32,7 +39,9 @@ export type {
3239
export { WebStandardStreamableHTTPServerTransport } from './server/streamableHttp.js';
3340

3441
// experimental exports
35-
export * from './experimental/index.js';
42+
export type { CreateTaskRequestHandler, TaskRequestHandler, ToolTaskHandler } from './experimental/tasks/interfaces.js';
43+
export { ExperimentalMcpServerTasks } from './experimental/tasks/mcpServer.js';
44+
export { ExperimentalServerTasks } from './experimental/tasks/server.js';
3645

3746
// re-export curated public API from core
3847
export * from '@modelcontextprotocol/core/public';

0 commit comments

Comments
 (0)