Skip to content

Conversation

Kehrlann
Copy link
Contributor

@Kehrlann Kehrlann commented Oct 1, 2025

  • When the client sends notification/initalized, servers MUST respond with HTTP 202 and an empty body. Before this PR, we checked for the absence of a Content-Type header to know whether the body was empty.
  • However, some servers will send an empty body with a Content-Type header, and that header may have an unsupported, default type such as text/html or text/plain.
  • Now we we also use the Content-Length header to check for an empty body. This header is optional in HTTP/2, so we do not make it our primary mechanism for detecting empty bodies.
  • Fixes Can't invoke Streamable HTTP MCP server implemented with Micronaut MCP #582

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

@Kehrlann Kehrlann requested review from tzolov and chemicL October 1, 2025 09:25
if (contentType.isBlank()) {
String contentLength = responseEvent.responseInfo()
.headers()
.firstValue("Content-Length")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to use a constant but it is inconsistent with the rest of the file (e.g. instances of Content-Type, a Cache-Control and an Access).

In that case I think we should standardize the whole transport. Agreed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, let's add the headers to the HttpHeaders class since they are either part of the specification of the HTTP-based remote transports or are simply needed to make it work. Last-Event-ID is not MCP specific but is part of the MCP remote transport logic so there's no need to think of other places for the common header names.

- When the client sends `notification/initalized`, servers must respond
  with HTTP 202 and an empty body. We checked for the absence of a
  Content-Type header to verify whether the body was empty.
- However, some servers will send an empty body with a Content-Type
  header, and that header may have an unsupported, default type such as
  `text/html` or `text/plain`.
- Now we we also use the Content-Length header to check for an empty
  body. This header is optional in HTTP/2, so we do not make it our
  primary mechanism for detecting empty bodies.
- As part of this PR, we also move hard-coded HTTP header names to the
  HttpHeaders interface. While they are not defined by the MCP spec,
  they are used by it and are core to implementing the protocol.
  Therefore, they have their place in a core interface.
- Fixes #582

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
@Kehrlann Kehrlann force-pushed the dgarnier/fix-client-transport-content-length-zero branch from c4bf139 to bb125d8 Compare October 1, 2025 10:18
@Kehrlann Kehrlann requested a review from chemicL October 1, 2025 10:19
Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Kehrlann !

@Kehrlann Kehrlann merged commit 080098e into main Oct 1, 2025
1 check passed
@Kehrlann Kehrlann deleted the dgarnier/fix-client-transport-content-length-zero branch October 1, 2025 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't invoke Streamable HTTP MCP server implemented with Micronaut MCP
3 participants