StreamableHTTPServerTransport should only check init status when there is an sessionId

When using stateless mode, the backend will create a new transport for each request. For new transport, the initialized filed is always false. So we should only check the initialized filed if there is session existing
This commit is contained in:
qikaigao 2025-04-14 00:46:13 -07:00 • committed by GitHub
commit f0fbfc7fcb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -371,7 +371,7 @@ export class StreamableHTTPServerTransport implements Transport {
* Returns true if the session is valid, false otherwise
*/
private validateSession(req: IncomingMessage, res: ServerResponse): boolean {
if (!this._initialized) {
if (this.sessionId && !this._initialized) {
// If the server has not been initialized yet, reject all requests
res.writeHead(400).end(JSON.stringify({
jsonrpc: "2.0",