Skip to content

Issue when using @hono/mcp, content-length is included when chunked encoding is used. #270

@ciamshrek

Description

@ciamshrek

I was trying to use @hono/mcp, when using Inspector it returns a precarious error.

[cause]: HTTPParserError: Response does not match the HTTP/1.1 protocol (Content-Length can't be present with Transfer-Encoding)
      at Parser.execute (node:internal/deps/undici/undici:5998:19)
      at Parser.readMore (node:internal/deps/undici/undici:5957:16)
      at Socket.<anonymous> (node:internal/deps/undici/undici:6285:18)
      at Socket.emit (node:events:518:28)
      at emitReadable_ (node:internal/streams/readable:834:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:89:21) {
    code: 'HPE_UNEXPECTED_CONTENT_LENGTH',
    data: 'c9\r\n' +
      'event: message\n' +
      'data: {"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{"listChanged":true}},"serverInfo":{"name":"example-mcp-server","version":"1.0.0"}},"jsonrpc":"2.0","id":0}\n' +
      '\n' +
      '\r\n' +
      '0\r\n' +
      '\r\n'
  }

Upon further debugging I traced that down to this line, https://github.com/honojs/node-server/blob/main/src/listener.ts#L167-L169, to me it sees more reasonable to expand the logic to check for chunked perhaps expand the code to shouldAddContentLength(headers): true/false and then derive it.

Happy to open PR if ya'll think that's the best way :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions