Skip to main content

Crate mcp_session

Crate mcp_session 

Source
Expand description

Bounded session management for MCP servers.

This crate provides BoundedSessionManager, a wrapper around rmcp’s LocalSessionManager that enforces:

  • Maximum concurrent sessions with FIFO eviction of the oldest session when the limit is reached.
  • Optional rate limiting on session creation via a sliding-window counter.
  • Idle timeout via rmcp’s keep_alive configuration (passed through).

§Quick start

use std::sync::Arc;
use mcp_session::BoundedSessionManager;
use mcp_session::SessionConfig;

let mut session_config = SessionConfig::default();
session_config.keep_alive = Some(std::time::Duration::from_secs(4 * 60 * 60));

let manager = Arc::new(
    BoundedSessionManager::new(session_config, 100)
        .with_rate_limit(10, std::time::Duration::from_secs(60)),
);

// Pass `manager` to `StreamableHttpService::new(factory, manager, config)`

Structs§

BoundedSessionManager
Wraps LocalSessionManager and limits the number of concurrent sessions.
SessionConfig

Enums§

BoundedSessionError
Errors returned by BoundedSessionManager.

Type Aliases§

SessionId