@@ -142,7 +142,7 @@ export class MCPProxyApiClient extends APIClientBase {
142142 async onStreamSessionInitialized ( _ctx , transport , self ) {
143143 const sessionId = transport . sessionId ! ;
144144 self . streamTransports [ sessionId ] = transport ;
145- apiClient . setProxyHandler ( MCPProtocols . STREAM , async ( req , res ) => {
145+ apiClient . setProxyHandler ( MCPProtocols . STREAM , async ( req : http . IncomingMessage , res : http . ServerResponse ) => {
146146 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
147147 // @ts -ignore
148148 self . app . RequestClass = EggRequest ;
@@ -157,43 +157,46 @@ export class MCPProxyApiClient extends APIClientBase {
157157 }
158158 const sessionId = req . headers [ 'mcp-session-id' ] as string | undefined ;
159159 if ( ! sessionId ) {
160- res . status ( 500 ) . json ( {
160+ res . writeHead ( 500 , { 'content-type' : 'application/json' } ) ;
161+ res . end ( JSON . stringify ( {
161162 jsonrpc : '2.0' ,
162163 error : {
163164 code : - 32603 ,
164165 message : 'session id not have and run in proxy' ,
165166 } ,
166167 id : null ,
167- } ) ;
168+ } ) ) ;
168169 } else {
169170 let transport : StreamableHTTPServerTransport ;
170171 const existingTransport = self . streamTransports [ sessionId ] ;
171172 if ( existingTransport instanceof StreamableHTTPServerTransport ) {
172173 transport = existingTransport ;
173174 } else {
174- res . status ( 400 ) . json ( {
175+ res . writeHead ( 400 , { 'content-type' : 'application/json' } ) ;
176+ res . end ( JSON . stringify ( {
175177 jsonrpc : '2.0' ,
176178 error : {
177179 code : - 32000 ,
178180 message : 'Bad Request: Session exists but uses a different transport protocol' ,
179181 } ,
180182 id : null ,
181- } ) ;
183+ } ) ) ;
182184 return ;
183185 }
184186 if ( transport ) {
185187 await self . app . ctxStorage . run ( ctx , async ( ) => {
186188 await transport . handleRequest ( ctx . req , ctx . res ) ;
187189 } ) ;
188190 } else {
189- res . status ( 404 ) . send ( {
191+ res . writeHead ( 400 , { 'content-type' : 'application/json' } ) ;
192+ res . end ( JSON . stringify ( {
190193 jsonrpc : '2.0' ,
191194 error : {
192195 code : - 32602 ,
193196 message : 'Bad Request: No transport found for sessionId' ,
194197 } ,
195198 id : null ,
196- } ) ;
199+ } ) ) ;
197200 }
198201 }
199202 } ) ;
0 commit comments