@@ -14,24 +14,6 @@ export type TransportOptions = {
1414 url ?: string ;
1515} ;
1616
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-
3517function createStdioTransport ( options : TransportOptions ) : Transport {
3618 let args : string [ ] = [ ] ;
3719
@@ -75,12 +57,18 @@ export function createTransport(options: TransportOptions): Transport {
7557 return createStdioTransport ( options ) ;
7658 }
7759
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+
7866 if ( transportType === "sse" ) {
79- return createSSETransport ( options ) ;
67+ return new SSEClientTransport ( url ) ;
8068 }
8169
8270 if ( transportType === "http" ) {
83- return createHTTPTransport ( options ) ;
71+ return new StreamableHTTPClientTransport ( url ) ;
8472 }
8573
8674 throw new Error ( `Unsupported transport type: ${ transportType } ` ) ;
0 commit comments