#[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.
impl StructuralPartialEq for PeerAddr
Auto Trait Implementations§
impl Freeze for PeerAddr
impl RefUnwindSafe for PeerAddr
impl Send for PeerAddr
impl Sync for PeerAddr
impl Unpin for PeerAddr
impl UnsafeUnpin for PeerAddr
impl UnwindSafe for PeerAddr
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.