@@ -39,12 +39,19 @@ function createMockResponse(): jest.Mocked<ServerResponse> {
39
39
describe ( "StreamableHTTPServerTransport" , ( ) => {
40
40
let transport : StreamableHTTPServerTransport ;
41
41
let mockResponse : jest . Mocked < ServerResponse > ;
42
+ let mockRequest : string ;
42
43
43
44
beforeEach ( ( ) => {
44
45
transport = new StreamableHTTPServerTransport ( {
45
46
sessionId : randomUUID ( ) ,
46
47
} ) ;
47
48
mockResponse = createMockResponse ( ) ;
49
+ mockRequest = JSON . stringify ( {
50
+ jsonrpc : "2.0" ,
51
+ method : "test" ,
52
+ params : { } ,
53
+ id : 1 ,
54
+ } ) ;
48
55
} ) ;
49
56
50
57
afterEach ( ( ) => {
@@ -90,11 +97,13 @@ describe("StreamableHTTPServerTransport", () => {
90
97
91
98
it ( "should reject invalid session ID" , async ( ) => {
92
99
const req = createMockRequest ( {
93
- method : "GET " ,
100
+ method : "POST " ,
94
101
headers : {
95
102
"mcp-session-id" : "invalid-session-id" ,
96
- "accept" : "application/json, text/event-stream"
103
+ "accept" : "application/json, text/event-stream" ,
104
+ "content-type" : "application/json" ,
97
105
} ,
106
+ body : mockRequest ,
98
107
} ) ;
99
108
100
109
await transport . handleRequest ( req , mockResponse ) ;
@@ -107,11 +116,13 @@ describe("StreamableHTTPServerTransport", () => {
107
116
108
117
it ( "should reject non-initialization requests without session ID with 400 Bad Request" , async ( ) => {
109
118
const req = createMockRequest ( {
110
- method : "GET " ,
119
+ method : "POST " ,
111
120
headers : {
112
- accept : "application/json, text/event-stream" ,
121
+ "accept" : "application/json, text/event-stream" ,
122
+ "content-type" : "application/json" ,
113
123
// No mcp-session-id header
114
124
} ,
125
+ body : mockRequest
115
126
} ) ;
116
127
117
128
await transport . handleRequest ( req , mockResponse ) ;
0 commit comments