systemprompt-mcp 0.36.0

Native Model Context Protocol (MCP) implementation for systemprompt.io. Orchestration, per-server OAuth2, RBAC middleware, and tool-call governance — the core of the AI governance pipeline.
Documentation
//! Persisted service-state transitions for MCP server orchestration.
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.

use crate::error::McpDomainResult;
use systemprompt_database::ServiceRepository;

use super::models::McpServiceState;

#[derive(Debug, Clone)]
pub struct ServiceStateService {
    service_repo: ServiceRepository,
}

impl ServiceStateService {
    pub const fn new(service_repo: ServiceRepository) -> Self {
        Self { service_repo }
    }

    pub async fn get_mcp_service(&self, name: &str) -> McpDomainResult<Option<McpServiceState>> {
        let service = self.service_repo.find_service_by_name(name).await?;
        Ok(service.map(|s| McpServiceState {
            name: s.name,
            host: "127.0.0.1".to_owned(),
            port: s.port as u16,
            status: s.status,
        }))
    }

    pub async fn list_mcp_services(&self) -> McpDomainResult<Vec<McpServiceState>> {
        let services = self.service_repo.list_mcp_services().await?;
        Ok(services
            .into_iter()
            .map(|s| McpServiceState {
                name: s.name,
                host: "127.0.0.1".to_owned(),
                port: s.port as u16,
                status: s.status,
            })
            .collect())
    }

    pub async fn list_running_mcp_services(&self) -> McpDomainResult<Vec<McpServiceState>> {
        let services = self.service_repo.list_mcp_services().await?;
        Ok(services
            .into_iter()
            .filter(|s| s.status == "running")
            .map(|s| McpServiceState {
                name: s.name,
                host: "127.0.0.1".to_owned(),
                port: s.port as u16,
                status: s.status,
            })
            .collect())
    }
}