From 4b350fe967306ce13001c82269a8f940300e2c7d Mon Sep 17 00:00:00 2001 From: logikonline Date: Sun, 5 Apr 2026 02:48:24 -0400 Subject: [PATCH] fix(mcp): use Content-Length framing for all responses Adds writeFramed helper to send responses with HTTP-style Content-Length headers instead of raw JSON lines. Ensures compatibility with Claude Code which expects framed messages. Updates both main loop and writeResponse to use consistent framing. --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 977f1cb..73a0fac 100644 --- a/main.go +++ b/main.go @@ -110,8 +110,8 @@ func main() { debugLog("Response: %s", string(response)) - // Write response to stdout - fmt.Println(string(response)) + // Write response to stdout with Content-Length framing + writeFramed(response) } } @@ -211,7 +211,11 @@ func readMessage(reader *bufio.Reader) ([]byte, error) { func writeResponse(resp interface{}) { data, _ := json.Marshal(resp) - fmt.Println(string(data)) + writeFramed(data) +} + +func writeFramed(data []byte) { + fmt.Fprintf(os.Stdout, "Content-Length: %d\r\n\r\n%s", len(data), data) } func debugLog(format string, args ...interface{}) {