Skip to main content

aion_server/mcp/
runtime.rs

1//! The MCP runtime: the server object and its construction from config.
2
3use std::sync::Arc;
4
5use aion_mcp::protocol::meta::Implementation;
6use aion_mcp::{McpServer, McpServerConfig};
7
8use crate::config::ResolvedMcpConfig;
9use crate::{ServerError, ServerState};
10
11use super::service::AionToolService;
12
13/// The MCP server plus everything it needs, constructed once at startup.
14pub struct McpRuntime {
15    server: McpServer<AionToolService>,
16}
17
18impl McpRuntime {
19    /// Build the runtime from validated configuration.
20    ///
21    /// The advertised server identity is this binary's own name and version —
22    /// self-reported, unverified, and used for nothing but display, exactly as
23    /// the revision says such an identity must be.
24    ///
25    /// # Errors
26    ///
27    /// [`ServerError::Config`] when a published tool schema fails to compile.
28    pub fn build(state: ServerState, config: &ResolvedMcpConfig) -> Result<Self, ServerError> {
29        let service = AionToolService::new(state)?;
30        let server = McpServer::new(
31            Arc::new(service),
32            McpServerConfig::new(
33                Implementation::new("aion", env!("CARGO_PKG_VERSION")),
34                config.discover_ttl_ms,
35                config.tools_list_ttl_ms,
36                config.task_poll_interval_ms,
37                config.allowed_origins.clone(),
38            ),
39        );
40        Ok(Self { server })
41    }
42
43    /// The MCP server.
44    pub(crate) const fn server(&self) -> &McpServer<AionToolService> {
45        &self.server
46    }
47}