Skip to main content

dnslib/mcp/tools/
logs.rs

1use rmcp::{ErrorData as McpError, model::*};
2
3use crate::{
4    control_plane::policy::Policy,
5    core::dns::{logs, service::DnsService},
6    mcp::{helpers::run_json, params::LogsParams},
7};
8
9pub async fn handle_logs<C: DnsService + Send + Sync>(
10    client: &C,
11    policy: &Policy,
12    params: LogsParams,
13) -> Result<CallToolResult, McpError> {
14    Ok(run_json("dns_logs", policy.check_read(), async move {
15        let lines = logs::get_logs(client, params.into()).await?;
16        serde_json::to_value(lines).map_err(|err| {
17            crate::core::error::Error::parse(format!("failed to serialize logs: {err}"))
18        })
19    })
20    .await)
21}