v2: limit public exports#1680
Open
KKonstantinov wants to merge 5 commits intomodelcontextprotocol:mainfrom
Open
v2: limit public exports#1680KKonstantinov wants to merge 5 commits intomodelcontextprotocol:mainfrom
v2: limit public exports#1680KKonstantinov wants to merge 5 commits intomodelcontextprotocol:mainfrom
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
v2: (draft) limit public exportsv2: limit public exports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Limit public API exports to a curated surface, hiding internal implementation details (Zod schemas, Protocol class, stdio internals, etc.) from end users.
Motivation and Context
The SDK currently re-exports everything from
@modelcontextprotocol/corethrough@modelcontextprotocol/clientand@modelcontextprotocol/servervia blanketexport *statements. This leaks internal implementation details into the public API surface — Zod schema objects, the abstractProtocolclass, internal helpers likenormalizeHeadersandmergeCapabilities, and theInMemoryTransporttest utility.This PR introduces a two-tier export system:
@modelcontextprotocol/core): Fullexport *for use by client/server packages internally@modelcontextprotocol/core/public): Curated named exports for end users, re-exported by@modelcontextprotocol/clientand@modelcontextprotocol/serverAdditionally, the monolithic
types.tsfile (~2800 lines) is split into focused modules:schemas.ts(Zod schema definitions only),types.ts(TypeScript type aliases and standalone interfaces),constants.ts,enums.ts,errors.ts, andguards.ts.How Has This Been Tested?
pnpm typecheck:all— passes across all packagespnpm lint:all— passes across all packagespnpm test:all— all 386 tests passpnpm check:all— passes (includes typecheck + lint +docs:checkwith 0 warnings)Breaking Changes
Yes — consumers who imported internal symbols that are no longer part of the public API will need to update their code:
ToolSchema,ResourceSchema, etc.) are no longer exported publicly. TypeScript types derived from them (Tool,Resource, etc.) remain available.InMemoryTransportis no longer exported publicly (test utility only).Protocolclass andmergeCapabilitiesare no longer exported publicly (internal abstractions).normalizeHeaders, stdio parsing, etc.) are no longer exported publicly.Types of changes
Checklist
Additional context
Architecture
The new
@modelcontextprotocol/core/publicsubpath export (packages/core/src/exports/public/index.ts) contains explicit named exports for each public symbol, organized by category. Client and server barrels now useexport * from '@modelcontextprotocol/core/public'instead ofexport * from '@modelcontextprotocol/core', combined with explicit named exports for their own symbols.Types split
The original
packages/core/src/types/types.tshas been split into:schemas.tstypes.tsInfer<typeof Schema>), standalone interfaces, protocol type mapsconstants.tsenums.tsProtocolErrorCodeenumerrors.tsProtocolErrorandUrlElicitationRequiredErrorclassesguards.tsisJSONRPCRequest, etc.)index.tsAn internal barrel (
types/index.ts) re-exports everything for internal package use. The public barrel (exports/public/index.ts) exports fromtypes/types.tsbut NOT fromtypes/schemas.ts, keeping Zod runtime objects internal.