More MCP work

This commit is contained in:
2026-03-08 21:28:47 -04:00
parent 93d4ed2038
commit 695de53b30
19 changed files with 388 additions and 546 deletions

View File

@@ -68,7 +68,7 @@ def disconnect():
def send_and_receive(message):
"""Send a JSON message to the editor and return the response."""
"""Send a JSON message to the editor and return the null-terminated response."""
data = json.dumps(message) + "\n"
sock.sendall(data.encode())
@@ -78,10 +78,10 @@ def send_and_receive(message):
if not chunk:
raise ConnectionError("Connection closed")
result += chunk
try:
return json.loads(result)
except json.JSONDecodeError:
continue
if b"\0" in result:
break
return result[:result.index(b"\0")].decode()
def forward_to_editor(arguments):
@@ -128,10 +128,8 @@ def handle_message(msg):
params = msg.get("params", {})
arguments = params.get("arguments", {})
result = forward_to_editor(arguments)
is_error = "error" in result
return make_jsonrpc(msg_id, {
"content": [{"type": "text", "text": json.dumps(result)}],
**({"isError": True} if is_error else {}),
"content": [{"type": "text", "text": result}],
})
return {