3030 */
3131class StreamableHttpTransport extends BaseTransport
3232{
33+ public const MCP_SESSION_ID_HEADER = 'Mcp-Session-Id ' ;
34+
3335 private ResponseFactoryInterface $ responseFactory ;
3436 private StreamFactoryInterface $ streamFactory ;
3537
@@ -62,8 +64,8 @@ public function __construct(
6264 $ this ->corsHeaders = array_merge ([
6365 'Access-Control-Allow-Origin ' => '* ' ,
6466 '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 ' ,
67+ 'Access-Control-Allow-Headers ' => 'Content-Type, ' . self :: MCP_SESSION_ID_HEADER . ' , Mcp-Protocol-Version, Last-Event-ID, Authorization, Accept ' ,
68+ 'Access-Control-Expose-Headers ' => self :: MCP_SESSION_ID_HEADER ,
6769 ], $ corsHeaders );
6870
6971 foreach ($ middleware as $ m ) {
@@ -120,7 +122,7 @@ protected function handlePostRequest(): ResponseInterface
120122 protected function handleDeleteRequest (): ResponseInterface
121123 {
122124 if (!$ this ->sessionId ) {
123- return $ this ->createErrorResponse (Error::forInvalidRequest (' Mcp-Session-Id header is required. ' ), 400 );
125+ return $ this ->createErrorResponse (Error::forInvalidRequest (self :: MCP_SESSION_ID_HEADER . ' header is required. ' ), 400 );
124126 }
125127
126128 $ this ->handleSessionEnd ($ this ->sessionId );
@@ -144,7 +146,7 @@ protected function createJsonResponse(): ResponseInterface
144146 ->withBody ($ this ->streamFactory ->createStream ($ responseBody ));
145147
146148 if ($ this ->sessionId ) {
147- $ response = $ response ->withHeader (' Mcp-Session-Id ' , $ this ->sessionId ->toRfc4122 ());
149+ $ response = $ response ->withHeader (self :: MCP_SESSION_ID_HEADER , $ this ->sessionId ->toRfc4122 ());
148150 }
149151
150152 return $ response ;
@@ -211,7 +213,7 @@ protected function createStreamedResponse(): ResponseInterface
211213 ->withBody ($ stream );
212214
213215 if ($ this ->sessionId ) {
214- $ response = $ response ->withHeader (' Mcp-Session-Id ' , $ this ->sessionId ->toRfc4122 ());
216+ $ response = $ response ->withHeader (self :: MCP_SESSION_ID_HEADER , $ this ->sessionId ->toRfc4122 ());
215217 }
216218
217219 return $ response ;
@@ -276,7 +278,7 @@ protected function withCorsHeaders(ResponseInterface $response): ResponseInterfa
276278 private function handleRequest (ServerRequestInterface $ request ): ResponseInterface
277279 {
278280 $ this ->request = $ request ;
279- $ sessionIdString = $ request ->getHeaderLine (' Mcp-Session-Id ' );
281+ $ sessionIdString = $ request ->getHeaderLine (self :: MCP_SESSION_ID_HEADER );
280282 $ this ->sessionId = $ sessionIdString ? Uuid::fromString ($ sessionIdString ) : null ;
281283
282284 return match ($ request ->getMethod ()) {
0 commit comments