Repository navigation
feat(mcp): streamable-HTTP MCP client transport in tole-core - #533
Conversation
`--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.
|
CI:
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 |
🔍 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.
|
CI:
The earlier 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.
|
Cora Review (blocking,
The earlier 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).
|
Cora Review (blocking,
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.
|
CI:
Generated by Claude Code |
What
--mcp-server name=https://host/path(and themcp_serverconfig key) now connects to a remote MCP server over Streamable HTTP, next to the existing stdio form. It lives inside the existingmcpfeature oftole-core; builds withoutmcplink 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
McpServerConfignow holdstransport: McpTransport(Stdio { command, args }|Http { url }) instead ofcommand/args. Breaking for embedders oftole-core(0.10.x, pre-1.0); noted in the CHANGELOG. New public items:mcp::{McpTransport, token_env_name}.TOLE_MCP_<NAME>_TOKENonly (name upper-cased,-becomes_), re-read on every (re)connect, sent only to that endpoint. Never accepted in a spec or config file. TheTOKENin the name also makes the existing child-env scrub drop it.parseand again at connect, because the enum is public): theurlcrate (the parser the client uses) must accept it;httpsrequired, plainhttponly forlocalhost/127.0.0.0/8/::1(lookalikes such as127.0.0.1.evil.comrefused); 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).Authorizationheader in an error body.Risk::Write, results stay capped and fenced; pre-authorize a trusted server with--allow 'mcp_<name>_*'.reqwest-tls-no-provider;ring(already in the tree viaureq) 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.rmcpfloor raised to 3.9 (RUSTSEC-2026-0462, unbounded response buffering in the HTTP client, fixed in 3.9.0); new optionalrustlsandurlunder themcpfeature (urlis already in the tree via reqwest).docs/threat-model.md(new "Remote MCP servers" section with residuals), CHANGELOG,--mcp-serverhelp 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 withoutmcpis unchanged: no reqwest, no rmcp. If this is too much, the alternative is a small client over theureqalready in the tree (more code); I kept rmcp's supported transport for now.Testing
cargo test --workspacepassescargo fmt --all -- --checkpassescargo clippy --workspace --all-targets -- -D warningspassescorais 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.crates/tole-core/tests/mcp_http.rsagainst an in-process HTTP server on loopback: token sent on every request; no token means noAuthorizationheader; 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 withoutparseis an error and the shared reactor survives. Plus parse/validation tests inmcp_tests.rsand unit tests for the scrubber inmcp.rs. Mutation checked: weakening the scrub makes the leak tests fail.httpon 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-featuresandcargo check -p tole-cli --no-default-featurespass; the iOS/Android cross-check buildstole-corewithoutmcp, so it is unaffected.Related Issues
Closes #530
Checklist
feat/)develop