#[non_exhaustive]pub struct PeerAddr {
pub addr: SocketAddr,
}Expand description
Direct socket peer address of the current HTTP/TLS connection.
Inserted as a request extension into every request served by serve —
on both the plain and the TLS listener — and extractable in any axum
handler, including routes mounted via
McpServerConfig::with_extra_router (which bypass auth/RBAC and
therefore often need the peer address for their own protection, e.g.
per-IP rate limiting).
The same address is also mirrored into
axum::extract::ConnectInfo<SocketAddr> on the TLS listener, so
third-party middleware that expects the stock axum extension (e.g.
per-IP rate-limit key extractors) works unmodified under TLS.
§Semantics
- Direct peer only. This is the socket’s remote address. Behind an
L4/L7 proxy or load balancer it is the proxy’s address; the framework
performs no
X-Forwarded-For/Forwardedinterpretation. - Available on HTTP and TLS transports alike (
serve). - Absent under
serve_stdio— a stdio session has no network peer (stdio bypasses the HTTP stack entirely). - The separate Prometheus metrics listener (feature
metrics) is a different router and does not carry this extension.
§Privacy
PeerAddr exposes raw peer network metadata. The framework deliberately
never logs it on its own; whether to log or persist peer addresses is
application policy.
§Example
use axum::{Router, routing::get};
use rmcp_server_kit::transport::{McpServerConfig, PeerAddr};
async fn whoami(peer: PeerAddr) -> String {
peer.addr.ip().to_string()
}
let _config = McpServerConfig::new("127.0.0.1:8443", "my-server", "1.0.0")
.with_extra_router(Router::new().route("/whoami", get(whoami)));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.addr: SocketAddrDirect socket peer of this connection.
Trait Implementations§
impl Copy for PeerAddr
impl Eq for PeerAddr
Source§impl<S: Send + Sync> FromRequestParts<S> for PeerAddr
Extract PeerAddr from request extensions.
impl<S: Send + Sync> FromRequestParts<S> for PeerAddr
Extract PeerAddr from request extensions.