fix(mcp,start): JSON-RPC notifications return 202; no tmux attach

- mcp_post: notifications (no `id` field) → HTTP 202 with empty body,
  per streamable-HTTP MCP transport spec. Fixes rmcp 'transport channel
  closed' on codex's notifications/initialized.
- start.sh: don't attach to tmux; print URL only. Backend + tmux session
  run in background. UI is the only viewing surface.
- scripts/stop.sh: convenience teardown.
This commit is contained in:
ai-chess
2026-05-14 23:41:11 +03:00
parent e48f01dcb5
commit 4c5b306a9a
4 changed files with 54 additions and 8 deletions
+19 -3
View File
@@ -5,7 +5,7 @@ import json
from contextlib import asynccontextmanager
from typing import Any
from fastapi import FastAPI, HTTPException, Request, WebSocket, WebSocketDisconnect
from fastapi import FastAPI, HTTPException, Request, Response, WebSocket, WebSocketDisconnect
from fastapi.responses import FileResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
@@ -220,8 +220,24 @@ def build_app(state: state_mod.AppState) -> FastAPI:
except ValueError:
raise HTTPException(404, "unknown side")
body = await request.json()
if isinstance(body, list): # batch
return [await handle_mcp(s, item) for item in body if isinstance(item, dict)]
# JSON-RPC notification (no "id" field) → MUST get HTTP 202 with no body
# per streamable-HTTP MCP transport spec; otherwise rmcp (codex's client)
# treats the 200+body as an unexpected response and closes the channel.
if isinstance(body, list):
responses = []
for item in body:
if not isinstance(item, dict):
continue
if "id" not in item:
await handle_mcp(s, item)
continue
responses.append(await handle_mcp(s, item))
if not responses:
return Response(status_code=202)
return responses
if "id" not in body:
await handle_mcp(s, body)
return Response(status_code=202)
return await handle_mcp(s, body)
# --------- static UI ---------