RootsHandler

Trait RootsHandler 

Source
pub trait RootsHandler:
    Send
    + Sync
    + Debug {
    // Required method
    fn handle_roots_request<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = HandlerResult<Vec<Root>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Roots handler for responding to server requests for filesystem roots

Per MCP 2025-06-18 specification, roots/list is a SERVER->CLIENT request. Servers ask clients what filesystem roots (directories/files) they have access to. This is commonly used when servers need to understand their operating boundaries, such as which repositories or project directories they can access.

§Examples

use turbomcp_client::handlers::{RootsHandler, HandlerResult};
use turbomcp_protocol::types::Root;
use async_trait::async_trait;

#[derive(Debug)]
struct MyRootsHandler {
    project_dirs: Vec<String>,
}

#[async_trait]
impl RootsHandler for MyRootsHandler {
    async fn handle_roots_request(&self) -> HandlerResult<Vec<Root>> {
        Ok(self.project_dirs
            .iter()
            .map(|dir| Root {
                uri: format!("file://{}", dir).into(),
                name: Some(dir.split('/').last().unwrap_or("").to_string()),
            })
            .collect())
    }
}

Required Methods§

Source

fn handle_roots_request<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = HandlerResult<Vec<Root>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a roots/list request from the server

This method is called when the server wants to know which filesystem roots the client has available. The implementation should return a list of Root objects representing directories or files the server can operate on.

§Returns

Returns a vector of Root objects, each with a URI (must start with file://) and optional human-readable name.

§Note

Per MCP specification, URIs must start with file:// for now. This restriction may be relaxed in future protocol versions.

Implementors§