LLMProvider

Trait LLMProvider 

Source
pub trait LLMProvider:
    Send
    + Sync
    + Debug {
    // Required methods
    fn name(&self) -> &str;
    fn generate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: &'life1 LLMRequest,
    ) -> Pin<Box<dyn Future<Output = LLMResult<LLMResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list_models<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = LLMResult<Vec<ModelInfo>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn capabilities(&self) -> &LLMCapabilities;

    // Provided methods
    fn version(&self) -> &str { ... }
    fn get_model_info<'life0, 'life1, 'async_trait>(
        &'life0 self,
        model: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = LLMResult<ModelInfo>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn supports_model<'life0, 'life1, 'async_trait>(
        &'life0 self,
        model: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn estimate_tokens(&self, text: &str) -> usize { ... }
    fn validate_request<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: &'life1 LLMRequest,
    ) -> Pin<Box<dyn Future<Output = LLMResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = LLMResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn handle_create_message<'life0, 'async_trait>(
        &'life0 self,
        request: CreateMessageRequest,
    ) -> Pin<Box<dyn Future<Output = LLMResult<CreateMessageResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Core trait for LLM providers

Implement this trait to add support for new LLM providers. The trait provides a standardized interface for generating text, managing models, and handling provider-specific functionality.

§Examples

use turbomcp_client::llm::{LLMProvider, LLMRequest, LLMResponse, LLMResult, ModelInfo, LLMCapabilities};
use async_trait::async_trait;

#[derive(Debug)]
struct CustomProvider;

#[async_trait]
impl LLMProvider for CustomProvider {
    fn name(&self) -> &str {
        "custom"
    }

    async fn generate(&self, request: &LLMRequest) -> LLMResult<LLMResponse> {
        // Implementation here
        todo!()
    }

    async fn list_models(&self) -> LLMResult<Vec<ModelInfo>> {
        // Return available models
        todo!()
    }

    fn capabilities(&self) -> &LLMCapabilities {
        // Return provider capabilities
        todo!()
    }
}

Required Methods§

Source

fn name(&self) -> &str

Provider name (e.g., “openai”, “anthropic”)

Source

fn generate<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 LLMRequest, ) -> Pin<Box<dyn Future<Output = LLMResult<LLMResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generate a response for the given request

This is the core method that handles text generation. Implementations should convert the request to the provider’s format, make the API call, and return a standardized response.

Source

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

List available models for this provider

Source

fn capabilities(&self) -> &LLMCapabilities

Get provider capabilities

Provided Methods§

Source

fn version(&self) -> &str

Provider version

Source

fn get_model_info<'life0, 'life1, 'async_trait>( &'life0 self, model: &'life1 str, ) -> Pin<Box<dyn Future<Output = LLMResult<ModelInfo>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get information about a specific model

Source

fn supports_model<'life0, 'life1, 'async_trait>( &'life0 self, model: &'life1 str, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check if a model is supported

Source

fn estimate_tokens(&self, text: &str) -> usize

Estimate token count for text (optional override)

Source

fn validate_request<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 LLMRequest, ) -> Pin<Box<dyn Future<Output = LLMResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Validate a request before sending

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = LLMResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Health check for the provider

Source

fn handle_create_message<'life0, 'async_trait>( &'life0 self, request: CreateMessageRequest, ) -> Pin<Box<dyn Future<Output = LLMResult<CreateMessageResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle MCP CreateMessageRequest (adapts to LLM types)

This method provides a bridge between MCP protocol types and the LLM system. It converts CreateMessageRequest to LLMRequest, calls generate(), and converts the response back to CreateMessageResult.

Implementors§