@@ -1115,6 +1115,29 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
11151115 } ) ;
11161116 } ) ;
11171117
1118+ it ( 'should accept application/json-only Accept headers in JSON response mode' , async ( ) => {
1119+ const response = await sendPostRequest ( baseUrl , TEST_MESSAGES . toolsList , sessionId , { Accept : 'application/json' } ) ;
1120+
1121+ expect ( response . status ) . toBe ( 200 ) ;
1122+ expect ( response . headers . get ( 'content-type' ) ) . toBe ( 'application/json' ) ;
1123+
1124+ const result = await response . json ( ) ;
1125+ expect ( result ) . toMatchObject ( {
1126+ jsonrpc : '2.0' ,
1127+ result : expect . objectContaining ( {
1128+ tools : expect . arrayContaining ( [ expect . objectContaining ( { name : 'greet' } ) ] )
1129+ } ) ,
1130+ id : 'tools-1'
1131+ } ) ;
1132+ } ) ;
1133+
1134+ it ( 'should accept wildcard Accept headers in JSON response mode' , async ( ) => {
1135+ const response = await sendPostRequest ( baseUrl , TEST_MESSAGES . toolsList , sessionId , { Accept : '*/*' } ) ;
1136+
1137+ expect ( response . status ) . toBe ( 200 ) ;
1138+ expect ( response . headers . get ( 'content-type' ) ) . toBe ( 'application/json' ) ;
1139+ } ) ;
1140+
11181141 it ( 'should return JSON response for batch requests' , async ( ) => {
11191142 const batchMessages : JSONRPCMessage [ ] = [
11201143 { jsonrpc : '2.0' , method : 'tools/list' , params : { } , id : 'batch-1' } ,
@@ -3180,6 +3203,31 @@ describe('WebStandardStreamableHTTPServerTransport - onerror callback', () => {
31803203 expect ( onerrorSpy . mock . calls [ 0 ] ! [ 0 ] ! . message ) . toMatch ( / N o t A c c e p t a b l e / ) ;
31813204 } ) ;
31823205
3206+ it ( 'should allow application/json-only Accept headers in JSON response mode' , async ( ) => {
3207+ const jsonServer = new McpServer ( { name : 'json-test-server' , version : '1.0.0' } ) ;
3208+ const jsonTransport = new WebStandardStreamableHTTPServerTransport ( {
3209+ sessionIdGenerator : ( ) => randomUUID ( ) ,
3210+ enableJsonResponse : true
3211+ } ) ;
3212+ const jsonOnError = vi . fn < ( error : Error ) => void > ( ) ;
3213+ jsonTransport . onerror = jsonOnError ;
3214+ await jsonServer . connect ( jsonTransport ) ;
3215+
3216+ try {
3217+ const response = await jsonTransport . handleRequest (
3218+ req ( 'POST' , { body : TEST_MESSAGES . initialize , headers : { Accept : 'application/json' , 'Content-Type' : 'application/json' } } )
3219+ ) ;
3220+
3221+ expect ( response . status ) . toBe ( 200 ) ;
3222+ expect ( response . headers . get ( 'content-type' ) ) . toBe ( 'application/json' ) ;
3223+ expect ( await response . json ( ) ) . toMatchObject ( { jsonrpc : '2.0' , id : 'init-1' } ) ;
3224+ expect ( jsonOnError ) . not . toHaveBeenCalled ( ) ;
3225+ } finally {
3226+ await jsonTransport . close ( ) ;
3227+ await jsonServer . close ( ) ;
3228+ }
3229+ } ) ;
3230+
31833231 it ( 'should call onerror for unsupported Content-Type' , async ( ) => {
31843232 await transport . handleRequest (
31853233 req ( 'POST' , {
0 commit comments