@@ -14,24 +14,6 @@ export type TransportOptions = {
14
14
url ?: string ;
15
15
} ;
16
16
17
- function createSSETransport ( options : TransportOptions ) : Transport {
18
- const baseUrl = new URL ( options . url ?? "" ) ;
19
- const sseUrl = baseUrl . pathname . endsWith ( "/sse" )
20
- ? baseUrl
21
- : new URL ( "/sse" , baseUrl ) ;
22
-
23
- return new SSEClientTransport ( sseUrl ) ;
24
- }
25
-
26
- function createHTTPTransport ( options : TransportOptions ) : Transport {
27
- const baseUrl = new URL ( options . url ?? "" ) ;
28
- const mcpUrl = baseUrl . pathname . endsWith ( "/mcp" )
29
- ? baseUrl
30
- : new URL ( "/mcp" , baseUrl ) ;
31
-
32
- return new StreamableHTTPClientTransport ( mcpUrl ) ;
33
- }
34
-
35
17
function createStdioTransport ( options : TransportOptions ) : Transport {
36
18
let args : string [ ] = [ ] ;
37
19
@@ -75,12 +57,18 @@ export function createTransport(options: TransportOptions): Transport {
75
57
return createStdioTransport ( options ) ;
76
58
}
77
59
60
+ // If not STDIO, then it must be either SSE or HTTP.
61
+ if ( ! options . url ) {
62
+ throw new Error ( "URL must be provided for SSE or HTTP transport types." ) ;
63
+ }
64
+ const url = new URL ( options . url ) ;
65
+
78
66
if ( transportType === "sse" ) {
79
- return createSSETransport ( options ) ;
67
+ return new SSEClientTransport ( url ) ;
80
68
}
81
69
82
70
if ( transportType === "http" ) {
83
- return createHTTPTransport ( options ) ;
71
+ return new StreamableHTTPClientTransport ( url ) ;
84
72
}
85
73
86
74
throw new Error ( `Unsupported transport type: ${ transportType } ` ) ;
0 commit comments