{"slug": "two-rust-clients-for-gemma-4-calling-the-endpoint-vs-calling-the-mcp-server", "title": "Two Rust Clients for Gemma 4: Calling the Endpoint vs. Calling the MCP Server 🦀", "summary": "A developer published two Rust CLI demos, gemma-rust and gemma-rust-mcp, that query a self-hosted Gemma 4 E2B model through an OpenAI-compatible HTTP endpoint and through an MCP server, respectively. The HTTP client prints the raw model response and metadata, while the MCP client launches the rig's own Python MCP server and returns tool output as markdown, illustrating what an agent sees versus what the model said. Both clients run against llama-server on a GTX 1650 Ti and vLLM on an NVIDIA L4 in Cloud Run.", "body_md": "This article provides a step by step guide to two small Rust CLIs that ask a self-hosted Gemma 4 E2B the same question. The first calls the model's OpenAI-compatible HTTP endpoint directly. The second is an MCP client: it launches the rig's own MCP server and asks through its tools.\n\n[https://github.com/xbill9/gemma-rust](https://github.com/xbill9/gemma-rust)\n\n[https://github.com/xbill9/gemma-rust-mcp](https://github.com/xbill9/gemma-rust-mcp)\n\nBoth CLIs are demos, and their output is read by an audience. So neither hides anything behind a `--verbose` flag: every run prints the target, the health check, the request, the answer, the model's reasoning, token counts, latency, and whatever the server says about itself.\n\nThey run against two very different deployments of the same model with the same code:\n\n`llama-server` on a 2021-era laptop GPU, a GTX 1650 Ti with 4 GiB, no auth\nThe interesting part is what changes when the same question goes through MCP instead of HTTP. It is not the answer.\n\nBecause they answer two different questions.\n\n**gemma-rust shows what the model said.** One HTTP call, the raw OpenAI-style response, every field printed.\n\n**gemma-rust-mcp shows what an agent sees.** An MCP client like Claude Code never touches the endpoint. It calls tools, and gets back whatever those tools choose to report. Writing a second client in Rust — one that is not Claude Code and not the Python SDK the servers were built with — is the fastest way to find out what those servers actually return.\n\nNeither one starts, stops or deploys anything. The rigs do that.\n\n```\n  gemma-rust ─────── HTTP (reqwest) ───────────────────────┐\n                                                           ├──▶  llama-server   GTX 1650 Ti, local\n                                                           │     vLLM           NVIDIA L4, Cloud Run\n  gemma-rust-mcp ─── MCP over stdio (rmcp) ──▶ server.py ──┘\n                                               (Python, the rig's own)\n```\n\nThe MCP path makes the same HTTP call in the end. It just makes it from inside a Python process that the Rust client launched, and hands back markdown instead of JSON.\n\nThe strategy for building the two clients is an incremental step by step approach.\n\nFirst, a model server is brought up locally and checked with `curl`. Then the HTTP client is built and validated against it, including the two ways Gemma 4 returns an empty answer from a healthy server. The same binary is then pointed at Cloud Run.\n\nThen the rig's Python MCP server is installed, the MCP client is built, and the same question goes through the same two servers again — which is where the comparison comes from.\n\n`nvcc`) — this one is a GTX 1650 Ti, CUDA 13.3` git`, `cmake`, a C++ compiler, and `curl`\n`hf` CLI\nUse `rustup`:\n\n```\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\nsource ~/.cargo/env\nrustc --version\nrustc 1.98.1 (48a229cea 2026-09-01)\n```\n\nAnything recent works. The floors come from the dependencies' own `rust-version`:\n\n| Crate | Needs Rust | Needed by | \n|---|---|---|\n| `reqwest` 0.13.5 | 1.85.0 | gemma-rust | \n| `clap` 4.6.6 | 1.85 | both | \n| `rmcp` 3.3.0 | 1.88 | gemma-rust-mcp | \n\nBoth crates are edition 2024.\n\n`llama-server` is the local model server. Build it from source, at the commit the rig runs:\n\n```\ngit clone https://github.com/ggml-org/llama.cpp ~/llama.cpp\ncd ~/llama.cpp\ngit checkout 95ef7fc\ncmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=75 -DCMAKE_BUILD_TYPE=Release\ncmake --build build --config Release -j --target llama-server\nls build/bin/llama-server\nbuild/bin/llama-server\n```\n\n`75` is Turing, which is what a GTX 1650 Ti is. Set your own card's compute capability there, or leave the flag off and let CMake detect it.\n\nThe rig serves Google's QAT q4_0 GGUF of Gemma 4 E2B:\n\n```\nhf auth login\nhf download google/gemma-4-E2B-it-qat-q4_0-gguf --local-dir ~/models/gemma-4-E2B-it-qat-q4_0\nls -l ~/models/gemma-4-E2B-it-qat-q4_0/\n-rw-rw-r-- 1 xbill xbill 3349516256 Sep  3 13:19 gemma-4-E2B_q4_0-it.gguf\n```\n\nIt fits a 4 GiB card because most of the file never leaves the host — the [previous article](https://dev.to/gde/gemma-4-on-an-old-4-gb-laptop-gpu-qat-takes-it-from-95-gib-to-16-b5l) measures that.\n\nRun it in the foreground; Ctrl-C is the whole teardown:\n\n```\n~/llama.cpp/build/bin/llama-server \\\n  -m ~/models/gemma-4-E2B-it-qat-q4_0/gemma-4-E2B_q4_0-it.gguf \\\n  --host 127.0.0.1 --port 8080 -ngl 99 -c 8192\n```\n\nFrom a second terminal:\n\n```\ncurl -s http://127.0.0.1:8080/health\n{\"status\":\"ok\"}\n```\n\n🟢 That is the whole server side for the local target. The rig wraps this same command as `make serve`, with its flags in `tpu.env`.\n\n```\ncd ~\ngit clone https://github.com/xbill9/gemma-rust\ncd gemma-rust\nmake prod\nBuilding release...\n    Finished `release` profile [optimized] target(s) in 0.08s\nBinary: target/release/gemma-rust\n```\n\n(That time is an incremental rebuild; a clean one compiles the dependency tree first.) The dependencies are few:\n\n```\n[dependencies]\nanyhow = \"1.0.104\"\nclap = { version = \"4.6.6\", features = [\"derive\", \"env\"] }\nreqwest = { version = \"0.13.5\", default-features = false, features = [\"blocking\", \"json\", \"rustls\"] }\nrustyline = \"18.0.1\"\nserde = { version = \"1.0.229\", features = [\"derive\"] }\nserde_json = \"1.0.151\"\n```\n\n**`blocking` is deliberate.** One question, one answer — there is nothing to run concurrently, so there is no async runtime in the client's own code.\n\nLint is the gate:\n\n```\nmake lint\nLinting code...\n    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s\n```\n\nThat is `cargo clippy --all-targets -- -D warnings` and `cargo fmt --check`. `make test` runs and finds `0 tests`: both crates are demos, validated by running them against live servers, which is what the rest of this article does.\n\n```\n./target/release/gemma-rust \"In one sentence, what is a TPU?\"\n== Target ============================================================\n  endpoint               http://127.0.0.1:8080\n  target                 local (llama.cpp rig)\n  auth                   none\n\n== Health ============================================================\n  GET /health            200 OK in 0 ms\n  body                   {\"status\":\"ok\"}\n\n== Model =============================================================\n  served                 /home/xbill/models/gemma-4-E2B-it-qat-q4_0/gemma-4-E2B_q4_0-it.gguf (context 8192 tokens)\n  using                  /home/xbill/models/gemma-4-E2B-it-qat-q4_0/gemma-4-E2B_q4_0-it.gguf (first model the server lists)\n\n== Request ===========================================================\n  POST                   http://127.0.0.1:8080/v1/chat/completions\n  prompt                 In one sentence, what is a TPU?\n  max_tokens             1024\n\n== Answer ============================================================\n  A TPU (Tensor Processing Unit) is a specialized hardware accelerator designed by Google specifically to speed up the computationally intensive matrix operations required for training and running machine learning models.\n\n== Reasoning =========================================================\n  length                 1327 chars\n  1.  **Identify the core concept:** The user wants a one-sentence definition of a TPU (Tensor Processing Unit).\n  ...\n\n== Stats =============================================================\n  finish_reason          stop\n  prompt_tokens          25\n  cached_tokens          7\n  completion_tokens      330\n  total_tokens           355\n  latency (client)       4786 ms\n  tokens/s (client)      69.0  (completion tokens / latency; includes network and prefill)\n\n== Server timings (llama.cpp) ========================================\n  predicted_ms           4615.20\n  predicted_n            330\n  predicted_per_second   71.29\n  prompt_ms              147.38\n  prompt_n               18\n  ...\n\n== Response ==========================================================\n  id                     chatcmpl-rTO4HJkYHsrE4WisG2mileq6Jmxn0R4f\n  model                  /home/xbill/models/gemma-4-E2B-it-qat-q4_0/gemma-4-E2B_q4_0-it.gguf\n  system_fingerprint     b1-95ef7fc\n```\n\n✅ A one-sentence answer, and 1,327 characters of thinking in front of it. Gemma 4 on llama.cpp reasons by default, and that is where most of the 330 completion tokens went.\n\nThree decisions make one code path work on two servers that disagree about almost everything.\n\n**The model id comes from the server.** llama.cpp accepts any `model` value; vLLM returns 404 unless it is exactly the served id. The only default that works on both is the first id from `/v1/models`:\n\n``` js\nlet model = served\n    .first()\n    .and_then(|m| m[\"id\"].as_str())\n    .context(\"the server listed no models at /v1/models; pass --model\")?\n    .to_string();\n```\n\n**Both reasoning fields are read.** The two servers put Gemma's thinking in different places:\n\n```\n#[derive(Deserialize)]\nstruct Message {\n    content: Option<String>,\n    /// Where llama.cpp puts Gemma 4's thinking\n    reasoning_content: Option<String>,\n    /// Where vLLM puts it\n    reasoning: Option<String>,\n}\n```\n\n**Server stats are optional and printed generically.** llama.cpp returns a `timings` object; vLLM returns none. Both are `Option<Value>`, and whichever is present gets its own section.\n\nAuth follows the host: `--auth auto` runs `gcloud auth print-identity-token` for `*.run.app` endpoints only, and prints the token's length, never the token.\n\n**Use `/v1/chat/completions`, never `/v1/completions`.** On these instruction-tuned checkpoints the raw completions endpoint returns empty text, which looks exactly like a broken server.\n\n**Give Gemma room to think.** On llama.cpp, `content` stays empty until the thinking closes. Starve it and see:\n\n```\n./target/release/gemma-rust --max-tokens 32 \"In one sentence, what is a TPU?\"; echo \"exit=$?\"\n== Request ===========================================================\n  POST                   http://127.0.0.1:8080/v1/chat/completions\n  prompt                 In one sentence, what is a TPU?\n  max_tokens             32\n  warning: below 512, Gemma 4 may still be reasoning when it hits the limit and return an empty answer\n\n== Answer ============================================================\n  (empty) The model was still reasoning when it stopped. This is Gemma 4 thinking, not a broken server: raise --max-tokens.\n\n== Reasoning =========================================================\n  length                 116 chars\n  1.  **Analyze the Request:** The user wants a definition of a TPU (Tensor Processing Unit) in a *single sentence*.\n  2\n\n== Stats =============================================================\n  finish_reason          length\n  The reply hit max_tokens and is cut off.\nexit=2\n```\n\n`finish_reason: length`, empty `content`, non-empty reasoning. The CLI says what happened and **exits 2**, so a script cannot mistake an empty answer for success. That is why `--max-tokens` defaults to 1024.\n\n`--status` skips the question and probes every endpoint either server might offer:\n\n```\n./target/release/gemma-rust --status\n== Server ============================================================\n  GET /version           404 Not Found (not served by this server)\n  GET /props             200 OK in 0 ms\n  llama.cpp build        b1-95ef7fc\n  model_ftype            Q4_0\n  n_ctx                  8192\n  total_slots            1\n  modalities             text only\n\n== Model details =====================================================\n  GET /v1/models         200 OK in 0 ms\n  n_ctx_train            131072\n  n_embd                 1536\n  n_params               4628569635 (4.63 B parameters)\n  size                   3333699724 (3.33 GB on disk)\n\n== Slots =============================================================\n  GET /slots             200 OK in 0 ms\n  slots                  1 (0 busy)\n\n== Metrics ===========================================================\n  GET /metrics           200 OK in 0 ms\n  predicted_tokens_seconds 67.523\n  requests_processing    0\n  ...\n```\n\n**A 404 is reported, not an error.** `/version` is vLLM's; `/props` and `/slots` are llama.cpp's. Each server answers half the probes, and the list of which ones is itself useful.\n\nSame binary, different endpoint. If you deployed the Cloud Run rig, its Makefile prints the URL:\n\n```\nGEMMA_ENDPOINT=$(make -s -C ~/gemma4-dev/gpu-2B-cloudrun-devops-agent endpoint) \\\n  ./target/release/gemma-rust \"In one sentence, what is a TPU?\"\n== Target ============================================================\n  endpoint               https://<your-service>.a.run.app\n  target                 Cloud Run\n  auth                   bearer token from gcloud auth print-identity-token (845 chars, not shown)\n\n== Health ============================================================\n  Cloud Run scales to zero: the first request can take minutes while a GPU instance starts.\n  GET /health            200 OK in 185 ms\n\n== Model =============================================================\n  served                 /mnt/models/gemma-4-E2B-it (context 16384 tokens)\n  using                  /mnt/models/gemma-4-E2B-it (first model the server lists)\n\n== Answer ============================================================\n  A TPU (Tensor Processing Unit) is a specialized integrated circuit designed to accelerate machine learning workloads, particularly those involving large matrix multiplications common in deep learning.\n\n== Reasoning =========================================================\n  (none returned)\n\n== Stats =============================================================\n  finish_reason          stop\n  prompt_tokens          18\n  cached_tokens          -\n  completion_tokens      31\n  total_tokens           49\n  latency (client)       662 ms\n  tokens/s (client)      46.8  (completion tokens / latency; includes network and prefill)\n\n== Response ==========================================================\n  id                     chatcmpl-a870c80a585e2371\n  model                  /mnt/models/gemma-4-E2B-it\n  system_fingerprint     vllm-0.26.0-a3e182ca\n```\n\n🟢 31 tokens and no reasoning — vLLM does not think by default here — so the round trip is 662 ms. The service is `--no-allow-unauthenticated`; without a token the CLI explains itself instead of dumping Google's error page:\n\n```\n  GET /health            403 Forbidden in 304 ms\n  body                   (299 bytes, not shown)\n  The server rejected the request's credentials. Cloud Run needs an identity token from an account with roles/run.invoker (`gcloud auth print-identity-token`).\n```\n\nWhat the one code path had to absorb:\n\n|  | local llama.cpp | Cloud Run vLLM 0.26 | \n|---|---|---|\n| auth | none | identity token (403 without) | \n| `model` field | any value | exact served id (404 otherwise) | \n| reasoning field | `reasoning_content` | `reasoning` | \n| thinks by default | yes | no | \n| server stats | `timings` object | none | \n| context | 8192 | 16384 | \n\nThe MCP client does not talk to the model. It launches a rig's `server.py`, so the rigs come next:\n\n```\ngit clone https://github.com/xbill9/gemma4-dev ~/gemma4-dev\nmake -C ~/gemma4-dev/local-llamacpp-1650ti-2b-q4_0 install\npython3 -c \"import importlib.metadata as m;print('mcp', m.version('mcp'))\"\nmcp 2.2.0\n```\n\nThe rig servers need `mcp>=2` — the Python SDK line where `FastMCP` became `MCPServer`. They install into the system `python3`; if yours refuses system-wide installs, use a virtualenv and point the client at it with `--python` or `GEMMA_PYTHON`.\n\nThe rig reads its model path and `llama-server` location from `tpu.env`. A real environment variable wins over that file, so set `MODEL_PATH` and `LLAMA_SERVER_BIN` if yours live somewhere else.\n\n```\ncd ~\ngit clone https://github.com/xbill9/gemma-rust-mcp\ncd gemma-rust-mcp\nmake prod\nBuilding release...\n    Finished `release` profile [optimized] target(s) in 0.04s\nBinary: target/release/gemma-rust-mcp\n```\n\nThe feature flags are the part to get right. `rmcp`'s defaults are `base64`, `macros` and `server` — a server's feature set. A client has to ask for `client` and a transport by name:\n\n```\n[dependencies]\nanyhow = \"1.0.104\"\nclap = { version = \"4.6.6\", features = [\"derive\", \"env\"] }\nrmcp = { version = \"3.3.0\", features = [\"client\", \"transport-child-process\"] }\nrustyline = \"18.0.1\"\nserde = \"1.0.229\"\nserde_json = \"1.0.151\"\ntokio = { version = \"1.53.1\", features = [\"macros\", \"rt-multi-thread\", \"process\", \"time\"] }\n```\n\n| Feature | What it brings | \n|---|---|\n| `client` | `ServiceExt::serve` on the client side,`call_tool` ,`list_all_tools` | \n| `transport-child-process` | `TokioChildProcess` : spawn a server, speak MCP over its stdin/stdout | \n\n`make lint` is clean here too, and `make test` again finds `0 tests`.\n\n**Launch the server as a child process.** The rig opens its files by relative path, so the working directory matters. Stderr is piped so the server's own log can be printed at the end:\n\n``` js\nlet mut cmd = Command::new(&args.python);\ncmd.arg(\"server.py\").current_dir(&dir);\nlet (transport, stderr) = TokioChildProcess::builder(cmd)\n    .stderr(Stdio::piped())\n    .spawn()?;\n```\n\n**Handshake.** The client handler is `()` — this client has no callbacks to offer the server:\n\n``` js\nlet client = tokio::time::timeout(timeout, ().serve(transport)).await??;\n```\n\n**List the tools**, then **call one**:\n\n``` js\nlet tools = client.list_all_tools().await?;\n\nlet params = CallToolRequestParams::new(name).with_arguments(arguments);\nlet result = client.call_tool(params).await?;\n```\n\n💡 `CallToolRequestParams` is `#[non_exhaustive]`, so a struct literal will not compile. Use the constructor and the builder method.\n\n```\n./target/release/gemma-rust-mcp \"In one sentence, what is a TPU?\"\n== MCP server ========================================================\n  rig                    local-llamacpp-1650ti-2b-q4_0\n  command                python3 server.py\n  working dir            /home/xbill/gemma4-dev/local-llamacpp-1650ti-2b-q4_0\n  transport              stdio (child process)\n  pid                    334541\n  initialize             ok in 793 ms\n\n== Server info =======================================================\n  name                   local-llamacpp-1650ti-2b-q4_0\n  version                (empty)\n  protocol               2025-11-25\n  capabilities           tools, resources, prompts\n\n== Tools =============================================================\n  tools/list             7 tools in 2 ms\n  * gpu_status           Report the local GPU: name, compute capability, VRAM total/…\n  * model_info           Report the configured checkpoint, where it is, and the resi…\n    start_model_server   Start llama-server on the local GPU. No-op if it is already…\n    stop_model_server    Stop the running llama-server. Teardown is complete — nothi…\n  * model_server_status  Check whether llama-server is up and serving at the known l…\n  * query_model          Send a chat completion to the local endpoint and return the…\n    get_help             List the tools this rig exposes.\n  (* = called by this demo, which only calls read-only tools)\n\n== tools/call gpu_status =============================================\n  arguments              {}\n  latency                14 ms\n  isError                false\n  result:\n    📡 **GPU** — `local-llamacpp-1650ti-2b-q4_0`\n    NVIDIA GeForce GTX 1650 Ti with Max-Q Design, 7.5, 4096 MiB, 1632 MiB, 2101 MiB, 615.71.09\n\n== tools/call model_server_status ====================================\n  latency                27 ms\n  result:\n    ✅ Serving at http://127.0.0.1:8080 (pid 83619). `/health` → 200.\n\n== tools/call query_model ============================================\n  arguments              {\"max_tokens\":1024,\"prompt\":\"In one sentence, what is a TPU?\"}\n  latency                4608 ms\n  isError                false\n  result:\n    ✅ **Reply**\n\n    A TPU (Tensor Processing Unit) is a specialized integrated circuit developed by Google designed to accelerate machine learning workloads, specifically the complex matrix multiplications required by neural networks, significantly speeding up training and inference.\n\n    ---\n    _(plus 1173 chars of reasoning, suppressed)_\n    prompt 25 tok · completion 326 tok · 71.3 tok/s\n\n== Server log (stderr) ===============================================\n  2026-09-11 16:27:09,682 INFO HTTP Request: GET http://127.0.0.1:8080/health \"HTTP/1.1 200 OK\"\n  2026-09-11 16:27:14,292 INFO HTTP Request: POST http://127.0.0.1:8080/v1/chat/completions \"HTTP/1.1 200 OK\"\n```\n\n✅ Same model, same kind of answer. What came back around it is completely different: the GPU and its memory, the server's health, and a reply formatted for an agent to read — with the reasoning reduced to its length.\n\nThe server log at the bottom shows the HTTP call the tool made on the client's behalf. That is the \"same servers\" arrow in the diagram, visible.\n\nThe rig servers also offer tools that start and stop the model server, and on Cloud Run, deploy, destroy and rescale a billed GPU service. The client calls a fixed list and nothing else:\n\n```\n/// Read-only tools called before the query. Never add a tool that deploys, destroys,\n/// scales, starts, or stops anything: those are billed or destructive.\nfn status_tools(self) -> &'static [&'static str] {\n    match self {\n        Rig::Local => &[\"gpu_status\", \"model_server_status\", \"model_info\"],\n        Rig::Cloudrun => &[\n            \"cloudrun_status\",\n            \"cloudrun_get_system_status\",\n            \"cloudrun_get_model_details\",\n        ],\n    }\n}\n```\n\nThere is no \"call any tool\" option, on the command line or in interactive mode. A demo that can be talked into `cloudrun_destroy` is not a demo anyone should run in front of an audience.\n\nMCP has an `isError` flag on every tool result. These rig tools never set it. They report failure as markdown that starts with `❌`, and a reasoning-only reply as markdown that starts with `📡`:\n\n```\n./target/release/gemma-rust-mcp --no-status --max-tokens 32 \"In one sentence, what is a TPU?\"; echo \"exit=$?\"\n== tools/call query_model ============================================\n  arguments              {\"max_tokens\":32,\"prompt\":\"In one sentence, what is a TPU?\"}\n  latency                499 ms\n  isError                false\n  result:\n    📡 **Reasoning only — no answer yet.** `finish_reason: length` after 32 tokens, all of them thinking.\n\n    This is Gemma 4 reasoning, not a broken server. Re-run with a larger `max_tokens` (currently 32).\n    ...\n  No answer: the model was still reasoning when it stopped. Raise --max-tokens.\nexit=2\n```\n\n`isError false`, and still not an answer. A client that trusts the protocol flag reports success here. This one reads the first character of the text, and exits 2 exactly like the HTTP client does.\n\n```\n./target/release/gemma-rust-mcp --rig cloudrun \"In one sentence, what is a TPU?\"\n== MCP server ========================================================\n  rig                    gpu-2B-cloudrun-devops-agent\n  initialize             ok in 3219 ms\n\n== Server info =======================================================\n  name                   Self-Hosted vLLM DevOps Agent\n  protocol               2025-11-25\n\n== Tools =============================================================\n  tools/list             27 tools in 2 ms\n  ...\n\n== tools/call cloudrun_query_gemma4_with_stats =======================\n  arguments              {\"prompt\":\"In one sentence, what is a TPU?\"}\n  latency                1333 ms\n  isError                false\n  result:\n    ### 📊 Performance Stats\n    - **Model:** `/mnt/models/gemma-4-E2B-it`\n    - **Time to First Token (TTFT):** `0.086s`\n    - **Total Generation Time:** `0.688s`\n    - **Tokens per Second:** `53.11 tokens/s`\n    - **Total Tokens (approx.):** `32`\n\n    ### 💬 Model Response\n    A TPU (Tensor Processing Unit) is a specialized type of integrated circuit designed to accelerate machine learning workloads, particularly those involving tensor operations common in deep learning.<turn|>\n\n== Server log (stderr) ===============================================\n  ... INFO - 📡 Automatically discovered vLLM at: https://<your-service>.a.run.app\n  2026-09-11 11:41:36,754 - httpx - INFO - HTTP Request: GET https://<your-service>.a.run.app/health \"HTTP/1.1 200 OK\"\n  2026-09-11 11:41:37,399 - httpx2 - INFO - HTTP Request: GET https://<your-service>.a.run.app/v1/models \"HTTP/1.1 200 OK\"\n  2026-09-11 11:41:37,479 - httpx2 - INFO - HTTP Request: POST https://<your-service>.a.run.app/v1/chat/completions \"HTTP/1.1 200 OK\"\n```\n\nThree things the HTTP client could not have shown:\n\n`GET /health` and a `GET /v1/models` before its `POST`. The HTTP client does those once per session; this tool does them on every call.`<turn|>`, Gemma's end-of-turn marker, leaked by the rig's streaming tool. The client prints what the tool returned — which is how the bug was found.\nThe same question, through the same two servers:\n\n|  | 🦀 gemma-rust (HTTP) | 🦀 gemma-rust-mcp (MCP) | \n|---|---|---|\n| What you get | 🥇 the raw OpenAI-style response | what the tool chooses to report, as markdown | \n| Reasoning | 🥇 full text | local: its length only; Cloud Run: none | \n| Token counts | 🥇 exact, from `usage` , incl. cached | local: exact; Cloud Run: approximate | \n| Rig status | HTTP probes of the server | 🥇 GPU, model and deployment, from the rig's tools | \n| `-i` keeps the conversation | 🥇 yes | no — the tool takes one prompt | \n| Runs on its own | 🥇 yes | needs Python 3, `mcp>=2` and the rig's`server.py` | \n\nAnd what it cost, measured:\n\n|  | 🦀 gemma-rust (HTTP) | 🦀 gemma-rust-mcp (MCP) | \n|---|---|---|\n| Local query | 4786 ms, 330 tokens | 4608 ms, 326 tokens | \n| Cloud Run query | 🥇 662 ms | 1333 ms | \n| Before the first query, Cloud Run | 🥇 185 ms `GET /health` , plus the token fetch | 3219 ms `initialize` | \n| Crates in `Cargo.lock` | 186 | 🥇 121 | \n| Release binary | 8.5M | 🥇 6.5M | \n| `src/main.rs` | 777 lines | 🥇 542 lines | \n\n**Locally, it is a tie.** 4786 ms for 330 tokens against 4608 ms for 326: the model's thinking dominates both, and one sample each cannot separate the MCP layer from the difference between one Gemma reply and the next.\n\n**On Cloud Run, the hop shows.** 1333 ms against 662 ms is 671 ms (arithmetic), roughly the two extra round trips the tool makes before it asks. Session start is where MCP really pays: 3219 ms to launch Python, import the SDK and discover the service URL through `gcloud`, before the first tool call.\n\n**The smaller crate is the MCP one**, because it speaks stdio and never opens a TLS connection. `reqwest` with `rustls` brings a TLS stack; the MCP client leaves the HTTPS to the Python server.\n\n**Use the HTTP client to see the model.** Reasoning, exact token counts, cached tokens, server timings, the raw JSON with `--raw`. When the question is \"what did Gemma do\", this is the one.\n\n**Use the MCP client to see the agent's view.** It is the fastest way to test an MCP server from outside the SDK it was written with, and it found two things no unit test did: a failure flag that is never set, and an end-of-turn marker leaking into answers.\n\nNeither half of that is about Rust being fast. The work is a model thinking on a GPU. Rust earns its place here with one static binary per client, a type for every response field, and a compiler that notices when vLLM and llama.cpp disagree about where the reasoning goes.\n\nThe goal of this article was to ask Gemma 4 E2B the same question from Rust in two ways — directly over its HTTP endpoint, and through the rig's MCP server — on a local llama.cpp GPU and on Cloud Run. The key to the solution was printing everything each path returns, which turns two small clients into a side-by-side view of what a model says and what an agent sees. The results were:\n\n`/v1/models` and reading both reasoning fields`isError` false, and the Cloud Run tool leaks Scope: one laptop with a GTX 1650 Ti Max-Q (4 GiB, driver 615.71.09) running llama.cpp `b1-95ef7fc` with the Gemma 4 E2B QAT q4_0 GGUF, and one Cloud Run service on an NVIDIA L4 running vLLM 0.26.0. One run per client per target, so each figure is a single sample and model replies vary from run to run; the local runs were captured at 16:27 on 2026-09-11 and the Cloud Run runs earlier the same day, and the HTTP and MCP runs are separate requests, not the same one observed twice. Rust 1.98.1, `rmcp` 3.3.0, `reqwest` 0.13.5, Python 3.14.7 with `mcp` 2.2.0.\n\nThe strategy for using Rust to call Gemma 4 over HTTP and over MCP was validated with an incremental step by step approach.", "url": "https://wpnews.pro/news/two-rust-clients-for-gemma-4-calling-the-endpoint-vs-calling-the-mcp-server", "canonical_source": "https://dev.to/gde/two-rust-clients-for-gemma-4-calling-the-endpoint-vs-calling-the-mcp-server-3kj4", "published_at": "2026-09-11 23:28:43+00:00", "updated_at": "2026-09-11 23:52:16.467266+00:00", "lang": "en", "topics": ["large-language-models", "ai-agents", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["Gemma 4", "Rust", "llama-server", "vLLM", "Cloud Run", "NVIDIA L4", "GTX 1650 Ti", "MCP"], "alternates": {"html": "https://wpnews.pro/news/two-rust-clients-for-gemma-4-calling-the-endpoint-vs-calling-the-mcp-server", "markdown": "https://wpnews.pro/news/two-rust-clients-for-gemma-4-calling-the-endpoint-vs-calling-the-mcp-server.md", "text": "https://wpnews.pro/news/two-rust-clients-for-gemma-4-calling-the-endpoint-vs-calling-the-mcp-server.txt", "jsonld": "https://wpnews.pro/news/two-rust-clients-for-gemma-4-calling-the-endpoint-vs-calling-the-mcp-server.jsonld"}}