Skip to content

Commit 045c62a

Browse files
feat!: remove WebSocketClientTransport (#1783)
Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
1 parent 4aec5f7 commit 045c62a

File tree

9 files changed

+28
-120
lines changed

9 files changed

+28
-120
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/client': major
3+
---
4+
5+
Remove `WebSocketClientTransport`. WebSocket is not a spec-defined transport; use stdio or Streamable HTTP. The `Transport` interface remains exported for custom implementations. See #142.

docs/migration-SKILL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Replace all `@modelcontextprotocol/sdk/...` imports using this table.
4343
| `@modelcontextprotocol/sdk/client/streamableHttp.js` | `@modelcontextprotocol/client` |
4444
| `@modelcontextprotocol/sdk/client/sse.js` | `@modelcontextprotocol/client` |
4545
| `@modelcontextprotocol/sdk/client/stdio.js` | `@modelcontextprotocol/client` |
46-
| `@modelcontextprotocol/sdk/client/websocket.js` | `@modelcontextprotocol/client` |
46+
| `@modelcontextprotocol/sdk/client/websocket.js` | REMOVED (use Streamable HTTP or stdio; implement `Transport` for custom needs) |
4747

4848
### Server imports
4949

@@ -96,6 +96,7 @@ Notes:
9696
| `ErrorCode.RequestTimeout` | `SdkErrorCode.RequestTimeout` |
9797
| `ErrorCode.ConnectionClosed` | `SdkErrorCode.ConnectionClosed` |
9898
| `StreamableHTTPError` | REMOVED (use `SdkError` with `SdkErrorCode.ClientHttp*`) |
99+
| `WebSocketClientTransport` | REMOVED (use `StreamableHTTPClientTransport` or `StdioClientTransport`) |
99100

100101
All other symbols from `@modelcontextprotocol/sdk/types.js` retain their original names (e.g., `CallToolResultSchema`, `ListToolsResultSchema`, etc.).
101102

docs/migration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ const transport = new NodeStreamableHTTPServerTransport({ sessionIdGenerator: ()
110110

111111
The SSE transport has been removed from the server. Servers should migrate to Streamable HTTP. The client-side SSE transport remains available for connecting to legacy SSE servers.
112112

113+
### `WebSocketClientTransport` removed
114+
115+
`WebSocketClientTransport` has been removed. WebSocket is not a spec-defined MCP transport, and keeping it in the SDK encouraged transport proliferation without a conformance baseline.
116+
117+
Use `StdioClientTransport` for local servers or `StreamableHTTPClientTransport` for remote servers. If you need WebSocket for a custom deployment, implement the `Transport` interface directly — it remains exported from `@modelcontextprotocol/client`.
118+
119+
**Before (v1):**
120+
121+
```typescript
122+
import { WebSocketClientTransport } from '@modelcontextprotocol/sdk/client/websocket.js';
123+
const transport = new WebSocketClientTransport(new URL('ws://localhost:3000'));
124+
```
125+
126+
**After (v2):**
127+
128+
```typescript
129+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
130+
const transport = new StreamableHTTPClientTransport(new URL('http://localhost:3000/mcp'));
131+
```
132+
113133
### Server auth removed
114134

115135
Server-side OAuth/auth has been removed entirely from the SDK. This includes `mcpAuthRouter`, `OAuthServerProvider`, `OAuthTokenVerifier`, `requireBearerAuth`, `authenticateClient`, `ProxyOAuthServerProvider`, `allowedMethods`, and all associated types.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"@types/express-serve-static-core": "catalog:devTools",
6161
"@types/node": "^24.10.1",
6262
"@types/supertest": "catalog:devTools",
63-
"@types/ws": "catalog:devTools",
6463
"@typescript/native-preview": "catalog:devTools",
6564
"eslint": "catalog:devTools",
6665
"eslint-config-prettier": "catalog:devTools",
@@ -75,7 +74,6 @@
7574
"typescript": "catalog:devTools",
7675
"typescript-eslint": "catalog:devTools",
7776
"vitest": "catalog:devTools",
78-
"ws": "catalog:devTools",
7977
"zod": "catalog:runtimeShared"
8078
},
8179
"resolutions": {

packages/client/src/client/websocket.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

packages/client/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export type {
6969
StreamableHTTPReconnectionOptions
7070
} from './client/streamableHttp.js';
7171
export { StreamableHTTPClientTransport } from './client/streamableHttp.js';
72-
export { WebSocketClientTransport } from './client/websocket.js';
7372

7473
// experimental exports
7574
export { ExperimentalClientTasks } from './experimental/tasks/client.js';

pnpm-lock.yaml

Lines changed: 0 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ catalogs:
1818
'@types/express': ^5.0.6
1919
'@types/express-serve-static-core': ^5.1.0
2020
'@types/supertest': ^6.0.2
21-
'@types/ws': ^8.5.12
2221
'@typescript/native-preview': ^7.0.0-dev.20251217.1
2322
eslint: ^9.39.2
2423
eslint-config-prettier: ^10.1.8
@@ -32,7 +31,6 @@ catalogs:
3231
typescript-eslint: ^8.48.1
3332
vite-tsconfig-paths: ^5.1.4
3433
vitest: ^4.0.15
35-
ws: ^8.18.0
3634
runtimeClientOnly:
3735
cross-spawn: ^7.0.5
3836
eventsource: ^3.0.2

scripts/cli.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import WebSocket from 'ws';
2-
3-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4-
(global as any).WebSocket = WebSocket;
5-
61
import express from 'express';
72
import { Client } from '../src/client/index.js';
83
import { SSEClientTransport } from '../src/client/sse.js';
94
import { StdioClientTransport } from '../src/client/stdio.js';
10-
import { WebSocketClientTransport } from '../src/client/websocket.js';
115
import { Server } from '../src/server/index.js';
126
import { SSEServerTransport } from '../src/server/sse.js';
137
import { StdioServerTransport } from '../src/server/stdio.js';
@@ -38,7 +32,7 @@ async function runClient(url_or_command: string, args: string[]) {
3832
if (url?.protocol === 'http:' || url?.protocol === 'https:') {
3933
clientTransport = new SSEClientTransport(new URL(url_or_command));
4034
} else if (url?.protocol === 'ws:' || url?.protocol === 'wss:') {
41-
clientTransport = new WebSocketClientTransport(new URL(url_or_command));
35+
throw new Error('WebSocket URLs are no longer supported. Use http(s) or stdio instead.');
4236
} else {
4337
clientTransport = new StdioClientTransport({
4438
command: url_or_command,

0 commit comments

Comments
 (0)