I'm developing a MCP client and a server. I noticed that if I'm in stateful mode on the server (Stateless = false) the client will make only a POST / call to initialize the server. However if I enable the stateless mode (Stateless = true) the client will make an additional GET / call (that will get a 405 error) to the server.
In debugging I noticed the GET call is coming from here
|
_getReceiveTask ??= ReceiveUnsolicitedMessagesAsync(); |
What I don't get is why the GET call is made only when stateless and how it is deciding that (since state is a feature of the server and not the client) and if it makes sense to do that at all since as far as I understand in stateless mode unsolicited messages aren't supported. I should be the opposite in principle
|
The Streamable HTTP client automatically reconnects its SSE event stream when the connection drops. This only applies to **stateful sessions** — the GET event stream is how the server sends unsolicited messages to the client, and it requires an active session. Stream reconnection is separate from session expiry: reconnection recovers the event stream within an existing session, while the example above handles creating a new session after the server has terminated the old one. |
.
If that matters the client is set to TransportMode = HttpTransportMode.StreamableHttp avoiding SSE.
I'm developing a MCP client and a server. I noticed that if I'm in stateful mode on the server (Stateless = false) the client will make only a POST / call to initialize the server. However if I enable the stateless mode (Stateless = true) the client will make an additional GET / call (that will get a 405 error) to the server.
In debugging I noticed the GET call is coming from here
csharp-sdk/src/ModelContextProtocol.Core/Client/StreamableHttpClientSessionTransport.cs
Line 154 in 07435dc
What I don't get is why the GET call is made only when stateless and how it is deciding that (since state is a feature of the server and not the client) and if it makes sense to do that at all since as far as I understand in stateless mode unsolicited messages aren't supported. I should be the opposite in principle
csharp-sdk/docs/concepts/stateless/stateless.md
Line 321 in 07435dc
If that matters the client is set to TransportMode = HttpTransportMode.StreamableHttp avoiding SSE.