Skip to content

Commit 606c278

Browse files
committed
clean up tests - remove mockRequestInfo
1 parent 166da76 commit 606c278

File tree

10 files changed

+47
-73
lines changed

10 files changed

+47
-73
lines changed

src/client/index.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ import {
2121
import { Transport } from "../shared/transport.js";
2222
import { Server } from "../server/index.js";
2323
import { InMemoryTransport } from "../inMemory.js";
24-
import { RequestInfo } from "../server/types/types.js";
25-
26-
const mockRequestInfo: RequestInfo = {
27-
headers: {
28-
'content-type': 'application/json',
29-
'accept': 'application/json',
30-
},
31-
};
24+
3225
/***
3326
* Test: Initialize with Matching Protocol Version
3427
*/
@@ -50,7 +43,7 @@ test("should initialize with matching protocol version", async () => {
5043
},
5144
instructions: "test instructions",
5245
},
53-
}, { requestInfo: mockRequestInfo });
46+
});
5447
}
5548
return Promise.resolve();
5649
}),
@@ -108,7 +101,7 @@ test("should initialize with supported older protocol version", async () => {
108101
version: "1.0",
109102
},
110103
},
111-
}, { requestInfo: mockRequestInfo });
104+
});
112105
}
113106
return Promise.resolve();
114107
}),
@@ -158,7 +151,7 @@ test("should reject unsupported protocol version", async () => {
158151
version: "1.0",
159152
},
160153
},
161-
}, { requestInfo: mockRequestInfo });
154+
});
162155
}
163156
return Promise.resolve();
164157
}),

src/server/index.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,11 @@ import {
1515
ListResourcesRequestSchema,
1616
ListToolsRequestSchema,
1717
SetLevelRequestSchema,
18-
ErrorCode,
18+
ErrorCode
1919
} from "../types.js";
2020
import { Transport } from "../shared/transport.js";
2121
import { InMemoryTransport } from "../inMemory.js";
2222
import { Client } from "../client/index.js";
23-
import { RequestInfo } from "./types/types.js";
24-
25-
const mockRequestInfo: RequestInfo = {
26-
headers: {
27-
'content-type': 'application/json',
28-
'traceparent': '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01',
29-
},
30-
};
3123

3224
test("should accept latest protocol version", async () => {
3325
let sendPromiseResolve: (value: unknown) => void;
@@ -86,7 +78,7 @@ test("should accept latest protocol version", async () => {
8678
version: "1.0",
8779
},
8880
},
89-
}, { requestInfo: mockRequestInfo });
81+
});
9082

9183
await expect(sendPromise).resolves.toBeUndefined();
9284
});
@@ -147,7 +139,7 @@ test("should accept supported older protocol version", async () => {
147139
version: "1.0",
148140
},
149141
},
150-
}, { requestInfo: mockRequestInfo });
142+
});
151143

152144
await expect(sendPromise).resolves.toBeUndefined();
153145
});
@@ -207,7 +199,7 @@ test("should handle unsupported protocol version", async () => {
207199
version: "1.0",
208200
},
209201
},
210-
}, { requestInfo: mockRequestInfo });
202+
});
211203

212204
await expect(sendPromise).resolves.toBeUndefined();
213205
});

src/server/mcp.test.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,13 @@ import {
1414
LoggingMessageNotificationSchema,
1515
Notification,
1616
TextContent,
17-
ElicitRequestSchema,
17+
ElicitRequestSchema
1818
} from "../types.js";
1919
import { ResourceTemplate } from "./mcp.js";
2020
import { completable } from "./completable.js";
2121
import { UriTemplate } from "../shared/uriTemplate.js";
22-
import { RequestInfo } from "./types/types.js";
2322
import { getDisplayName } from "../shared/metadataUtils.js";
2423

25-
const mockRequestInfo: RequestInfo = {
26-
headers: {
27-
'content-type': 'application/json',
28-
'accept': 'application/json',
29-
},
30-
};
31-
3224
describe("McpServer", () => {
3325
/***
3426
* Test: Basic Server Instance
@@ -222,8 +214,7 @@ describe("ResourceTemplate", () => {
222214
signal: abortController.signal,
223215
requestId: 'not-implemented',
224216
sendRequest: () => { throw new Error("Not implemented") },
225-
sendNotification: () => { throw new Error("Not implemented") },
226-
requestInfo: mockRequestInfo
217+
sendNotification: () => { throw new Error("Not implemented") }
227218
});
228219
expect(result?.resources).toHaveLength(1);
229220
expect(list).toHaveBeenCalled();

src/server/sse.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ describe('SSEServerTransport', () => {
232232
);
233233
});
234234

235-
/***
235+
/**
236236
* Test: Tool With Request Info
237237
*/
238238
it("should pass request info to tool callback", async () => {

src/server/sse.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { randomUUID } from "node:crypto";
22
import { IncomingMessage, ServerResponse } from "node:http";
33
import { Transport } from "../shared/transport.js";
4-
import { JSONRPCMessage, JSONRPCMessageSchema } from "../types.js";
4+
import { JSONRPCMessage, JSONRPCMessageSchema, MessageExtraInfo, RequestInfo } from "../types.js";
55
import getRawBody from "raw-body";
66
import contentType from "content-type";
77
import { AuthInfo } from "./auth/types.js";
8-
import { MessageExtraInfo, RequestInfo } from "./types/types.js";
98
import { URL } from 'url';
109

1110
const MAXIMUM_MESSAGE_SIZE = "4mb";

src/server/streamableHttp.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { IncomingMessage, ServerResponse } from "node:http";
22
import { Transport } from "../shared/transport.js";
3-
import { isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessage, JSONRPCMessageSchema, RequestId, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from "../types.js";
3+
import { MessageExtraInfo, RequestInfo, isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessage, JSONRPCMessageSchema, RequestId, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from "../types.js";
44
import getRawBody from "raw-body";
55
import contentType from "content-type";
66
import { randomUUID } from "node:crypto";
77
import { AuthInfo } from "./auth/types.js";
8-
import { MessageExtraInfo, RequestInfo } from "./types/types.js";
98

109
const MAXIMUM_MESSAGE_SIZE = "4mb";
1110

src/server/types/types.ts

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

src/shared/protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import {
2222
Result,
2323
ServerCapabilities,
2424
RequestMeta,
25+
MessageExtraInfo,
26+
RequestInfo,
2527
} from "../types.js";
2628
import { Transport, TransportSendOptions } from "./transport.js";
2729
import { AuthInfo } from "../server/auth/types.js";
28-
import { MessageExtraInfo, RequestInfo } from "../server/types/types.js";
2930

3031
/**
3132
* Callback for progress notifications.

src/shared/transport.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { MessageExtraInfo } from "../server/types/types.js";
2-
import { JSONRPCMessage, RequestId } from "../types.js";
1+
import { JSONRPCMessage, MessageExtraInfo, RequestId } from "../types.js";
32

43
/**
54
* Options for sending a JSON-RPC message.

src/types.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z, ZodTypeAny } from "zod";
2+
import { AuthInfo } from "./server/auth/types.js";
23

34
export const LATEST_PROTOCOL_VERSION = "2025-06-18";
45
export const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
@@ -1463,6 +1464,36 @@ type Flatten<T> = T extends Primitive
14631464

14641465
type Infer<Schema extends ZodTypeAny> = Flatten<z.infer<Schema>>;
14651466

1467+
/**
1468+
* Headers that are compatible with both Node.js and the browser.
1469+
*/
1470+
export type IsomorphicHeaders = Record<string, string | string[] | undefined>;
1471+
1472+
/**
1473+
* Information about the incoming request.
1474+
*/
1475+
export interface RequestInfo {
1476+
/**
1477+
* The headers of the request.
1478+
*/
1479+
headers: IsomorphicHeaders;
1480+
}
1481+
1482+
/**
1483+
* Extra information about a message.
1484+
*/
1485+
export interface MessageExtraInfo {
1486+
/**
1487+
* The request information.
1488+
*/
1489+
requestInfo?: RequestInfo;
1490+
1491+
/**
1492+
* The authentication information.
1493+
*/
1494+
authInfo?: AuthInfo;
1495+
}
1496+
14661497
/* JSON-RPC types */
14671498
export type ProgressToken = Infer<typeof ProgressTokenSchema>;
14681499
export type Cursor = Infer<typeof CursorSchema>;

0 commit comments

Comments
 (0)