Skip to main content
Glama

mcp-server-cloudflare

Official
by cloudflare
dex-analytics.tools.ts3.44 kB
import { z } from 'zod' import { getCloudflareClient } from '@repo/mcp-common/src/cloudflare-api' import { getProps } from '@repo/mcp-common/src/get-props' import type { AccountGetParams } from 'cloudflare/resources/accounts/accounts.mjs' import type { ReportGetParams } from 'cloudflare/resources/dns/analytics.mjs' import type { ZoneGetParams } from 'cloudflare/resources/dns/settings.mjs' import type { DNSAnalyticsMCP } from '../dns-analytics.app' function getStartDate(days: number) { const today = new Date() const start_date = new Date(today.setDate(today.getDate() - days)) return start_date.toISOString() } export function registerAnalyticTools(agent: DNSAnalyticsMCP) { // Register DNS Report tool agent.server.tool( 'dns_report', 'Fetch the DNS Report for a given zone since a date', { zone: z.string(), days: z.number(), }, async ({ zone, days }) => { try { const props = getProps(agent) const client = getCloudflareClient(props.accessToken) const start_date = getStartDate(days) const params: ReportGetParams = { zone_id: zone, metrics: 'responseTimeAvg,queryCount,uncachedCount,staleCount', dimensions: 'responseCode,responseCached', since: start_date, } const result = await client.dns.analytics.reports.get(params) return { content: [ { type: 'text', text: JSON.stringify({ result, }), }, ], } } catch (error) { return { content: [ { type: 'text', text: `Error fetching DNS report: ${error instanceof Error && error.message}`, }, ], } } } ) // Register Account DNS Settings display tool agent.server.tool( 'show_account_dns_settings', 'Show DNS settings for current account', async () => { try { const accountId = await agent.getActiveAccountId() if (!accountId) { return { content: [ { type: 'text', text: 'No currently active accountId. Try listing your accounts (accounts_list) and then setting an active account (set_active_account)', }, ], } } const props = getProps(agent) const client = getCloudflareClient(props.accessToken) const params: AccountGetParams = { account_id: accountId, } const result = await client.dns.settings.account.get(params) return { content: [ { type: 'text', text: JSON.stringify({ result, }), }, ], } } catch (error) { return { content: [ { type: 'text', text: `Error fetching DNS report: ${error instanceof Error && error.message}`, }, ], } } } ) // Register Zone DNS Settings display tool agent.server.tool( 'show_zone_dns_settings', 'Show DNS settings for a zone', { zone: z.string(), }, async ({ zone }) => { try { const props = getProps(agent) const client = getCloudflareClient(props.accessToken) const params: ZoneGetParams = { zone_id: zone, } const result = await client.dns.settings.zone.get(params) return { content: [ { type: 'text', text: JSON.stringify({ result, }), }, ], } } catch (error) { return { content: [ { type: 'text', text: `Error fetching DNS report: ${error instanceof Error && error.message}`, }, ], } } } ) }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cloudflare/mcp-server-cloudflare'

If you have feedback or need assistance with the MCP directory API, please join our Discord server