Skip to content

Commit 255c06f

Browse files
committed
Made both stdio and http test servers fully composable, cleaned up types, terminology, and usage.
1 parent 5ee7d77 commit 255c06f

File tree

9 files changed

+616
-437
lines changed

9 files changed

+616
-437
lines changed

cli/__tests__/cli.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import {
1111
createTestConfig,
1212
createInvalidConfig,
1313
deleteConfigFile,
14-
getTestMcpServerCommand,
1514
} from "./helpers/fixtures.js";
15+
import { getTestMcpServerCommand } from "./helpers/test-server-stdio.js";
16+
import { createTestServerHttp } from "./helpers/test-server-http.js";
1617
import {
17-
createInstrumentedServer,
1818
createEchoTool,
19-
} from "./helpers/instrumented-server.js";
19+
createTestServerInfo,
20+
} from "./helpers/test-fixtures.js";
2021

2122
describe("CLI Tests", () => {
2223
describe("Basic CLI Mode", () => {
@@ -363,7 +364,10 @@ describe("CLI Tests", () => {
363364

364365
describe("Logging Options", () => {
365366
it("should set log level", async () => {
366-
const server = createInstrumentedServer({});
367+
const server = createTestServerHttp({
368+
serverInfo: createTestServerInfo(),
369+
logging: true,
370+
});
367371

368372
try {
369373
const port = await server.start("http");
@@ -731,7 +735,8 @@ describe("CLI Tests", () => {
731735

732736
describe("HTTP Transport", () => {
733737
it("should infer HTTP transport from URL ending with /mcp", async () => {
734-
const server = createInstrumentedServer({
738+
const server = createTestServerHttp({
739+
serverInfo: createTestServerInfo(),
735740
tools: [createEchoTool()],
736741
});
737742

@@ -757,7 +762,8 @@ describe("CLI Tests", () => {
757762
});
758763

759764
it("should work with explicit --transport http flag", async () => {
760-
const server = createInstrumentedServer({
765+
const server = createTestServerHttp({
766+
serverInfo: createTestServerInfo(),
761767
tools: [createEchoTool()],
762768
});
763769

@@ -785,7 +791,8 @@ describe("CLI Tests", () => {
785791
});
786792

787793
it("should work with explicit transport flag and URL suffix", async () => {
788-
const server = createInstrumentedServer({
794+
const server = createTestServerHttp({
795+
serverInfo: createTestServerInfo(),
789796
tools: [createEchoTool()],
790797
});
791798

@@ -813,7 +820,8 @@ describe("CLI Tests", () => {
813820
});
814821

815822
it("should fail when SSE transport is given to HTTP server", async () => {
816-
const server = createInstrumentedServer({
823+
const server = createTestServerHttp({
824+
serverInfo: createTestServerInfo(),
817825
tools: [createEchoTool()],
818826
});
819827

cli/__tests__/headers.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import {
55
expectOutputContains,
66
expectCliSuccess,
77
} from "./helpers/assertions.js";
8+
import { createTestServerHttp } from "./helpers/test-server-http.js";
89
import {
9-
createInstrumentedServer,
1010
createEchoTool,
11-
} from "./helpers/instrumented-server.js";
11+
createTestServerInfo,
12+
} from "./helpers/test-fixtures.js";
1213

1314
describe("Header Parsing and Validation", () => {
1415
describe("Valid Headers", () => {
1516
it("should parse valid single header and send it to server", async () => {
16-
const server = createInstrumentedServer({
17+
const server = createTestServerHttp({
18+
serverInfo: createTestServerInfo(),
1719
tools: [createEchoTool()],
1820
});
1921

@@ -52,7 +54,8 @@ describe("Header Parsing and Validation", () => {
5254
});
5355

5456
it("should parse multiple headers", async () => {
55-
const server = createInstrumentedServer({
57+
const server = createTestServerHttp({
58+
serverInfo: createTestServerInfo(),
5659
tools: [createEchoTool()],
5760
});
5861

@@ -86,7 +89,8 @@ describe("Header Parsing and Validation", () => {
8689
});
8790

8891
it("should handle header with colons in value", async () => {
89-
const server = createInstrumentedServer({
92+
const server = createTestServerHttp({
93+
serverInfo: createTestServerInfo(),
9094
tools: [createEchoTool()],
9195
});
9296

@@ -119,7 +123,8 @@ describe("Header Parsing and Validation", () => {
119123
});
120124

121125
it("should handle whitespace in headers", async () => {
122-
const server = createInstrumentedServer({
126+
const server = createTestServerHttp({
127+
serverInfo: createTestServerInfo(),
123128
tools: [createEchoTool()],
124129
});
125130

cli/__tests__/helpers/fixtures.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import fs from "fs";
22
import path from "path";
33
import os from "os";
44
import crypto from "crypto";
5-
import { fileURLToPath } from "url";
6-
import { dirname } from "path";
7-
8-
const __dirname = dirname(fileURLToPath(import.meta.url));
5+
import { getTestMcpServerCommand } from "./test-server-stdio.js";
96

107
/**
118
* Sentinel value for tests that don't need a real server
@@ -90,20 +87,3 @@ export function createInvalidConfig(): string {
9087
export function deleteConfigFile(configPath: string): void {
9188
cleanupTempDir(path.dirname(configPath));
9289
}
93-
94-
/**
95-
* Get the path to the test MCP server script
96-
*/
97-
export function getTestMcpServerPath(): string {
98-
return path.resolve(__dirname, "test-mcp-server.ts");
99-
}
100-
101-
/**
102-
* Get the command and args to run the test MCP server
103-
*/
104-
export function getTestMcpServerCommand(): { command: string; args: string[] } {
105-
return {
106-
command: "tsx",
107-
args: [getTestMcpServerPath()],
108-
};
109-
}

0 commit comments

Comments
 (0)