Skip to content

feat(mcp): streamable-HTTP MCP client transport in tole-core - #533

Merged
ajianaz merged 6 commits into
developfrom
feat/mcp-http-client
Nov 10, 2026
Merged

ajianaz merged 6 commits into
developfrom
feat/mcp-http-client

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What

--mcp-server name=https://host/path (and the mcp_server config key) now connects to a remote MCP server over Streamable HTTP, next to the existing stdio form. It lives inside the existing mcp feature of tole-core; builds without mcp link no HTTP client.

Why

The MCP client could only talk to servers it spawns itself, so remote MCP servers (hosted web search/scrape, hosted memory) could not be attached without a local stdio bridge process. Closes #530.

Changes

  • McpServerConfig now holds transport: McpTransport (Stdio { command, args } | Http { url }) instead of command / args. Breaking for embedders of tole-core (0.10.x, pre-1.0); noted in the CHANGELOG. New public items: mcp::{McpTransport, token_env_name}.
  • Token: read from TOLE_MCP_<NAME>_TOKEN only (name upper-cased, - becomes _), re-read on every (re)connect, sent only to that endpoint. Never accepted in a spec or config file. The TOKEN in the name also makes the existing child-env scrub drop it.
  • Url rules (validated in parse and again at connect, because the enum is public): the url crate (the parser the client uses) must accept it; https required, plain http only for localhost / 127.0.0.0/8 / ::1 (lookalikes such as 127.0.0.1.evil.com refused); credentials, whitespace, control characters, backslashes and percent-encoded hosts refused. Cross-origin redirects are not followed (rmcp's same-origin policy, covered by a test).
  • Errors: the one funnel every reactor op passes through scrubs the token and the url (as typed, and in the normalized form the client echoes: lowercased or decoded host, elided port, path and query), including a server that echoes the Authorization header in an error body.
  • Trust model unchanged: every tool stays Risk::Write, results stay capped and fenced; pre-authorize a trusted server with --allow 'mcp_<name>_*'.
  • TLS: rmcp's reqwest transport with reqwest-tls-no-provider; ring (already in the tree via ureq) is installed once as the process provider, so aws-lc is not pulled in. A failing client build is caught and degrades to a startup warning instead of killing the shared MCP reactor thread.
  • Dependencies: rmcp floor raised to 3.9 (RUSTSEC-2026-0462, unbounded response buffering in the HTTP client, fixed in 3.9.0); new optional rustls and url under the mcp feature (url is already in the tree via reqwest).
  • Docs in the same PR: README (MCP section and tool table), docs/threat-model.md (new "Remote MCP servers" section with residuals), CHANGELOG, --mcp-server help text.

Binary size (release tole-cli, default features, measured before the rmcp 3.9 bump): 11,416,448 B before, 14,529,936 B after, so +3.1 MB (+27%). About 35 new crates (reqwest, hyper-rustls, rustls-platform-verifier, tower, ...). The tole-core tree without mcp is unchanged: no reqwest, no rmcp. If this is too much, the alternative is a small client over the ureq already in the tree (more code); I kept rmcp's supported transport for now.

Testing

  • cargo test --workspace passes
  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets -- -D warnings passes
  • Cora review run locally: not run (cora is not installed where this was written). The CI Cora Review job is the verdict; it raised two blocking findings during this PR (scrubbing of the normalized url, url validation), both addressed in follow-up commits.
  • Smoke test: 7 integration tests in crates/tole-core/tests/mcp_http.rs against an in-process HTTP server on loopback: token sent on every request; no token means no Authorization header; a 401 whose body echoes the headers leaves no token, url or host in the error; a connection error leaves no part of the typed url in the message; a cross-origin redirect target is never contacted; a dropped connection is evicted and the next call reconnects; an unparseable url built without parse is an error and the shared reactor survives. Plus parse/validation tests in mcp_tests.rs and unit tests for the scrubber in mcp.rs. Mutation checked: weakening the scrub makes the leak tests fail.
  • Not tested: a real remote server over the internet and real TLS (tests use http on loopback), and the release targets other than x86_64 Linux (macOS and Windows use platform certificate stores through rustls-platform-verifier; the release workflow will build them). cargo check -p tole-core --no-default-features and cargo check -p tole-cli --no-default-features pass; the iOS/Android cross-check builds tole-core without mcp, so it is unaffected.

Related Issues

Closes #530

Checklist

  • Branch name follows convention (feat/)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR

`--mcp-server name=https://host/path` (and the `mcp_server` config key)
now connects to a remote MCP server next to the stdio form, inside the
existing `mcp` feature. Builds without `mcp` link no HTTP client.

- Token only from TOLE_MCP_<NAME>_TOKEN, re-read on every (re)connect,
  sent only to that endpoint, never accepted in a spec or config file.
- https required (plain http only for loopback), credentials in the url
  refused, cross-origin redirects not followed (rmcp default policy).
- The token, url and host are scrubbed from every reactor error.
- Tools stay Risk::Write; pre-authorize with --allow 'mcp_<name>_*'.
- rustls without a bundled provider: `ring` (already in the tree via
  ureq) is installed once, so aws-lc is not pulled in.

API change: McpServerConfig holds `transport: McpTransport` instead of
`command`/`args`.
…#530)

- rmcp builds its default reqwest client with `.expect(..)`; a panic in
  the shared MCP reactor would take down every MCP server of the process
  (stdio ones too). Catch it and degrade to a startup warning.
- The HTTP tests set TOLE_MCP_*_TOKEN once, before any test touches the
  reactor, instead of mutating the environment from parallel threads.
- Threat model: document the case-folded token env name and the system
  proxy residuals.

ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

CI: Test failed on tui_e2e::tui_never_passes_escape_sequences_from_provider_text. This is not caused by this PR; I re-ran the failed jobs once.

  • The failure is assertion left == right failed: left: None, right: Some(0) at crates/tole-cli/tests/tui_e2e.rs:367: wait_exit() returned None, i.e. the TUI had not exited within its 10 s deadline (the test started at :16.6 and failed at :27.1, so exactly that timeout).
  • The diff touches only tole-core's MCP client, its tests, docs and Cargo.lock; the TUI path never builds an HTTP client or installs the TLS provider (that only happens when an https:// or http:// MCP server is configured, and this test configures none). The same test passes locally, alone (3 runs) and in a full cargo test --workspace.
  • Likely cause, a pre-existing race in the test itself: it sends /quit\r right after the streamed text appears, without t.idle() first. docs/tui.md says / commands are ignored while a turn runs, so on a slow runner /quit can arrive before the turn has settled and is dropped. The other TUI tests call t.idle() (waits for the idle hint) before sending a command. This fits the evidence but I have not reproduced it.
  • Proposed patch (not included in this PR, to keep it to one change): add t.idle(); before t.send("/quit\r"); in that test.

If the re-run is green I will leave it at that; if it fails again I will treat it as real and dig in further.


Generated by Claude Code

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

rmcp 3.7.0 buffers Streamable HTTP client response bodies without a
bound (RUSTSEC-2026-0462, fixed in 3.9.0). The HTTP client is exactly
what #530 turns on, so a hostile remote MCP server could exhaust memory.
Raise the floor to 3.9 and update the lockfile.

ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

CI: Cargo Audit failed, and this one is this PR's. Pushed a fix.

  • Finding: RUSTSEC-2026-0462 (medium, 6.5), "Unbounded response body buffering in Streamable HTTP clients", in rmcp 3.7.0; fixed in >= 3.9.0. The advisory is dated 2026-11-05. The vulnerable code is the HTTP client this PR enables: a hostile remote MCP server could make tole buffer an unbounded response body.
  • Fix: rmcp raised to 3.9 in crates/tole-core/Cargo.toml (so the floor is the fixed version for downstream users too) and Cargo.lock updated to rmcp 3.9.0 / rmcp-macros 3.9.0. The update also brings in sha2, digest and a few small RustCrypto crates.
  • Checked locally before pushing: cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, and the full cargo test --workspace (all green, including the new mcp_http tests and the serve/MCP tests that use the rmcp server side).
  • yoke-derive 0.8.3 (yanked) is an existing allowed warning, not part of this change.
  • Not checked: cargo audit itself (not installed here), so CI is the confirmation. tole-cli's own rmcp requirement (server side only) still says 3.3; the lockfile resolves it to 3.9.0 as well.

The earlier Test failure (tui_e2e) is the unrelated test race described above; its re-run is separate.


Generated by Claude Code

…shes (#530)

The HTTP client echoes the normalized url (lowercased host, default port
dropped), so replacing only the string the operator typed missed it:
`https://Example.COM:443/mcp` surfaced as `https://example.com/mcp`.
Scrub the url, its path and query, the authority and the bare host
case-insensitively, and refuse backslashes in the url (parsers read them
as `/`, so the validated host could differ from the contacted one).

Tests: unit tests for the scrubber, plus a real connection-refused error
whose echoed url must carry none of the typed host/path/query.

ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Cora Review (blocking, mcp.rs:246): valid, fixed.

  • Finding: scrub_err only replaced the url as typed, so a spec like https://Example.COM:443/mcp produced an error echoing the normalized https://example.com/mcp, and the host and path reached the transcript.
  • Verified, not assumed: I added a failing test first (the old scrubber leaves example.com / the query in the message), and a second test with a real connection-refused error from the client, whose text is error sending request for url (http://localhost:<port>/...). With the scrub weakened back to a literal replace that test fails and shows the leak; with the fix both pass.
  • Fix: the url, its path and query, the authority and the bare host are each scrubbed case-insensitively (replace_ci), after the as-typed forms. The token scrub is unchanged.
  • Related hardening in the same commit: a backslash in the url is refused. URL parsers read \ as /, so the host validated by validate_http_url could differ from the host actually contacted.
  • Docs: docs/threat-model.md now says the client echoes the normalized url and lists the backslash rule.
  • Checked locally: fmt, clippy -D warnings, and cargo test -p tole-core --features mcp three times in a row (398 lib tests, 6 mcp_http, 8 mcp_tests), all green.

The earlier Cargo Audit failure is already fixed (rmcp 3.9.0). The Test failure in tui_e2e is the unrelated test race described above.


Generated by Claude Code

…d forms (#530)

- validate_http_url now runs url::Url::parse, so a port above 65535, a
  `1.2.3.4.5` host and the like are config errors instead of connect-time
  client errors; the same check runs again at connect time because
  McpTransport is public.
- Percent-encoded hosts are refused: the parser decodes them, so the host
  contacted would differ from the one validated and typed.
- The transport config is built inside the catch_unwind with the client.
- scrub_err also scrubs the parsed, normalized url, host, path and query
  (decoded or rewritten hosts are echoed in that form).

ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Cora Review (blocking, mcp.rs:691): the premise is wrong, the concern is real; fixed.

  • Cora says StreamableHttpClientTransportConfig::with_uri does Url::parse(..).expect(..) and would panic outside the catch_unwind. In rmcp 3.9.0 (and 3.7.0) with_uri only stores the string (Self { uri: uri.into(), ..Default::default() }); parsing happens later, per request, and fails as an error. I also checked behaviour: a url the parser accepts but the host rejects produced an ordinary handshake error, not a panic.
  • The real gap behind the finding: validate_http_url was a hand-rolled check, so a port above 65535 (https://example.com:99999/mcp) or https://1.2.3.4.5/mcp passed config validation and failed later at connect time.
  • While checking this I found a worse case the review did not mention: https://ex%41mple.com/mcp is valid to the url parser, which decodes the host to example.com. So the host contacted was not the host validated or typed, and the scrubber (which matched the typed host) would also have missed it in an error echo.
  • Fixes (commit after 080a79e):
    • validate_http_url now runs url::Url::parse first (the parser the client uses; its errors never echo the url), so those urls are config errors at startup. It runs again at connect time, because McpTransport is public and can be built without parse.
    • Percent-encoded hosts are refused.
    • The transport config is now built inside the same catch_unwind as the client, as defence in depth even though with_uri cannot panic.
    • scrub_err also scrubs the parsed, normalized url, host, path and query (decoded or IDNA-rewritten hosts are echoed in that form).
  • Tests: parse-time rejection of the three urls; a config built without parse returns an error before any connection and the shared reactor still serves a healthy server afterwards; scrubber cases for rewritten hosts; percent-encoded hosts refused.
  • Checked locally: fmt, clippy -D warnings, cargo test -p tole-core --features mcp (400 lib tests plus all integration tests), cargo check -p tole-core --no-default-features and -p tole-cli --no-default-features.
  • New dependency: url (optional, under mcp); it is already in the tree via reqwest, so no new crate is built.

Generated by Claude Code

The MCP reactor is one per process and caches connections by server
name, so two tests registering `httpb` against different fake servers
made whichever ran second see no traffic (CI: `assert!(!fake.seen()
.is_empty())` failed in http_server_without_a_token_sends_no_authorization).
Rename the newer test's server and document the rule in the test file.

ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

CI: Test failed on mcp_http::http_server_without_a_token_sends_no_authorization (assert!(!fake.seen().is_empty())). This one is this PR's, a bug in my own test; fixed.

  • Cause: the MCP reactor is one per process and keeps connections keyed by server NAME. In the last commit I added a test that also used the name httpb, so two tests registered the same name against two different fake servers. Whichever ran second talked to the first test's cached connection and its own fake saw zero requests. Locally the no-auth test happened to run first (0 failures in 25 runs even with the duplicate name), on CI the order flipped.
  • Proven, not guessed: a scratch test that registers the same name against two fake servers shows a_seen=5 b_seen=0 every time, which is exactly the CI assertion failing. The scratch test is not committed.
  • Fix: the newer test uses its own name (httpg), and the test file now documents that every test needs a unique server name. 12 consecutive local runs of the file, all 7 tests green; fmt and clippy -D warnings clean.
  • Unrelated to this: the earlier tui_e2e failure on the previous head was the separate /quit-before-idle race described above.

Generated by Claude Code

@ajianaz
ajianaz merged commit b04ff42 into develop Nov 10, 2026
26 of 28 checks passed
@ajianaz
ajianaz deleted the feat/mcp-http-client branch November 20, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mcp): streamable-HTTP MCP client transport in tole-core (feature mcp)

2 participants