Skip to main content

dnslib/mcp/tools/
cache.rs

1use rmcp::{ErrorData as McpError, model::*};
2
3use crate::{
4    control_plane::policy::Policy,
5    core::dns::cache,
6    core::dns::service::DnsService,
7    mcp::{helpers::run_json, params::DomainParams},
8};
9
10pub async fn handle_list_cache<C: DnsService + Send + Sync>(
11    client: &C,
12    policy: &Policy,
13    p: DomainParams,
14) -> Result<CallToolResult, McpError> {
15    Ok(run_json(
16        "dns_list_cache",
17        policy.check_read(),
18        cache::list_cache(client, &p.domain),
19    )
20    .await)
21}
22
23pub async fn handle_delete_cache_zone<C: DnsService + Send + Sync>(
24    client: &C,
25    policy: &Policy,
26    p: DomainParams,
27) -> Result<CallToolResult, McpError> {
28    Ok(run_json(
29        "dns_delete_cache_zone",
30        policy.check_delete(),
31        cache::delete_cache_zone(client, &p.domain),
32    )
33    .await)
34}
35
36pub async fn handle_flush_cache<C: DnsService + Send + Sync>(
37    client: &C,
38    policy: &Policy,
39) -> Result<CallToolResult, McpError> {
40    Ok(run_json(
41        "dns_flush_cache",
42        policy.check_write(),
43        cache::flush_cache(client),
44    )
45    .await)
46}