✅ Successfully implemented HTTP/SSE MCP server support for normal wonopcode TUI mode.
Claude CLI now uses wonopcode's custom tools via HTTP/SSE in all modes:
wonopcode(TUI mode)wonopcode run(command mode)wonopcode --headless(headless mode - already worked)
crates/wonopcode/src/main.rs(+82 lines, -2 lines)
New async function that:
- Binds to
127.0.0.1:0(random available port) - Creates MCP HTTP state with all wonopcode tools
- Starts background HTTP server serving
/mcp/sseand/mcp/messageendpoints - Returns tuple of
(mcp_sse_url, server_handle) - Uses simplified router (no CORS needed for localhost)
Added after line 613:
// Start background MCP HTTP server for Claude CLI integration
let (mcp_url, mcp_server_handle) = match start_mcp_server(cwd).await {
Ok((url, handle)) => (Some(url), Some(handle)),
Err(e) => {
tracing::warn!(error = %e, "Failed to start MCP server, Claude CLI will not use custom tools");
(None, None)
}
};Changed line 626:
// Before:
mcp_url: None, // No custom MCP tools in TUI mode
// After:
mcp_url, // Use background MCP server for custom toolsAdded at line 743 (shutdown section):
// Shutdown MCP server
if let Some(handle) = mcp_server_handle {
handle.abort();
}Same three changes as run_command():
- MCP server startup after line 1644
- Updated
mcp_urlfield at line 1667 - MCP server shutdown at line 1706 (with graceful 100ms delay)
- User runs
wonopcodeorwonopcode run "..." start_mcp_server(cwd)is called- Server binds to random port (e.g.,
127.0.0.1:54321) - Returns URL:
http://127.0.0.1:54321/mcp/sse - URL is passed to
RunnerConfigasmcp_url - When Claude CLI provider is created, it uses this URL
- Claude CLI connects via HTTP/SSE to wonopcode's MCP server
- Claude CLI uses wonopcode tools (not built-in tools)
- User exits wonopcode
- MCP server handle is aborted
- (Optional) 100ms grace period for TUI mode
- Instance cleanup proceeds
┌────────────────┐ ┌──────────────┐
│ wonopcode │ NO MCP │ Claude CLI │
│ (TUI mode) │ ────────► │ (built-in │
│ │ │ tools) │
└────────────────┘ └──────────────┘
┌────────────────┐ ┌──────────────────┐ ┌──────────────┐
│ wonopcode │ spawns │ Background HTTP │ HTTP/SSE │ Claude CLI │
│ (TUI mode) │ ────────► │ MCP Server │ ◄───────► │ (wonopcode │
│ │ │ (random port) │ │ tools) │
└────────────────┘ └──────────────────┘ └──────────────┘
│
│ serves
▼
┌──────────────┐
│ /mcp/sse │
│ /mcp/message │
└──────────────┘
cargo build --release✅ Compiles successfully with no warnings
./target/release/wonopcodeExpected log output:
Starting background MCP HTTP server address=127.0.0.1:xxxxx
MCP HTTP server started mcp_url="http://127.0.0.1:xxxxx/mcp/sse"
When using Anthropic provider with Claude CLI auth:
Using Claude CLI for subscription-based access with custom tools
✅ Unified Architecture - Same HTTP/SSE MCP server used in all modes ✅ No Configuration - Automatic port selection, works out of the box ✅ Clean Shutdown - Proper cleanup on exit ✅ Graceful Fallback - If MCP server fails to start, continues without custom tools ✅ Localhost Only - Binds to 127.0.0.1 for security ✅ No CORS Complexity - Simplified for localhost-only use
UPDATE.md- Original architecture documentationIMPLEMENTATION.md- Detailed implementation guideCHANGES.md- This file, summary of completed workmcp-tui-mode.patch- Patch file (for reference)
Run these commands to verify:
# Check that it compiles
cargo build --release
# Check line count changes
git diff --stat crates/wonopcode/src/main.rs
# Expected: 1 file changed, 82 insertions(+), 2 deletions(-)
# Check that start_mcp_server exists
grep -c "async fn start_mcp_server" crates/wonopcode/src/main.rs
# Expected: 1
# Check that mcp_url is used (not None)
grep "mcp_url, // Use background MCP server" crates/wonopcode/src/main.rs | wc -l
# Expected: 2
# Check that shutdown code exists
grep -c "// Shutdown MCP server" crates/wonopcode/src/main.rs
# Expected: 2To use in production:
cargo install --path crates/wonopcode --lockedThe Claude CLI provider will now automatically use wonopcode's custom tools via the background MCP server in all modes.