Skip to main content

pmcp/shared/
mod.rs

1//! Shared components used by both client and server.
2
3pub mod batch;
4pub mod context;
5pub mod event_store;
6pub mod http_utils;
7pub mod logging;
8pub mod middleware;
9pub mod middleware_presets;
10/// Peer back-channel trait for server-to-client RPCs from inside request handlers.
11#[cfg(not(target_arch = "wasm32"))]
12pub mod peer;
13/// Target-agnostic one-slot pending-response buffer for one-shot transports.
14///
15/// Internal plumbing (`pub(crate)`) backing the `WasmHttpTransport`
16/// send→receive correlation; ungated so it host-tests under plain `cargo test`.
17pub(crate) mod pending_slot;
18/// Target-agnostic PKCE (RFC 7636) crypto helper (verifier/challenge/state).
19///
20/// Ungated on purpose — compiles on host AND wasm32 via `getrandom::fill`
21/// (contrast the `#[cfg(not(target_arch = "wasm32"))]` peer/stdio entries).
22pub mod pkce;
23pub mod protocol;
24pub mod protocol_helpers;
25#[cfg(not(target_arch = "wasm32"))]
26pub mod reconnect;
27pub mod session;
28pub mod simd_parsing;
29pub mod sse_parser;
30
31#[cfg(feature = "sse")]
32pub mod sse_optimized;
33
34#[cfg(not(target_arch = "wasm32"))]
35pub mod connection_pool;
36#[cfg(not(target_arch = "wasm32"))]
37pub mod stdio;
38pub mod transport;
39pub mod uri_template;
40
41// Cross-platform runtime abstraction
42pub mod runtime;
43
44// Platform-specific WebSocket modules
45#[cfg(all(feature = "websocket", not(target_arch = "wasm32")))]
46pub mod websocket;
47
48#[cfg(all(feature = "websocket-wasm", target_arch = "wasm32"))]
49pub mod wasm_websocket;
50
51#[cfg(target_arch = "wasm32")]
52pub mod wasm_http;
53
54#[cfg(all(feature = "http", not(target_arch = "wasm32")))]
55pub mod http;
56pub mod http_constants;
57
58#[cfg(all(feature = "streamable-http", not(target_arch = "wasm32")))]
59/// Streamable HTTP transport implementation for MCP.
60pub mod streamable_http;
61
62// Re-export commonly used types
63pub use batch::{BatchRequest, BatchResponse};
64pub use context::{ClientInfo, ContextPropagator, RequestContext};
65pub use event_store::{
66    EventStore, EventStoreConfig, InMemoryEventStore, MessageDirection, ResumptionManager,
67    ResumptionState, ResumptionToken, StoredEvent,
68};
69#[cfg(all(not(target_arch = "wasm32"), feature = "logging"))]
70pub use logging::init_logging;
71pub use logging::{CorrelatedLogger, LogConfig, LogEntry, LogFormat, LogLevel};
72pub use middleware::{
73    AdvancedMiddleware, AuthMiddleware, CircuitBreakerMiddleware, CompressionMiddleware,
74    CompressionType, EnhancedMiddlewareChain, LoggingMiddleware, MetricsMiddleware, Middleware,
75    MiddlewareChain, MiddlewareContext, MiddlewarePriority, PerformanceMetrics,
76    RateLimitMiddleware, RetryMiddleware,
77};
78pub use protocol::{ProgressCallback, Protocol, ProtocolOptions, RequestOptions};
79pub use protocol_helpers::{
80    create_notification, create_request, parse_notification, parse_request,
81};
82#[cfg(not(target_arch = "wasm32"))]
83pub use reconnect::{ReconnectConfig, ReconnectGuard, ReconnectManager};
84pub use session::{Session, SessionConfig, SessionManager};
85#[cfg(not(target_arch = "wasm32"))]
86pub use stdio::StdioTransport;
87pub use transport::{Transport, TransportMessage};
88pub use uri_template::UriTemplate;
89
90#[cfg(all(feature = "websocket", not(target_arch = "wasm32")))]
91pub use websocket::{WebSocketConfig, WebSocketTransport};
92
93#[cfg(all(feature = "websocket-wasm", target_arch = "wasm32"))]
94pub use wasm_websocket::{WasmWebSocketConfig, WasmWebSocketTransport};
95
96#[cfg(target_arch = "wasm32")]
97pub use wasm_http::{WasmHttpClient, WasmHttpConfig, WasmHttpTransport};
98
99#[cfg(all(feature = "http", not(target_arch = "wasm32")))]
100pub use http::{HttpConfig, HttpTransport};
101
102#[cfg(all(feature = "streamable-http", not(target_arch = "wasm32")))]
103pub use streamable_http::{StreamableHttpTransport, StreamableHttpTransportConfig};
104
105#[cfg(feature = "sse")]
106pub use sse_optimized::{OptimizedSseConfig, OptimizedSseTransport};
107
108#[cfg(not(target_arch = "wasm32"))]
109pub use connection_pool::{
110    ConnectionId, ConnectionPool, ConnectionPoolConfig, HealthStatus, LoadBalanceStrategy,
111    PoolStats, PooledTransport,
112};
113
114pub use simd_parsing::{
115    CpuFeatures, ParsingMetrics, SimdBase64, SimdHttpHeaderParser, SimdJsonParser, SimdSseParser,
116};