Skip to content

Commit efc8f32

Browse files
authored
Merge branch 'main' into ci-test-cli
2 parents b84e527 + 6d4a664 commit efc8f32

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

cli/scripts/cli-tests.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ async function runTests() {
680680
// Test 26: HTTP transport with explicit --transport http flag
681681
await runBasicTest(
682682
"http_transport_with_explicit_flag",
683-
"http://127.0.0.1:3001",
683+
"http://127.0.0.1:3001/mcp",
684684
"--transport",
685685
"http",
686686
"--cli",
@@ -710,6 +710,26 @@ async function runTests() {
710710
"tools/list",
711711
);
712712

713+
// Test 29: HTTP transport without URL (should fail)
714+
await runErrorTest(
715+
"http_transport_without_url",
716+
"--transport",
717+
"http",
718+
"--cli",
719+
"--method",
720+
"tools/list",
721+
);
722+
723+
// Test 30: SSE transport without URL (should fail)
724+
await runErrorTest(
725+
"sse_transport_without_url",
726+
"--transport",
727+
"sse",
728+
"--cli",
729+
"--method",
730+
"tools/list",
731+
);
732+
713733
// Kill HTTP server
714734
try {
715735
process.kill(-httpServer.pid);

cli/src/transport.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
3517
function 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

Comments
 (0)