aion-server 0.30.0

Aion workflow server library: HTTP, gRPC, WebSocket, and worker endpoints. Run it with the `aion` binary from the aion-cli crate.
Documentation
//! The assistant MCP runtime: the protocol server and its construction.

use std::sync::Arc;

use aion_mcp::protocol::meta::Implementation;
use aion_mcp::{McpServer, McpServerConfig};

use crate::config::ResolvedMcpConfig;
use crate::{ServerError, ServerState};

use super::service::AssistantToolService;

/// The assistant MCP server, constructed once at startup.
pub(crate) struct AssistantMcpRuntime {
    server: McpServer<AssistantToolService>,
}

impl AssistantMcpRuntime {
    /// Build the runtime.
    ///
    /// The protocol-layer knobs (cache TTLs, poll interval, allowed origins) are
    /// read from the SAME `[mcp]` section the general route uses, deliberately:
    /// they describe how this server speaks MCP, not which catalogue is behind
    /// it, and a second set of them would be a second thing to keep in step for
    /// no gain. The section's `enabled` switch is NOT read here — it governs the
    /// general catalogue, and darkening the workflow tools must not take the
    /// assistant's own context tool away from its own agent.
    ///
    /// # Errors
    ///
    /// [`ServerError::Config`] when the published tool schema fails to compile.
    pub(crate) fn build(
        state: ServerState,
        config: &ResolvedMcpConfig,
    ) -> Result<Self, ServerError> {
        let service = AssistantToolService::new(state).map_err(|error| ServerError::Config {
            message: format!("the assistant MCP tool catalog is invalid: {error}"),
        })?;
        Ok(Self {
            server: McpServer::new(
                Arc::new(service),
                McpServerConfig::new(
                    Implementation::new("aion-assistant", env!("CARGO_PKG_VERSION")),
                    config.discover_ttl_ms,
                    config.tools_list_ttl_ms,
                    config.task_poll_interval_ms,
                    config.allowed_origins.clone(),
                ),
            ),
        })
    }

    /// The protocol server.
    pub(crate) const fn server(&self) -> &McpServer<AssistantToolService> {
        &self.server
    }
}