Skip to content

Batched requests' responses order is not respecting the order of requests #548

@aozherelyeva

Description

@aozherelyeva

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:

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions