pub struct StreamableHttpTransport { /* private fields */ }mcp only.Expand description
Streamable-HTTP MCP transport.
Construct with StreamableHttpTransport::new for a live connection, or
StreamableHttpTransport::with_poster to inject a custom HttpPoster
(used by tests).
Implementations§
Source§impl StreamableHttpTransport
impl StreamableHttpTransport
Sourcepub fn new(endpoint: impl Into<String>, auth: McpAuth) -> Result<Arc<Self>>
pub fn new(endpoint: impl Into<String>, auth: McpAuth) -> Result<Arc<Self>>
Create a transport that talks to endpoint over real HTTP.
§Errors
Returns an error if the underlying HTTP client cannot be built.
Sourcepub fn with_timeout(
endpoint: impl Into<String>,
auth: McpAuth,
request_timeout: Duration,
) -> Result<Arc<Self>>
pub fn with_timeout( endpoint: impl Into<String>, auth: McpAuth, request_timeout: Duration, ) -> Result<Arc<Self>>
Create a transport over real HTTP with a custom per-request timeout.
Sets both the underlying reqwest client’s request timeout and the
transport-level send deadline to request_timeout, so a slow or hung
streamable-HTTP server trips this deadline instead of the
DEFAULT_SEND_DEADLINE / DEFAULT_HTTP_TIMEOUT defaults. MCP tool
calls routinely exceed 60s (builds, codegen); raise the timeout for
those servers, or lower it for latency-sensitive ones.
§Errors
Returns an error if the underlying HTTP client cannot be built.
Sourcepub fn with_poster(poster: Arc<dyn HttpPoster>, auth: McpAuth) -> Arc<Self>
pub fn with_poster(poster: Arc<dyn HttpPoster>, auth: McpAuth) -> Arc<Self>
Create a transport backed by a custom HttpPoster.
This is the seam tests use to script JSON / SSE responses without a network.
Sourcepub fn builder(endpoint: impl Into<String>, auth: McpAuth) -> Result<Self>
pub fn builder(endpoint: impl Into<String>, auth: McpAuth) -> Result<Self>
Create an un-wrapped transport over real HTTP for further builder-style
configuration (e.g. StreamableHttpTransport::with_header).
The backing reqwest client uses DEFAULT_HTTP_TIMEOUT and the
transport uses DEFAULT_SEND_DEADLINE. To raise the request timeout
past the default minute (e.g. for long builds / codegen), use
StreamableHttpTransport::builder_with_timeout — calling
StreamableHttpTransport::with_request_timeout on a builder produced
here only relaxes the send deadline and cannot lift the client’s own
DEFAULT_HTTP_TIMEOUT (see its docs).
Wrap the result in Arc before handing it to McpClient::new:
use std::sync::Arc;
use agent_sdk::mcp::{McpAuth, StreamableHttpTransport};
let transport = Arc::new(
StreamableHttpTransport::builder("https://example.com/mcp", McpAuth::None)?
.with_header("X-Tenant-Id", "acme"),
);§Errors
Returns an error if the underlying HTTP client cannot be built.
Sourcepub fn builder_with_timeout(
endpoint: impl Into<String>,
auth: McpAuth,
request_timeout: Duration,
) -> Result<Self>
pub fn builder_with_timeout( endpoint: impl Into<String>, auth: McpAuth, request_timeout: Duration, ) -> Result<Self>
Create an un-wrapped transport over real HTTP with a custom request
timeout, for further builder-style configuration before wrapping in
Arc.
Sets both the backing reqwest client’s request timeout and the
transport-level send deadline to request_timeout. This is the path to
use when raising the timeout past DEFAULT_HTTP_TIMEOUT: building
the client with the higher timeout is the only way a long-running tool
call (build, codegen) can run past the default minute — chaining
StreamableHttpTransport::with_request_timeout onto a plain
StreamableHttpTransport::builder cannot, because the underlying
reqwest client was already built with DEFAULT_HTTP_TIMEOUT.
Mirrors StreamableHttpTransport::with_timeout but returns an
un-wrapped transport so callers can chain
StreamableHttpTransport::with_header before wrapping in Arc:
use std::sync::Arc;
use std::time::Duration;
use agent_sdk::mcp::{McpAuth, StreamableHttpTransport};
let transport = Arc::new(
StreamableHttpTransport::builder_with_timeout(
"https://example.com/mcp",
McpAuth::None,
Duration::from_secs(300),
)?
.with_header("X-Tenant-Id", "acme"),
);§Errors
Returns an error if the underlying HTTP client cannot be built.
Sourcepub fn with_poster_owned(poster: Arc<dyn HttpPoster>, auth: McpAuth) -> Self
pub fn with_poster_owned(poster: Arc<dyn HttpPoster>, auth: McpAuth) -> Self
Create an un-wrapped transport backed by a custom HttpPoster, for
further builder-style configuration before wrapping in Arc.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Add a static custom header sent on every request (e.g. a tenant id).
Call this on an un-wrapped transport from StreamableHttpTransport::builder
(or StreamableHttpTransport::with_poster_owned) before wrapping it in
Arc.
Sourcepub fn with_request_timeout(self, request_timeout: Duration) -> Self
pub fn with_request_timeout(self, request_timeout: Duration) -> Self
Set the overall per-request send deadline (default
DEFAULT_SEND_DEADLINE).
This bounds every McpTransport::send / send_notification call
regardless of the underlying HttpPoster’s own timeout, so a custom
poster (or a ReqwestPoster whose client timeout is longer) still has
a guaranteed cancellation path. Call it on an un-wrapped transport from
StreamableHttpTransport::builder or
StreamableHttpTransport::with_poster_owned before wrapping in Arc.
§This never raises the bound past the backing poster’s own timeout
The effective per-request bound is the minimum of this send deadline
and the backing HttpPoster’s own timeout. For a ReqwestPoster
built via StreamableHttpTransport::builder /
ReqwestPoster::new, that client timeout is DEFAULT_HTTP_TIMEOUT
(60s), so:
- Lowering works:
with_request_timeout(Duration::from_secs(5))trips the send deadline at 5s, well before the client’s 60s. - Raising does not work here:
with_request_timeout(Duration::from_secs(300))leaves the send deadline at 300s but the client still aborts the request at its own 60sDEFAULT_HTTP_TIMEOUT. To genuinely raise the timeout, build the transport withStreamableHttpTransport::builder_with_timeout(orStreamableHttpTransport::with_timeout), which configures both the reqwest client timeout and this send deadline together.