Skip to content

Commit e1575e5

Browse files
teolex2020claude
andcommitted
fix: MCP _read_message supports both Content-Length and bare JSON
Claude Desktop uses Content-Length framing — previous rewrite broke it by not falling back to bare JSON when framing is absent. Now handles both paths reliably on Windows pipes. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 3c4fe13 commit e1575e5

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

python/aura/mcp_server.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,36 @@ def run_stdio(self):
293293
self.brain.close()
294294

295295
def _read_message(self) -> bytes | None:
296-
"""Read a JSON-RPC message (Content-Length framing per MCP spec)."""
297-
# Read headers
296+
"""Read a JSON-RPC message.
297+
298+
Supports both Content-Length framing (MCP spec) and bare JSON lines
299+
(some clients skip headers). Robust on Windows pipes.
300+
"""
301+
first = self._stdin.readline()
302+
if not first:
303+
return None
304+
first = first.rstrip(b"\r\n")
305+
306+
# Bare JSON line (starts with '{')
307+
if first.startswith(b"{"):
308+
return first
309+
310+
# Content-Length header framing
298311
headers = {}
312+
if b":" in first:
313+
k, _, v = first.partition(b":")
314+
headers[k.strip().lower()] = v.strip()
315+
299316
while True:
300317
line = self._stdin.readline()
301318
if not line:
302319
return None
303320
line = line.rstrip(b"\r\n")
304321
if line == b"":
305-
break # blank line ends headers
322+
break
306323
if b":" in line:
307-
key, _, value = line.partition(b":")
308-
headers[key.strip().lower()] = value.strip()
324+
k, _, v = line.partition(b":")
325+
headers[k.strip().lower()] = v.strip()
309326

310327
length = int(headers.get(b"content-length", 0))
311328
if length == 0:

0 commit comments

Comments
 (0)