rig-mcp-server 0.47.10

Serve Rig agents and tools over the Model Context Protocol (MCP): agents as tools with sessions, streamed progress and cancellation; typed agents with structured output; stdio and Streamable HTTP.
Documentation
//! Argument completion: what a completer is asked, and the boxed error it may return.

use std::collections::HashMap;
use std::sync::Arc;

use futures::future::BoxFuture;

/// The error a completer returns, boxed. It is logged by kind only and never
/// sent to the client.
pub(crate) type BoxError = Box<dyn std::error::Error + Send + Sync>;

/// The function a server awaits for `completion/complete`.
pub(crate) type Completer = Arc<
    dyn Fn(CompletionRequest) -> BoxFuture<'static, Result<Vec<String>, BoxError>> + Send + Sync,
>;

/// What a client asks completions for.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum CompletionTarget {
    /// An argument of the prompt with this name.
    Prompt(String),
    /// A resource, by the URI the server serves it at, or a resource template,
    /// by its URI template (such as `memo://{id}`); the argument is then a variable.
    Resource(String),
}

/// One `completion/complete` request, as a completer sees it.
///
/// Build one with [`CompletionRequest::new`] to call a completer directly in a
/// unit test.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct CompletionRequest {
    /// The prompt or resource the argument belongs to.
    pub target: CompletionTarget,
    /// The name of the argument being completed.
    pub argument: String,
    /// What the client has typed for the argument so far.
    pub value: String,
    /// The arguments the client has already resolved, by name. Empty when the
    /// client sent no context.
    pub context: HashMap<String, String>,
}

impl CompletionRequest {
    /// A request for `argument` of `target`, with the value typed so far and the
    /// arguments already resolved.
    pub fn new(
        target: CompletionTarget,
        argument: impl Into<String>,
        value: impl Into<String>,
        context: HashMap<String, String>,
    ) -> Self {
        Self {
            target,
            argument: argument.into(),
            value: value.into(),
            context,
        }
    }
}