Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/client-droppable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/client': patch
---

esbuild, webpack and Bun can again drop `Client` from bundles that do not use it. Since 2.4.0 they kept it, together with the JSON Schema validator. No runtime change.
16 changes: 7 additions & 9 deletions packages/client/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ const LIST_CHANGED_EVICTIONS: Readonly<Record<string, readonly string[]>> = {

const DEFAULT_LIST_MAX_PAGES = 64;

// Package-internal (not exported from the package): what the `ext/` clients share with Client. Set in Client's static block.
export const clientInternals = {} as {
// Package-internal (not exported from the package): what the `ext/` clients share with Client. Not a static block, which would keep Client in every bundle.
export const clientInternals: {
enforceStrictCapabilities(client: Client): boolean;
logger(client: Client): SdkLogger;
walkPages<R extends { nextCursor?: string }>(
Expand All @@ -478,6 +478,11 @@ export const clientInternals = {} as {
params: ReadResourceRequest['params'],
options?: CacheableRequestOptions
): Promise<{ result: ReadResourceResult; cached: boolean }>;
} = {
enforceStrictCapabilities: client => client['_enforceStrictCapabilities'],
logger: client => client['_logger'],
walkPages: (client, method, fetchPage, items) => client['_walkPages'](method, fetchPage, items),
readResource: (client, params, options) => client['_readResource'](params, options)
};

/**
Expand Down Expand Up @@ -618,13 +623,6 @@ export class Client extends Protocol<ClientContext> {
/** Backing store for {@linkcode getDiscoverResult}. Per-connection. */
private _discoverResult?: DiscoverResult;

static {
clientInternals.enforceStrictCapabilities = client => client._enforceStrictCapabilities;
clientInternals.logger = client => client._logger;
clientInternals.walkPages = (client, method, fetchPage, items) => client._walkPages(method, fetchPage, items);
clientInternals.readResource = (client, params, options) => client._readResource(params, options);
}

/**
* Clears every per-connection field in one place. Called at the start of
* each fresh (non-resuming) connect and from `close()`, so a stale
Expand Down
4 changes: 4 additions & 0 deletions packages/client/test/client/treeShaking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ describe('tree shaking (built dist, bundled with esbuild)', () => {
expect(bundle).not.toMatch(/cfWorkerProvider|@opentelemetry\/api/);
});

test('Client is dropped on its own merits, not only because of the chunk it lands in', async () => {
expect(await bundleUsing('Protocol', { ignoreAnnotations: true })).not.toMatch(/\bClient = class\b/);
});

test('a browser app that uses Client still gets its JSON Schema validator', async () => {
expect(await bundleUsing('Client')).toMatch(/\bCfWorkerJsonSchemaValidator = class\b/);
});
Expand Down
Loading