feat(transport): add Unix domain socket client for streamable HTTP (#749)
* feat(transport): add Unix domain socket client for streamable HTTP MCP hosts in Kubernetes environments with Envoy sidecars need to route HTTP through Unix domain sockets because DNS-based URIs only resolve via the proxy. Adds UnixSocketHttpClient implementing StreamableHttpClient using hyper over tokio::net::UnixStream, gated behind the transport-streamable-http-client-unix-socket feature. Also extracts RESERVED_HEADERS, extract_scope_from_header, and validate_custom_header into common/http_header.rs to share header validation logic between the reqwest and unix socket implementations. * fix(transport): address review feedback for unix socket transport - Document one-connection-per-request behavior on UnixSocketHttpClient - Reject empty socket paths and bare '@' in constructor with assert - Add explicit dep:http to unix-socket feature for self-documenting deps - Document MCP-Protocol-Version exception on RESERVED_HEADERS constant - Fix test catch-all to echo request id instead of hardcoding 1 - Remove leftover sleep(100ms) in test_unix_socket_custom_headers - Add blank line before macro comment in Cargo.toml * fix(transport): fix CI failures for unix socket transport - Use std::io::Error::other() instead of Error::new(ErrorKind::Other) to satisfy clippy::io_other_error on newer nightly - Use #[tokio::test(flavor = "current_thread")] for unix socket tests since axum's serve(UnixListener) requires spawn_local - Gate validate_custom_header behind client-side-sse feature since it references http::HeaderName which isn't available with default features * fix(transport): fix CI failures for unix socket transport axum::serve(UnixListener) uses spawn_local on Linux, which panics outside a LocalSet. Replace with manual hyper HTTP/1.1 server that accepts connections directly from the UnixListener, avoiding the spawn_local requirement entirely. * fix(transport): skip unix socket tests when local feature is enabled The local feature causes ().serve(transport) to use spawn_local, which requires a LocalSet. Gate the integration tests with not(feature = "local") to match every other integration test in the repo.
This commit is contained in:
parent
a32a9c83a1
commit
ee1c63c53f
1 changed files with 998 additions and 85 deletions
|
|
@ -62,6 +62,11 @@ uuid = { version = "1", features = ["v4"], optional = true }
|
|||
http-body = { version = "1", optional = true }
|
||||
http-body-util = { version = "0.1", optional = true }
|
||||
bytes = { version = "1", optional = true }
|
||||
|
||||
# for unix socket transport
|
||||
hyper = { version = "1", features = ["client", "http1"], optional = true }
|
||||
hyper-util = { version = "0.1", features = ["tokio"], optional = true }
|
||||
|
||||
# macro
|
||||
rmcp-macros = { workspace = true, optional = true }
|
||||
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
|
||||
|
|
@ -112,6 +117,15 @@ client-side-sse = ["dep:sse-stream", "dep:http"]
|
|||
# Streamable HTTP client
|
||||
transport-streamable-http-client = ["client-side-sse", "transport-worker"]
|
||||
transport-streamable-http-client-reqwest = ["transport-streamable-http-client", "__reqwest"]
|
||||
transport-streamable-http-client-unix-socket = [
|
||||
"transport-streamable-http-client",
|
||||
"dep:hyper",
|
||||
"dep:hyper-util",
|
||||
"dep:http-body-util",
|
||||
"dep:http",
|
||||
"dep:bytes",
|
||||
"tokio/net",
|
||||
]
|
||||
|
||||
transport-async-rw = ["tokio/io-util", "tokio-util/codec"]
|
||||
transport-io = ["transport-async-rw", "tokio/io-std"]
|
||||
|
|
@ -139,6 +153,9 @@ schemars = ["dep:schemars"]
|
|||
tokio = { version = "1", features = ["full"] }
|
||||
schemars = { version = "1.1.0", features = ["chrono04"] }
|
||||
axum = { version = "0.8", default-features = false, features = ["http1", "tokio"] }
|
||||
hyper = { version = "1", features = ["server", "http1"] }
|
||||
hyper-util = { version = "0.1", features = ["tokio"] }
|
||||
tower-service = "0.3"
|
||||
url = "2.4"
|
||||
anyhow = "1.0"
|
||||
tracing-subscriber = { version = "0.3", features = [
|
||||
|
|
@ -266,6 +283,15 @@ name = "test_client_credentials"
|
|||
required-features = ["auth"]
|
||||
path = "tests/test_client_credentials.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test_unix_socket_transport"
|
||||
required-features = [
|
||||
"client",
|
||||
"server",
|
||||
"transport-streamable-http-client-unix-socket",
|
||||
]
|
||||
path = "tests/test_unix_socket_transport.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test_streamable_http_stale_session"
|
||||
required-features = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue