Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(mcp-bridge): give the streamable-HTTP client a TLS backend (#497)

Abhishek Sharma7aa268f4c681
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65e4540d..b0234f72 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -177,6 +177,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
exists rather than reading one from a file ai-memory would have to write and
protect.
+- Gave `ai-memory mcp-bridge` a TLS backend so it can reach an `https://` MCP
+ server. `ai-memory-cli` enabled rmcp's `transport-streamable-http-client-reqwest`
+ feature, which pulls reqwest in via `__reqwest = ["dep:reqwest"]` and stops
+ there — no `rustls`, no `native-tls`, no TLS at all. reqwest with no TLS
+ feature refuses any non-`http` scheme, so every bridge run against an HTTPS
+ server URL failed at connect with `invalid URL, scheme is not http`, and the
+ only URL that worked was plaintext `http://` — which is also the transport
+ the bridge attaches its bearer token to. Enabling rmcp's `reqwest` feature
+ the bridge now uses rmcp's `reqwest-tls-no-provider`
+ (`reqwest?/rustls-no-provider`), which supplies the platform certificate
+ verifier without pinning a crypto provider, and installs `ring` — already
+ compiled for this binary via the workspace's reqwest 0.12 — as the process
+ default. rmcp's plain `reqwest` feature would have pinned `aws-lc-rs`,
+ adding a compiled C dependency to every build for a bridge most users never
+ enable. The workspace-client half of #492 landed in #496; this is the MCP
+ transport, which is a second, independent copy of reqwest ([#497]).
+
### Docs
- `docs/windows.md` gains **Scenario E**, a persistent-server story for native
diff --git a/Cargo.lock b/Cargo.lock
index b76998bc..0d4aefc6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -56,6 +56,7 @@ dependencies = [
"jsonc-parser",
"reqwest 0.12.28",
"rmcp",
+ "rustls",
"secrecy",
"serde",
"serde_json",
@@ -654,6 +655,16 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
+[[package]]
+name = "combine"
+version = "4.6.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd"
+dependencies = [
+ "bytes",
+ "memchr",
+]
+
[[package]]
name = "convert_case"
version = "0.10.0"
@@ -1618,6 +1629,55 @@ dependencies = [
"jiff-tzdb",
]
+[[package]]
+name = "jni"
+version = "0.22.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498"
+dependencies = [
+ "cfg-if",
+ "combine",
+ "jni-macros",
+ "jni-sys",
+ "log",
+ "simd_cesu8",
+ "thiserror 2.0.18",
+ "walkdir",
+ "windows-link",
+]
+
+[[package]]
+name = "jni-macros"
+version = "0.22.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "rustc_version",
+ "simd_cesu8",
+ "syn",
+]
+
+[[package]]
+name = "jni-sys"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2"
+dependencies = [
+ "jni-sys-macros",
+]
+
+[[package]]
+name = "jni-sys-macros"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264"
+dependencies = [
+ "quote",
+ "syn",
+]
+
[[package]]
name = "jobserver"
version = "0.1.34"
@@ -2427,15 +2487,20 @@ dependencies = [
"http-body",
"http-body-util",
"hyper",
+ "hyper-rustls",
"hyper-util",
"js-sys",
"log",
"percent-encoding",
"pin-project-lite",
+ "rustls",
+ "rustls-pki-types",
+ "rustls-platform-verifier",
"serde",
"serde_json",
"sync_wrapper",
"tokio",
+ "tokio-rustls",
"tokio-util",
"tower",
"tower-http",
@@ -2554,6 +2619,7 @@ version = "0.23.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b"
dependencies = [
+ "log",
"once_cell",
"ring",
"rustls-pki-types",
@@ -2584,6 +2650,33 @@ dependencies = [
"zeroize",
]
+[[package]]
+name = "rustls-platform-verifier"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "26d1e2536ce4f35f4846aa13bff16bd0ff40157cdb14cc056c7b14ba41233ba0"
+dependencies = [
+ "core-foundation",
+ "core-foundation-sys",
+ "jni",
+ "log",
+ "once_cell",
+ "rustls",
+ "rustls-native-certs",
+ "rustls-platform-verifier-android",
+ "rustls-webpki",
+ "security-framework",
+ "security-framework-sys",
+ "webpki-root-certs",
+ "windows-sys 0.52.0",
+]
+
+[[package]]
+name = "rustls-platform-verifier-android"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f"
+
[[package]]
name = "rustls-webpki"
version = "0.103.13"
@@ -2865,6 +2958,22 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
+[[package]]
+name = "simd_cesu8"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520"
+dependencies = [
+ "rustc_version",
+ "simdutf8",
+]
+
+[[package]]
+name = "simdutf8"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
+
[[package]]
name = "siphasher"
version = "1.0.3"
@@ -3641,6 +3750,15 @@ dependencies = [
"wasm-bindgen",
]
+[[package]]
+name = "webpki-root-certs"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b"
+dependencies = [
+ "rustls-pki-types",
+]
+
[[package]]
name = "winapi"
version = "0.3.9"
diff --git a/Cargo.toml b/Cargo.toml
index bd93ca61..51d2ae06 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -109,6 +109,11 @@ fs2 = "0.4"
winapi-util = "0.1"
# MCP server SDK.
+# Only used to install a process-wide crypto provider for the MCP bridge's HTTPS
+# transport. `default-features = false` is load-bearing: rustls' default set includes
+# `aws_lc_rs`, which is exactly the C/JNI toolchain the bridge avoids by using
+# rmcp's `reqwest-tls-no-provider`. `ring` is already in the lockfile via reqwest 0.12.
+rustls = { version = "0.23", default-features = false, features = ["ring", "logging", "std", "tls12"] }
rmcp = { version = "1.7", features = ["server", "macros", "transport-io", "transport-streamable-http-server", "schemars"] }
schemars = "1"
axum = "0.8"
diff --git a/crates/ai-memory-cli/Cargo.toml b/crates/ai-memory-cli/Cargo.toml
index 280bb4a9..e6d206b2 100644
--- a/crates/ai-memory-cli/Cargo.toml
+++ b/crates/ai-memory-cli/Cargo.toml
@@ -35,7 +35,29 @@ dirs.workspace = true
figment.workspace = true
flate2.workspace = true
fs2.workspace = true
-rmcp = { workspace = true, features = ["client", "transport-streamable-http-client-reqwest"] }
+# `transport-streamable-http-client-reqwest` pulls reqwest in with no TLS backend
+# (`__reqwest = ["dep:reqwest"]` and nothing more), so the bridge could not reach an
+# `https://` MCP server at all.
+#
+# `reqwest-tls-no-provider` is `reqwest?/rustls-no-provider`: the platform verifier
+# without a pinned crypto provider. rmcp's plain `reqwest` feature would be
+# `reqwest?/rustls`, which additionally pins aws-lc-rs — and with it a C toolchain
+# (cmake/nasm on Windows) in every build of this workspace. `ring` is already in the
+# lockfile via the reqwest 0.12 the rest of the workspace uses, so the bridge
+# installs that as the process default instead (see `install_crypto_provider` in
+# `commands/mcp_bridge.rs`).
+#
+# The crypto provider is the whole of the difference. Both routes go through
+# `rustls-platform-verifier`, so both put its deps — including `jni` and
+# `rustls-platform-verifier-android` — in the lockfile. Those are target-gated and
+# are not compiled for our platforms, but they are not avoided by this choice, and
+# a comment claiming otherwise would misdirect the next TLS decision here.
+rmcp = { workspace = true, features = [
+ "client",
+ "transport-streamable-http-client-reqwest",
+ "reqwest-tls-no-provider",
+] }
+rustls = { workspace = true }
serde.workspace = true
serde_json.workspace = true
toml_edit.workspace = true
diff --git a/crates/ai-memory-cli/src/commands/mcp_bridge.rs b/crates/ai-memory-cli/src/commands/mcp_bridge.rs
index 3927d7ad..61b255ff 100644
--- a/crates/ai-memory-cli/src/commands/mcp_bridge.rs
+++ b/crates/ai-memory-cli/src/commands/mcp_bridge.rs
@@ -85,6 +85,29 @@ fn upstream_config(
/// # Errors
/// Returns an error when Claude did not provide a lifecycle session id, the
/// upstream HTTP MCP server cannot initialize, or either transport fails.
+/// Install a process-wide rustls crypto provider before the bridge opens an HTTPS
+/// transport.
+///
+/// The bridge uses rmcp's `reqwest-tls-no-provider`, which supplies the platform
+/// certificate verifier without pinning a crypto provider — that is what keeps
+/// aws-lc-rs, and the C toolchain and Android JNI stack it needs, out of every build
+/// of this workspace. The trade is that rustls then has no default provider of its
+/// own, and without one the first `https://` request fails inside the handshake with
+/// an error that does not name the cause. `ring` is already compiled for this binary
+/// via the reqwest 0.12 the rest of the workspace uses, so install that.
+fn install_crypto_provider() -> Result<()> {
+ // `Err` means another component installed a provider first, which is fine — the
+ // postcondition we need is only that *some* provider is present.
+ let _ = rustls::crypto::ring::default_provider().install_default();
+ if rustls::crypto::CryptoProvider::get_default().is_none() {
+ anyhow::bail!(
+ "failed to install a rustls crypto provider; the MCP bridge cannot open an \
+ https:// connection without one"
+ );
+ }
+ Ok(())
+}
+
pub async fn run(config: &Config, args: McpBridgeArgs) -> Result<()> {
let session_id = config.runtime_env.claude_code_session_id().context(
"CLAUDE_CODE_SESSION_ID is missing; this bridge must be launched by Claude Code as an stdio MCP server",
@@ -94,6 +117,8 @@ pub async fn run(config: &Config, args: McpBridgeArgs) -> Result<()> {
.as_deref()
.map(mcp_server_url_from_base)
.unwrap_or_else(|| mcp_server_url_from_base(&config.server_url));
+ install_crypto_provider()?;
+
let transport = StreamableHttpClientTransport::from_config(upstream_config(
&server_url,
session_id,
@@ -130,6 +155,17 @@ pub async fn run(config: &Config, args: McpBridgeArgs) -> Result<()> {
#[cfg(test)]
mod tests {
+
+ #[test]
+ fn install_crypto_provider_is_idempotent_and_leaves_a_default() {
+ // The bridge builds its transport with `reqwest-tls-no-provider`, so rustls has
+ // no provider of its own. Both calls must succeed and a default must be present
+ // afterwards — the second models another component having installed one first.
+ super::install_crypto_provider().expect("first install");
+ assert!(rustls::crypto::CryptoProvider::get_default().is_some());
+ super::install_crypto_provider().expect("second install must not fail");
+ assert!(rustls::crypto::CryptoProvider::get_default().is_some());
+ }
use super::*;
use std::sync::{Arc, Mutex};
diff --git a/docs/https-via-proxy.md b/docs/https-via-proxy.md
index 9cacd92b..39d1bd85 100644
--- a/docs/https-via-proxy.md
+++ b/docs/https-via-proxy.md
@@ -447,3 +447,16 @@ If you can't take one of these paths cleanly, the honest answer is
already trust." The configuration that gives operators the wrong
mental model — looking secure, not being secure — is worse than
either.
+
+## The session-aware MCP bridge and HTTPS
+
+`ai-memory mcp-bridge` reaches `https://` server URLs. Earlier releases could not:
+its transport pulled in a second `reqwest` with no TLS backend compiled, so any
+non-`http` scheme was refused before a connection was attempted. If you front
+ai-memory with a TLS-terminating proxy as described above, point the bridge at the
+proxied `https://` URL directly — a second, local proxy on each client machine is
+not needed.
+
+The bridge uses the platform certificate verifier, so it trusts the same roots the
+operating system does. A certificate the OS does not trust — a self-signed one, or a
+private CA that has not been installed into the system trust store — is rejected.