Describe the bug
When sending a message with the batch payload of several requests, like:
val payload = encodeMessages(listOf(firstRequest, secondRequest))
So the body is:
[{"id":"first","method":"tools/list"},{"id":"second","method":"resources/list"}]
the response from the server will be
[{"id":"second",...},{"id":"first",...}]
instead of
[{"id":"first",...},{"id":"second",...}]
To Reproduce
Steps to reproduce the behavior:
- Checkout to the branch
zarechneva/streamable-http-transport-tests OR edit the StreamableHttpServerTransportTest and add the following checks to the batched requests wait for all responses before replying test:
// Check responses' order
assertEquals(listOf(firstRequest.id, secondRequest.id), responses.map { it.id })
val firstMeta = (responses[0] as ListToolsResult).meta
val secondMeta = (responses[1] as ListResourcesResult).meta
assertEquals("first", firstMeta?.get("label")?.jsonPrimitive?.content)
assertEquals("second", secondMeta?.get("label")?.jsonPrimitive?.content)
instead of a TODO.
2. Run io.modelcontextprotocol.kotlin.sdk.server.StreamableHttpServerTransportTest#batched requests wait for all responses before replying
Expected behavior
The order of responses should match the order of messages in the batch request.