From 38681376b55adae4e62b138d96acdea8df8901c9 Mon Sep 17 00:00:00 2001 From: Zoom Date: Fri, 15 May 2026 17:53:50 +0400 Subject: [PATCH] Send JSON-RPC error response when a request handler throws When a request handler raises an exception, runRpc catches it and logs the error but never sends a response back to the client. The MCP client's pending request hangs until its own timeout of 30 seconds for OpenCode, making the server appear unresponsive and wasting time on every failure. Fix: construct a JSON-RPC error response with code -32603 and the exception message, then write it to the transport output. --- lstransports.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lstransports.nim b/lstransports.nim index 007c05cd..3eca9b03 100644 --- a/lstransports.nim +++ b/lstransports.nim @@ -213,6 +213,12 @@ proc runRpc(ls: LanguageServer, req: RequestRx, rpc: RpcProc): Future[void] {.as except CatchableError as ex: error "[RunRPC] ", msg = ex.msg, req = req.`method` writeStackTrace(ex = ex) + var errJson = newJObject() + errJson["jsonrpc"] = %*"2.0" + if req.id.kind == riNumber: + errJson["id"] = %*req.id.num + errJson["error"] = %*{"code": -32603, "message": ex.msg} + ls.writeOutput(errJson) proc processMessage(ls: LanguageServer, message: string) {.raises: [].} = try: