From 4c8e2f6414c9e3125ff30f98cc21fd133f1cb153 Mon Sep 17 00:00:00 2001 From: Riz Ashraf Date: Tue, 29 Sep 2026 18:24:43 +0100 Subject: [PATCH] docs: remove zigbuild references and update just commands, fix: remove Content-Length formatting causing parse errors --- README.md | 18 ++++++------ justfile | 73 ++++++++++++++++++++++++++++++++++++++++-------- stub/src/main.rs | 21 ++++++++++++-- 3 files changed, 89 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index f34d39c..ced8c6a 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,13 @@ Copy-Item target\release\mcp-memory-stub.exe C:\Users\reazul.ashraf\.local\bin\m if (-not (Get-Process mcp-memory-server -ErrorAction SilentlyContinue)) { Start-Process -FilePath "C:\Users\reazul.ashraf\.local\bin\mcp-memory-server.exe" -WindowStyle Hidden -ErrorAction SilentlyContinue } ``` -**Shutting Down:** If you need to stop or restart the background daemon (e.g., to replace the executable after a recompile), you MUST NEVER use brute-force OS kill commands (e.g., Stop-Process, pkill, or kill). Instead, you MUST ALWAYS use the server's built-in graceful shutdown mechanisms: -1. The CLI flag: `--exit` (or `--restart`) +**Shutting Down & Managing:** If you need to stop, start, or restart the background daemon (e.g., to replace the executable after a recompile), you MUST NEVER use brute-force OS kill commands (e.g., Stop-Process, pkill, or kill). Instead, you MUST ALWAYS use the built-in graceful shutdown mechanisms, which are wrapped neatly in the `justfile`: ```powershell -mcp-memory-server.exe --exit +just start +just stop +just restart ``` -2. The HTTP endpoint: `POST http://127.0.0.1:3000/shutdown` +Alternatively, you can gracefully shut down the server by invoking the executable with the `--exit` flag (`mcp-memory-server.exe --exit`) or hitting the HTTP endpoint (`POST http://127.0.0.1:3000/shutdown`). ` **Step 2:** Update your Windows ~/.gemini/config/mcp_config.json to point the CLI to the ultra-lightweight stub (since the server is already running in the background): `json @@ -44,11 +45,10 @@ mcp-memory-server.exe --exit ` ` ### 2. WSL / Linux Installation (The Stub) -Compile the ultra-lightweight stub as a static Linux binary (from the Windows host): -`powershell -cargo zigbuild --target x86_64-unknown-linux-musl --release -p mcp-memory-stub -wsl.exe -d Ubuntu -e bash -c "cp /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory/target/x86_64-unknown-linux-musl/release/mcp-memory-stub ~/.local/bin/mcp-memory-stub && chmod +x ~/.local/bin/mcp-memory-stub" -` +Compile the ultra-lightweight stub as a native Linux binary directly from WSL (we do not use zigbuild): +```powershell +just deploy-stub-wsl +``` ` Update your WSL ~/.gemini/config/mcp_config.json: `json diff --git a/justfile b/justfile index 8b16de2..bbb3329 100644 --- a/justfile +++ b/justfile @@ -22,28 +22,65 @@ shutdown-server: -if (Get-Process mcp-memory-server, mcp-memory-stub, mcp-memory-win-nvim -ErrorAction SilentlyContinue) { Stop-Process -Name mcp-memory-server, mcp-memory-stub, mcp-memory-win-nvim -Force -ErrorAction SilentlyContinue } # Build Windows-native binaries -build-win: - Write-Host "Building Windows binaries..." -ForegroundColor Cyan - cargo build --release -p mcp-memory-server -p mcp-memory-stub -p mcp-memory-win-nvim +build-win: build-server build-stub-win build-nvim-win # Deploy Windows-native binaries -deploy-win: shutdown-server - Write-Host "Deploying Windows binaries..." -ForegroundColor Cyan - Copy-Item -Force target\release\mcp-memory-stub.exe "C:\Users\reazul.ashraf\.local\bin\"; Copy-Item -Force target\release\mcp-memory-win-nvim.exe "C:\Users\reazul.ashraf\.local\bin\" +deploy-win: deploy-server deploy-stub-win deploy-nvim-win deploy-rules-win + +build-server: + Write-Host "Building Windows Server..." -ForegroundColor Cyan + cargo build --release -p mcp-memory-server + +deploy-server: shutdown-server + Write-Host "Deploying Windows Server..." -ForegroundColor Cyan Copy-Item -Force target\release\mcp-memory-server.exe "C:\Users\reazul.ashraf\.local\bin\" + +build-stub-win: + Write-Host "Building Windows Stub..." -ForegroundColor Cyan + cargo build --release -p mcp-memory-stub + +deploy-stub-win: + Write-Host "Deploying Windows Stub..." -ForegroundColor Cyan + -Stop-Process -Name mcp-memory-stub -Force -ErrorAction SilentlyContinue + Copy-Item -Force target\release\mcp-memory-stub.exe "C:\Users\reazul.ashraf\.local\bin\" + +build-nvim-win: + Write-Host "Building Windows Nvim..." -ForegroundColor Cyan + cargo build --release -p mcp-memory-win-nvim + +deploy-nvim-win: + Write-Host "Deploying Windows Nvim..." -ForegroundColor Cyan + -Stop-Process -Name mcp-memory-win-nvim -Force -ErrorAction SilentlyContinue + Copy-Item -Force target\release\mcp-memory-win-nvim.exe "C:\Users\reazul.ashraf\.local\bin\" + +deploy-rules-win: Write-Host "Deploying global Agent rules (Windows)..." -ForegroundColor Cyan if (!(Test-Path "C:\Users\reazul.ashraf\.gemini\config\rules")) { New-Item -ItemType Directory -Force -Path "C:\Users\reazul.ashraf\.gemini\config\rules" | Out-Null } Copy-Item -Force -Recurse agent-rules\* "C:\Users\reazul.ashraf\.gemini\config\rules\" # Build WSL-native binaries -build-wsl: - Write-Host "Building WSL binaries natively..." -ForegroundColor Cyan - wsl.exe -d Ubuntu -e bash -c 'export PATH="$PATH:/home/riz/.cargo/bin" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cargo build --release -p mcp-memory-stub -p mcp-memory-linux-nvim' +build-wsl: build-stub-wsl build-nvim-wsl # Deploy WSL-native binaries -deploy-wsl: - Write-Host "Deploying WSL binaries natively..." -ForegroundColor Cyan - wsl.exe -d Ubuntu -e bash -c 'export PATH="$PATH:/home/riz/.cargo/bin" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cp target/release/mcp-memory-stub /home/riz/.local/bin/ && cp target/release/mcp-memory-linux-nvim /home/riz/.local/bin/' +deploy-wsl: deploy-stub-wsl deploy-nvim-wsl deploy-rules-wsl + +build-stub-wsl: + Write-Host "Building WSL Stub natively..." -ForegroundColor Cyan + wsl.exe -d Ubuntu -e bash -c 'export PATH="$PATH:/home/riz/.cargo/bin" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cargo build --release -p mcp-memory-stub' + +deploy-stub-wsl: + Write-Host "Deploying WSL Stub natively..." -ForegroundColor Cyan + wsl.exe -d Ubuntu -e bash -c 'export PATH="$PATH:/home/riz/.cargo/bin" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cp target/release/mcp-memory-stub /home/riz/.local/bin/' + +build-nvim-wsl: + Write-Host "Building WSL Nvim natively..." -ForegroundColor Cyan + wsl.exe -d Ubuntu -e bash -c 'export PATH="$PATH:/home/riz/.cargo/bin" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cargo build --release -p mcp-memory-linux-nvim' + +deploy-nvim-wsl: + Write-Host "Deploying WSL Nvim natively..." -ForegroundColor Cyan + wsl.exe -d Ubuntu -e bash -c 'export PATH="$PATH:/home/riz/.cargo/bin" && cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && cp target/release/mcp-memory-linux-nvim /home/riz/.local/bin/' + +deploy-rules-wsl: Write-Host "Deploying global Agent rules (WSL)..." -ForegroundColor Cyan wsl.exe -d Ubuntu -e bash -c 'mkdir -p /home/riz/.gemini/config/rules && cp -r /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory/agent-rules/* /home/riz/.gemini/config/rules/' @@ -59,3 +96,15 @@ test-coverage: # Start the server directly startup-server: cargo run -p mcp-memory-server + +# Stop the background server +stop: shutdown-server + +# Start the server in the background (nohup equivalent) +start: + Write-Host "Starting MCP server in background..." -ForegroundColor Cyan + Start-Process -WindowStyle Hidden -FilePath mcp-memory-server + +# Restart the server +restart: stop start + diff --git a/stub/src/main.rs b/stub/src/main.rs index 4689161..d1f79f9 100644 --- a/stub/src/main.rs +++ b/stub/src/main.rs @@ -56,6 +56,7 @@ fn main() -> Result<(), Box> { .replace("https://", "wss://"); let ws_url = format!("{ws_url}/ws?client=proxy"); + let mut retry_count = 0; loop { if shutdown_rx.try_recv().is_ok() { tracing::info!("Stub shutdown requested"); @@ -87,6 +88,7 @@ fn main() -> Result<(), Box> { match connect_result { Ok(Ok((ws_stream, _))) => { + retry_count = 0; tracing::info!("Successfully connected to target server"); let (mut write, mut read) = ws_stream.split(); @@ -125,8 +127,8 @@ fn main() -> Result<(), Box> { ); use tokio::io::AsyncWriteExt; let mut stdout = tokio::io::stdout(); - let _ = stdout.write_all(text.as_bytes()).await; - let _ = stdout.write_all(b"\n").await; + let response = format!("{}\n", text); + let _ = stdout.write_all(response.as_bytes()).await; let _ = stdout.flush().await; } } @@ -153,14 +155,29 @@ fn main() -> Result<(), Box> { } Ok(Err(e)) => { tracing::error!("Failed to connect via WSS: {}", e); + retry_count += 1; + if retry_count >= 5 { + tracing::error!("Max connection retries reached. Exiting proxy."); + break; + } tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; } Err(_) => { tracing::error!("Connection attempt timed out"); + retry_count += 1; + if retry_count >= 5 { + tracing::error!("Max connection retries reached. Exiting proxy."); + break; + } tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; } } } + + if retry_count >= 5 { + return Err("Failed to connect to the MCP memory server after multiple attempts. Is it running?".into()); + } + Ok(()) }) }