-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(client,server): move stdio transports to ./stdio subpath export #1871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
felixweinberger
wants to merge
6
commits into
main
Choose a base branch
from
fweinberger/browser-stdio-conditional-export
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
46fe6d2
refactor(client,server): move stdio transports to ./stdio subpath export
felixweinberger 35b3755
test: make barrelClean chunk scan transitive (BFS) and CI-safe; map /…
felixweinberger dc84940
fix: add /stdio tsconfig paths in examples/{client,server} and test/i…
felixweinberger c2b85db
test(server): assert StdioServerTransport absent from root barrel; cl…
felixweinberger a4a6100
Merge branch 'main' into fweinberger/browser-stdio-conditional-export
KKonstantinov 86a6331
fix: address review comments — migration table shared/stdio row, serv…
felixweinberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@modelcontextprotocol/client': minor | ||
| '@modelcontextprotocol/server': minor | ||
| --- | ||
|
|
||
| Move stdio transports to a `./stdio` subpath export. Import `StdioClientTransport`, `getDefaultEnvironment`, `DEFAULT_INHERITED_ENV_VARS`, and `StdioServerParameters` from `@modelcontextprotocol/client/stdio`, and `StdioServerTransport` from `@modelcontextprotocol/server/stdio`. The package root entries no longer pull in `node:child_process`, `node:stream`, or `cross-spawn`, fixing bundling for browser and Cloudflare Workers targets. Node.js, Bun, and Deno consumers update the import path; runtime behavior is unchanged. |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Subpath entry for the stdio client transport. | ||
| // | ||
| // Exported separately from the root entry so that bundling `@modelcontextprotocol/client` for browser or | ||
| // Cloudflare Workers targets does not pull in `node:child_process`, `node:stream`, or `cross-spawn`. Import | ||
| // from `@modelcontextprotocol/client/stdio` only in process-spawning runtimes (Node.js, Bun, Deno). | ||
|
|
||
| export type { StdioServerParameters } from './client/stdio.js'; | ||
| export { DEFAULT_INHERITED_ENV_VARS, getDefaultEnvironment, StdioClientTransport } from './client/stdio.js'; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { execFileSync } from 'node:child_process'; | ||
| import { existsSync, readFileSync } from 'node:fs'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| import { beforeAll, describe, expect, test } from 'vitest'; | ||
|
|
||
| const pkgDir = join(dirname(fileURLToPath(import.meta.url)), '../..'); | ||
| const distDir = join(pkgDir, 'dist'); | ||
| const NODE_ONLY = /\b(child_process|cross-spawn|node:stream|node:child_process)\b/; | ||
|
|
||
| function chunkImportsOf(entryPath: string): string[] { | ||
| const visited = new Set<string>(); | ||
| const queue = [entryPath]; | ||
| while (queue.length > 0) { | ||
| const file = queue.shift()!; | ||
| if (visited.has(file)) continue; | ||
| visited.add(file); | ||
| const src = readFileSync(file, 'utf8'); | ||
| for (const m of src.matchAll(/from\s+["']\.\/(.+?\.mjs)["']/g)) { | ||
| queue.push(join(dirname(file), m[1]!)); | ||
| } | ||
| } | ||
| visited.delete(entryPath); | ||
| return [...visited]; | ||
| } | ||
|
|
||
| describe('@modelcontextprotocol/client root entry is browser-safe', () => { | ||
| beforeAll(() => { | ||
| if (!existsSync(join(distDir, 'index.mjs')) || !existsSync(join(distDir, 'stdio.mjs'))) { | ||
| execFileSync('pnpm', ['build'], { cwd: pkgDir, stdio: 'inherit' }); | ||
| } | ||
| }, 60_000); | ||
|
|
||
| test('dist/index.mjs contains no process-spawning runtime imports', () => { | ||
| const entry = join(distDir, 'index.mjs'); | ||
| expect(readFileSync(entry, 'utf8')).not.toMatch(NODE_ONLY); | ||
| }); | ||
|
|
||
| test('chunks transitively imported by dist/index.mjs contain no process-spawning runtime imports', () => { | ||
| const entry = join(distDir, 'index.mjs'); | ||
| for (const chunk of chunkImportsOf(entry)) { | ||
| expect({ chunk, content: readFileSync(chunk, 'utf8') }).not.toEqual( | ||
| expect.objectContaining({ content: expect.stringMatching(NODE_ONLY) }) | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| test('dist/stdio.mjs exists and exports StdioClientTransport', () => { | ||
| const stdio = readFileSync(join(distDir, 'stdio.mjs'), 'utf8'); | ||
| expect(stdio).toMatch(/\bStdioClientTransport\b/); | ||
| expect(stdio).toMatch(/\bgetDefaultEnvironment\b/); | ||
| expect(stdio).toMatch(/\bDEFAULT_INHERITED_ENV_VARS\b/); | ||
| }); | ||
| }); |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Subpath entry for the stdio server transport. | ||
| // | ||
| // Exported separately from the root entry to keep `StdioServerTransport` out of the default bundle | ||
| // surface — server stdio has only type-level Node imports, but matching the client's `./stdio` | ||
| // subpath gives consumers a consistent shape across packages. Import from | ||
| // `@modelcontextprotocol/server/stdio` only in process-stdio runtimes (Node.js, Bun, Deno). | ||
|
|
||
| export { StdioServerTransport } from './server/stdio.js'; | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.