3030 */
3131class StreamableHttpTransport extends BaseTransport
3232{
33+ private const SESSION_HEADER = 'Mcp-Session-Id ' ;
34+
35+ private const ALLOWED_HEADER = [
36+ 'Accept ' ,
37+ 'Authorization ' ,
38+ 'Content-Type ' ,
39+ 'Last-Event-ID ' ,
40+ 'Mcp-Protocol-Version ' ,
41+ self ::SESSION_HEADER ,
42+ ];
43+
3344 private ResponseFactoryInterface $ responseFactory ;
3445 private StreamFactoryInterface $ streamFactory ;
3546
@@ -62,8 +73,8 @@ public function __construct(
6273 $ this ->corsHeaders = array_merge ([
6374 'Access-Control-Allow-Origin ' => '* ' ,
6475 'Access-Control-Allow-Methods ' => 'GET, POST, DELETE, OPTIONS ' ,
65- 'Access-Control-Allow-Headers ' => ' Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID, Authorization, Accept ' ,
66- 'Access-Control-Expose-Headers ' => ' Mcp-Session-Id ' ,
76+ 'Access-Control-Allow-Headers ' => implode ( ' , ' , self :: ALLOWED_HEADER ) ,
77+ 'Access-Control-Expose-Headers ' => self :: SESSION_HEADER ,
6778 ], $ corsHeaders );
6879
6980 foreach ($ middleware as $ m ) {
@@ -120,7 +131,7 @@ protected function handlePostRequest(): ResponseInterface
120131 protected function handleDeleteRequest (): ResponseInterface
121132 {
122133 if (!$ this ->sessionId ) {
123- return $ this ->createErrorResponse (Error::forInvalidRequest (' Mcp-Session-Id header is required. ' ), 400 );
134+ return $ this ->createErrorResponse (Error::forInvalidRequest (self :: SESSION_HEADER . ' header is required. ' ), 400 );
124135 }
125136
126137 $ this ->handleSessionEnd ($ this ->sessionId );
@@ -144,7 +155,7 @@ protected function createJsonResponse(): ResponseInterface
144155 ->withBody ($ this ->streamFactory ->createStream ($ responseBody ));
145156
146157 if ($ this ->sessionId ) {
147- $ response = $ response ->withHeader (' Mcp-Session-Id ' , $ this ->sessionId ->toRfc4122 ());
158+ $ response = $ response ->withHeader (self :: SESSION_HEADER , $ this ->sessionId ->toRfc4122 ());
148159 }
149160
150161 return $ response ;
@@ -211,7 +222,7 @@ protected function createStreamedResponse(): ResponseInterface
211222 ->withBody ($ stream );
212223
213224 if ($ this ->sessionId ) {
214- $ response = $ response ->withHeader (' Mcp-Session-Id ' , $ this ->sessionId ->toRfc4122 ());
225+ $ response = $ response ->withHeader (self :: SESSION_HEADER , $ this ->sessionId ->toRfc4122 ());
215226 }
216227
217228 return $ response ;
@@ -276,7 +287,7 @@ protected function withCorsHeaders(ResponseInterface $response): ResponseInterfa
276287 private function handleRequest (ServerRequestInterface $ request ): ResponseInterface
277288 {
278289 $ this ->request = $ request ;
279- $ sessionIdString = $ request ->getHeaderLine (' Mcp-Session-Id ' );
290+ $ sessionIdString = $ request ->getHeaderLine (self :: SESSION_HEADER );
280291 $ this ->sessionId = $ sessionIdString ? Uuid::fromString ($ sessionIdString ) : null ;
281292
282293 return match ($ request ->getMethod ()) {
0 commit comments