Skip to content

feat(mcp): Rust-native MCP server (slice 1 — protocol handler, headless, no Node) - #1680

Merged
joelteply merged 6 commits into
canaryfrom
feat/mcp-rust-native-server
Jun 19, 2026
Merged

joelteply merged 6 commits into
canaryfrom
feat/mcp-rust-native-server

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Why

The keystone for the unsloth integration and coding personas. The MCP server today is src/mcp-server.ts — 871 lines of Node (@modelcontextprotocol/sdk + a WebSocket client to the core) that also duplicates the tool-catalog/search/help logic already in Rust (modules/mcp.rs). It's a forbidden Node dependency in the headless command path and a compression violation. This replaces its brain with headless Rust.

Design — the MCP server IS a client

McpServer holds only a CommandDispatch verb; it does not reach into module internals ([[persona-is-a-client]]):

  • tools/list → execute("mcp/list-tools") — modules/mcp.rs stays the single source of truth (commands ARE tools).
  • tools/call → map MCP tool name → command path → execute(command, arguments).

So it's pure JSON-RPC framing over the command verb. Production dispatch = a continuum_client::Connection (gated like any caller); tests = a mock. No Node, no TS, no direct CommandExecutor coupling.

Scope (slice 1 — pure + tested)

initialize / notifications/initialized / ping / tools/list / tools/call + JSON-RPC error framing. handle_message(json) -> Option<String> (Some=request, None=notification). Handles the meta-tool hyphen exception (mcp_search_tools→mcp/search-tools), surfaces command refusals as MCP isError content (not protocol errors), and never panics on malformed JSON.

7 unit tests (initialize/list/call/meta-exception/refusal/notification/malformed) — all green.

Next (slice 2)

stdio + HTTP/SSE transport bin → wire the dispatch to a continuum_client::Connection over the core, npm-start integration, then retire src/mcp-server.ts. Needs live validation (unsloth @127.0.0.1:8888 + Claude Code).

Part of the grounded unsloth plan (UIs stay separate; brains bridge via MCP + OpenAI-compatible, both headless-Rust).

🤖 Generated with Claude Code

joelteply added a commit that referenced this pull request Jun 19, 2026
Captures the fully worked-out unsloth integration design — grounded in the live
app (127.0.0.1:8888), the docs, and HTTP-header inspection (not assumption;
unverified facts marked VERIFY). Replaces the earlier blind sketch (an agent that
never inspected unsloth, misspelled it "Unslout", branch never left its sandbox).

docs/architecture/UNSLOTH-INTEGRATION.md:
- Strategy: leverage the engine (inference/training), keep the organism
  (cognition/genome/grid/collaboration); bleeding-edge via STABLE seams only.
- License (decisive): Apache-2.0 core / AGPL-3.0 Studio UI → never source-merge
  the UI; all integration is arm's-length.
- UIs stay separate (verified DENY + frame-ancestors:none + no plugin surface);
  launch unsloth's UI as its own window from a Settings link.
- Three headless brain seams: MCP server (Rust-native, #1680), OpenAI-compatible
  provider (persona-as-model), unsloth-as-inference-backend (adapter boundary,
  not a hard dep).
- Media: capability negotiation — base64 image content-parts over /v1 (verified
  for vision GGUFs) vs the local sensory bridge (vision-describe/STT → text);
  real-time WebRTC/avatars never cross the wire (compute-lease boundary).
- Docker/grid: light persona containers (no CUDA) + one shared grid-addressable
  unsloth GPU node; personas lease ai/generate across the grid.
- Training: adopt ShareGPT JSONL + Recipes (≈ ForgeRecipe); share via Hub/HF.
- Build plan in slices (MCP slice 1 landed) + open/to-verify list.

Referenced from ARCHITECTURE-INDEX.md (quick-nav) and ALPHA-GAP-ANALYSIS.md
(new workstream 0B) so the design is discoverable from the roadmap.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
joelteply added a commit that referenced this pull request Jun 19, 2026
#1681)

Captures the fully worked-out unsloth integration design — grounded in the live
app (127.0.0.1:8888), the docs, and HTTP-header inspection (not assumption;
unverified facts marked VERIFY). Replaces the earlier blind sketch (an agent that
never inspected unsloth, misspelled it "Unslout", branch never left its sandbox).

docs/architecture/UNSLOTH-INTEGRATION.md:
- Strategy: leverage the engine (inference/training), keep the organism
  (cognition/genome/grid/collaboration); bleeding-edge via STABLE seams only.
- License (decisive): Apache-2.0 core / AGPL-3.0 Studio UI → never source-merge
  the UI; all integration is arm's-length.
- UIs stay separate (verified DENY + frame-ancestors:none + no plugin surface);
  launch unsloth's UI as its own window from a Settings link.
- Three headless brain seams: MCP server (Rust-native, #1680), OpenAI-compatible
  provider (persona-as-model), unsloth-as-inference-backend (adapter boundary,
  not a hard dep).
- Media: capability negotiation — base64 image content-parts over /v1 (verified
  for vision GGUFs) vs the local sensory bridge (vision-describe/STT → text);
  real-time WebRTC/avatars never cross the wire (compute-lease boundary).
- Docker/grid: light persona containers (no CUDA) + one shared grid-addressable
  unsloth GPU node; personas lease ai/generate across the grid.
- Training: adopt ShareGPT JSONL + Recipes (≈ ForgeRecipe); share via Hub/HF.
- Build plan in slices (MCP slice 1 landed) + open/to-verify list.

Referenced from ARCHITECTURE-INDEX.md (quick-nav) and ALPHA-GAP-ANALYSIS.md
(new workstream 0B) so the design is discoverable from the roadmap.

Co-authored-by: Claude Opus 4.8 <[email protected]>
joelteply and others added 6 commits June 19, 2026 17:38
…s, no Node)

The keystone for the unsloth bridge + coding personas: a headless-Rust MCP
server brain that replaces src/mcp-server.ts (871 lines of Node +
@modelcontextprotocol/sdk). Keeps the command path headless — an MCP client
(unsloth Studio, Claude Code) speaks JSON-RPC, this turns each call into a
continuum command dispatch, zero Node/TS in the loop.

Design: the MCP server IS a client ([[persona-is-a-client]]). McpServer holds
only a CommandDispatch verb — it does NOT reach into module internals:
  - tools/list  → execute("mcp/list-tools")  (the existing catalog in
    modules/mcp.rs stays the single source of truth — commands ARE tools)
  - tools/call  → map MCP tool name → command path → execute(command, arguments)
So it's pure JSON-RPC framing over the command verb. In production the dispatch
is a continuum_client::Connection (gated like any caller); in tests, a mock.

handle_message(json) -> Option<String>: initialize / notifications/initialized /
ping / tools/list / tools/call + JSON-RPC error framing. Some(response) for
requests, None for notifications. tool_name_to_command handles the meta-tool
hyphen exception (mcp_search_tools → mcp/search-tools) vs the general _→/ rule.
Command refusals surface as MCP isError content (model sees it), not protocol
errors. Malformed JSON → parse error, never a panic.

7 unit tests cover initialize/list/call/meta-exception/refusal/notification/
malformed — all green. Pure + transport-agnostic.

Slice 2 (next): stdio + HTTP/SSE transport bin wiring the dispatch to a
continuum_client::Connection over the core, npm-start integration, then retire
src/mcp-server.ts. Needs live validation (unsloth @127.0.0.1 + Claude Code).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ontract)

Per Joel — type it WELL so the protocol is a solid contract, not Value-soup.
Every MCP message shape is now a real serde struct, parsed in / constructed out:
  - JsonRpcRequest, JsonRpcSuccess<T>, JsonRpcErrorResponse, JsonRpcError
  - InitializeResult / ServerCapabilities / ToolsCapability / ServerInfo
  - ListToolsResult (+ CatalogResult — validates the catalog into typed MCPTool)
  - CallToolParams, CallToolResult, ContentBlock (tagged enum, text today,
    extensible to image/resource for multi-modal tool results)

Raw serde_json::Value now appears ONLY at the two genuinely-dynamic seams: a
tool call's `arguments` and a command's result payload — both per-command JSON
the protocol ferries, not interprets. So the PROTOCOL is type-checked end to end;
only the command payload it carries stays dynamic.

Bonus: tools/list now deserializes the catalog into Vec<MCPTool>, so it also
proves the catalog (modules/mcp.rs) conforms to the MCP tool shape — drift fails
loudly. New test pins missing-`name` on tools/call → typed INVALID_PARAMS.

8 tests green (added invalid-params). No new warnings.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-mcp bin

Turns the tested protocol brain (slice 1) into a live, headless MCP server.

- StdioRunner<D>: the newline-delimited-JSON stdio loop MCP clients (unsloth
  Studio, Claude Code) speak. Generic over any async reader/writer, so it's
  unit-tested end-to-end with in-memory byte streams — two requests in, two
  responses out, notifications produce no line. (MCP stdio framing is
  newline-delimited, not LSP Content-Length; serde_json emits no embedded
  newlines, so one-message-per-line holds.)
- ConnectionDispatch<T: Transport>: the production CommandDispatch — forwards
  each tools/call to the headless core over a continuum_client::Connection
  (Value→Value), so every MCP call runs the SAME gated command path any client
  uses. The MCP server IS a client ([[persona-is-a-client]]), no privileged
  bypass. Tested through a real Connection over MockTransport.
- bin/continuum-mcp.rs: thin glue — attach to the core over airc IPC
  (Airc::attach_as → Connection::connect, mirroring continuum-client-ffi),
  ConnectionDispatch → McpServer → StdioRunner::run(stdin, stdout). Env-config
  (CONTINUUM_HOME/SOCKET/PEER/AGENT), fail-loud, stdout reserved for JSON-RPC
  (diagnostics → stderr). No Node anywhere.

continuum-client added to [dev-dependencies] with test-fixtures so tests can
drive a real Connection over MockTransport; production dep unchanged.

11 MCP tests green (3 transport + 8 protocol); bin compiles.

Slice 2b (live, not blind): register continuum-mcp in npm-start build, point an
MCP client's config at it, validate against unsloth @127.0.0.1:8888 + Claude
Code, then DELETE src/mcp-server.ts (the 871-line Node server it replaces).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…tall prereq

Slice 2b wiring — makes the MCP server real on disk and the inference engine a
first-class prerequisite.

start-server.sh: build the continuum-mcp bin (same crate/manifest/features/
profile as the core, fast incremental) before launching continuum-core-server.
MCP clients (unsloth Studio, Claude Code) SPAWN this bin, so it must exist after
`npm start` — built through the npm start path per the all-bins-build-via-start
rule, NOT a raw cargo build. Non-fatal: a failed mcp build warns; the core still
launches. An MCP client config points at the built binary; it replaces the Node
src/mcp-server.ts.

install.sh: add unsloth as step [8/9] (renumbered the steps to /9), the preferred
local inference + LoRA-training engine — like airc/tailscale, a curl-installer
prereq (curl -fsSL https://unsloth.ai/install.sh | sh, verified from unsloth
docs; macOS/Linux/WSL; runs as `unsloth studio -p 8888`). Installed by default
(it's the engine) but NON-FATAL + behind the AIProviderAdapter boundary —
Continuum still runs with another provider if absent (solve-for-public-users);
idempotent (command -v unsloth); skip with CONTINUUM_NO_UNSLOTH=1.

Validation: scripts pass `bash -n`; continuum-mcp bin builds (verified this
session). install.sh's full fresh-machine path is exercised by carl-install-smoke
CI, not runnable in this env — flagged for that gate.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…runbook

Makes the MCP server zero-config — the reliability win. With the core running,
continuum-mcp auto-discovers it via continuum_core::airc::discover() (the same
liveness probe the core uses): socket + peer_id resolved automatically, no manual
UUID/socket lookup (that lookup was the friction that bred unreliability). The
MCP client config is just `command: "continuum-mcp"`. Every value stays
overridable via env (CONTINUUM_SOCKET/PEER/HOME/AGENT); discovery fails LOUD if no
healthy core is found (so a bad target errors, never hangs).

docs/infrastructure/MCP-SERVER-HOOKUP.md: turnkey runbook — build (via npm start),
the MCP client config JSON (Claude Code / unsloth Studio), verify steps (incl. a
stdio smoke one-liner), troubleshooting, and §5 the gated retirement plan for the
Node src/mcp-server.ts (delete only AFTER live-green, as its own reversible
commit).

Bin compiles; 14 MCP module tests green. Live end-to-end (against the running
core + unsloth @127.0.0.1:8888 / Claude Code) is the slice-2b validation step —
the runbook is the script for it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
#21)

Live finding (2026-06-19): continuum-mcp's initialize round-tripped but
tools/list/call timed out — the sidecar and core are the SAME machine-account
peer, so a command addressed "to that peer" over airc never routed back to the
core's handler. A LOCAL sidecar must speak the core's IPC socket directly.

CoreIpcTransport (runtime/): a continuum_client::Transport over the core's Unix
IPC socket — newline-JSON request (params flattened with command+requestId) in,
length-prefixed JSON frame out, mirroring ipc/mod.rs. TYPED wire structs
(IpcRequest/IpcResponse) per "encode into structs, not magic" — no json! poking.
Lazy connect + reconnect-on-error; 64MB frame cap; success→result,
{success:false,error}→ClientError::Refused (so the MCP layer surfaces it as
isError, never hangs). Event/serve verbs are typed NotImplemented (follow-up).

continuum-mcp rewired to CoreIpcTransport against CONTINUUM_CORE_SOCKET (default
/tmp/continuum-core.sock) — simpler + airc-independent than the prior
discover()/attach path, and it removes the self-peer bug. Cross-grid MCP (remote
core over airc, a distinct peer) is a later path.

Tests exercise the transport against a REAL in-test IPC server speaking the
actual wire codec (not a mock of itself): round-trip + refusal→Refused +
non-object-params rejection. Fixed a test-isolation flake (per-instance unique
socket path; parallel tests had collided on a pid-only path). 3/3 stable.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@joelteply
joelteply force-pushed the feat/mcp-rust-native-server branch from 1d0e334 to 9b30257 Compare June 19, 2026 22:41
@joelteply
joelteply merged commit c3c288a into canary Jun 19, 2026
4 of 5 checks passed
@joelteply
joelteply deleted the feat/mcp-rust-native-server branch June 19, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant