From b2f498a7f1cf12ca0db4486c839f662a80be0647 Mon Sep 17 00:00:00 2001 From: Steve McCoole Date: Tue, 10 Mar 2026 15:49:02 -0500 Subject: [PATCH] Fix buffer limits and response parsing for large index payloads Increase the TCP read buffer in the Swift service from 1KB to 64KB and the Python asyncio stream reader limit from the default 64KB to 1MB to handle large JSON responses without truncation. Fix load_index to correctly extract the boolean from the nested status response structure instead of returning the raw dict. Also downgrade the misleading error-level log to a removed line. --- src/xcode_index_mcp/server.py | 12 +++++++++--- swift-service/Sources/TCPServer.swift | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/xcode_index_mcp/server.py b/src/xcode_index_mcp/server.py index 7130cab..f028141 100644 --- a/src/xcode_index_mcp/server.py +++ b/src/xcode_index_mcp/server.py @@ -147,7 +147,10 @@ async def connect(self): """Connect to the Swift MCP service.""" if not self.reader or not self.writer: try: - self.reader, self.writer = await asyncio.open_connection(self.host, self.port) + ## Increase limit to 1MB for large JSON responses + self.reader, self.writer = await asyncio.open_connection( + self.host, self.port, limit=1024*1024 + ) logger.info("Connected to Swift service") except Exception as e: raise McpError( @@ -233,8 +236,11 @@ async def load_index(projectName: str) -> bool: logger.info(f"Loading index for project: {projectName}") try: result = await swift_service.send_request("is_available", {"projectName": projectName}) - logger.error(f"Request sent successfully: {result}") - return result + # Extract available boolean from the nested result structure + if isinstance(result, dict) and result.get("type") == "status": + value = result.get("value", {}) + return value.get("available", False) + return False except Exception as e: logger.error(f"Failed to load index for project '{projectName}': {str(e)}") raise McpError( diff --git a/swift-service/Sources/TCPServer.swift b/swift-service/Sources/TCPServer.swift index c9b06e5..935a41f 100644 --- a/swift-service/Sources/TCPServer.swift +++ b/swift-service/Sources/TCPServer.swift @@ -99,7 +99,7 @@ class TCPServer { } private func handleClient(_ clientSocket: Int32) { - var buffer = [UInt8](repeating: 0, count: 1024) + var buffer = [UInt8](repeating: 0, count: 65536) while true { let bytesRead = read(clientSocket, &buffer, buffer.count)