Stack 5/5, based on client-mcp-endpoint. Merge in order.
Part of the client MCP stack (experimental): a client (TUI/desktop/web) opens a WebSocket to the server, and the server treats that incoming socket as an internal MCP server scoped to a location. Tool calls carry _meta["ai.opencode/sessionID"] so the client acts on the calling session. MCP has no official WebSocket transport, so this is a custom transport, which the spec allows.
This PR
The TUI connects as client MCP server tui (behind the client-mcp experiment, off by default) and exposes open_terminal and write_terminal.
- Opens or reuses the calling session's terminal without taking keyboard focus
- Errors if the session is unknown or not open in this TUI
write_terminal({ text }) types text as-is into the same terminal open_terminal would use (selected, else newest, else a new one); no newline is appended, so include \n to run a command. Input written before the pane attaches is queued and sent once it does
- Headless
<ClientMcp />; reconnects when the endpoint, credentials or directory change
Tests run the real TUI against a fake WebSocket peer (connection count, flag off, errors, create/reuse, no focus, written input reaches the PTY).
Two TUIs in the same directory both stay connected as tui: the most recently attached one serves the tools, and the earlier one takes over when it closes (connection stacking, #57503), so they don't keep replacing each other and reconnecting.
Stack
- feat(core): add MCP transport over incoming client sockets #57502 feat(core): add MCP transport over incoming client sockets
- feat(core): attach client-hosted MCP servers #57503 feat(core): attach client-hosted MCP servers
- feat(client): add connectClientMcp helper for client-hosted MCP tools #57504 feat(client): add connectClientMcp helper for client-hosted MCP tools
- feat(server): add client MCP websocket endpoint (experimental) #57505 feat(server): add client MCP websocket endpoint (experimental)
→ 5. feat(tui): expose open_terminal over client MCP (experimental) #57506 feat(tui): expose open_terminal over client MCP (experimental)