Module context

Module context 

Source
Expand description

Request context for MCP handlers.

The context provides access to the current request state and allows handlers to interact with the connection (sending notifications, progress updates, etc.).

§Key Features

  • Borrowing-friendly: Uses lifetime references, NO 'static requirement
  • Progress reporting: Send progress updates for long-running operations
  • Cancellation: Check if the request has been cancelled
  • Notifications: Send notifications back to the client via Peer trait

§Example

use mcpkit_server::{Context, NoOpPeer, ContextData};
use mcpkit_core::capability::{ClientCapabilities, ServerCapabilities};
use mcpkit_core::protocol::RequestId;

// Create test context data
let data = ContextData::new(
    RequestId::Number(1),
    ClientCapabilities::default(),
    ServerCapabilities::default(),
);
let peer = NoOpPeer;

// Create a context from the data
let ctx = Context::new(
    &data.request_id,
    data.progress_token.as_ref(),
    &data.client_caps,
    &data.server_caps,
    &peer,
);

// Check for cancellation
assert!(!ctx.is_cancelled());

Structs§

CancellationToken
A cancellation token for tracking request cancellation.
CancelledFuture
A future that completes when cancellation is requested.
Context
Request context passed to handler methods.
ContextData
Owned data for creating contexts.
NoOpPeer
A no-op peer implementation for testing.

Traits§

Peer
Trait for sending messages to the peer (client or server).