Skip to content

Commit 44e96f9

Browse files
committed
Use MCP common zones_list tool
1 parent 361ab3d commit 44e96f9

File tree

3 files changed

+12
-59
lines changed

3 files changed

+12
-59
lines changed

apps/dns-analytics/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Currently available tools:
1111

1212
| **Category** | **Tool** | **Description** |
1313
| ----------------------- | --------------------------- | -------------------------------------------------------------- |
14-
| **DNS Analytics** | `dns-report` | Fetch the DNS Report for a given zone over a given time frame. |
15-
| **Account DNS Setting** | `show-account-dns-settings` | Fetch the DNS setting for the current active account. |
16-
| **Zone DNS Setting** | `show-zone-dns-settings` | Fetch the DNS setting for a given zone. |
17-
| **Zone Information** | `list-zones-under-account` | List zones under the current active account. |
14+
| **Zone Information** | `zones_list` | List zones under the current active account. |
15+
| **DNS Analytics** | `dns_report` | Fetch the DNS Report for a given zone over a given time frame. |
16+
| **Account DNS Setting** | `show_account_dns_settings` | Fetch the DNS setting for the current active account. |
17+
| **Zone DNS Setting** | `show_zone_dns_settings` | Fetch the DNS setting for a given zone. |
1818

1919
This MCP server is still a work in progress, and we plan to add more tools in the future.
2020

apps/dns-analytics/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { getEnv } from '@repo/mcp-common/src/env'
1111
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
1212
import { CloudflareMCPServer } from '@repo/mcp-common/src/server'
1313
import { registerAccountTools } from '@repo/mcp-common/src/tools/account'
14+
import { registerZoneTools } from '@repo/mcp-common/src/tools/zone'
1415

1516
import { MetricsTracker } from '../../../packages/mcp-observability/src'
1617
import { registerAnalyticTools } from './tools/analytics'
@@ -63,8 +64,10 @@ export class DNSAnalyticsMCP extends McpAgent<Env, State, Props> {
6364

6465
registerAccountTools(this)
6566

66-
// Register Cloudflare DNS Analytic tools
67+
// Register Cloudflare DNS Analytics tools
6768
registerAnalyticTools(this)
69+
70+
registerZoneTools(this)
6871
}
6972

7073
async getActiveAccountId() {
@@ -89,11 +92,10 @@ export class DNSAnalyticsMCP extends McpAgent<Env, State, Props> {
8992
}
9093
}
9194

92-
// TODO: Add scopes for `dns_settings:read` and `dns_analytics:read` when they are ready.
93-
// Also remove `DEV_CLOUDFLARE_API_TOKEN` env var.
9495
const AnalyticsScopes = {
9596
...RequiredScopes,
9697
'account:read': 'See your account info such as account details, analytics, and memberships.',
98+
'zone:read': "See your zones",
9799
'dns_settings:read': 'See your DNS settings',
98100
'dns_analytics:read': 'See your DNS analytics',
99101
} as const

apps/dns-analytics/src/tools/analytics.ts

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { getEnv } from '@repo/mcp-common/src/env'
66
import type { AccountGetParams } from 'cloudflare/resources/accounts/accounts.mjs'
77
import type { ReportGetParams } from 'cloudflare/resources/dns/analytics.mjs'
88
import type { ZoneGetParams } from 'cloudflare/resources/dns/settings.mjs'
9-
import type { ZoneListParams } from 'cloudflare/resources/zones/zones.mjs'
109
import type { Env } from '../context'
1110
import type { DNSAnalyticsMCP } from '../index'
1211

@@ -21,7 +20,7 @@ function getStartDate(days: number) {
2120
export function registerAnalyticTools(agent: DNSAnalyticsMCP) {
2221
// Register DNS Report tool
2322
agent.server.tool(
24-
'dns-report',
23+
'dns_report',
2524
'Fetch the DNS Report for a given zone since a date',
2625
{
2726
zone: z.string(),
@@ -62,7 +61,7 @@ export function registerAnalyticTools(agent: DNSAnalyticsMCP) {
6261
)
6362
// Register Account DNS Settings display tool
6463
agent.server.tool(
65-
'show-account-dns-settings',
64+
'show_account_dns_settings',
6665
'Show DNS settings for current account',
6766
async () => {
6867
try {
@@ -106,7 +105,7 @@ export function registerAnalyticTools(agent: DNSAnalyticsMCP) {
106105
)
107106
// Register Zone DNS Settings display tool
108107
agent.server.tool(
109-
'show-zone-dns-settings',
108+
'show_zone_dns_settings',
110109
'Show DNS settings for a zone',
111110
{
112111
zone: z.string(),
@@ -140,52 +139,4 @@ export function registerAnalyticTools(agent: DNSAnalyticsMCP) {
140139
}
141140
}
142141
)
143-
144-
// Register Zone DNS Settings display tool
145-
agent.server.tool(
146-
'list-zones-under-account',
147-
'List zones under the current active account',
148-
async () => {
149-
try {
150-
const client = getCloudflareClient(agent.props.accessToken)
151-
const accountId = await agent.getActiveAccountId()
152-
if (!accountId) {
153-
return {
154-
content: [
155-
{
156-
type: 'text',
157-
text: 'No currently active accountId. Try listing your accounts (accounts_list) and then setting an active account (set_active_account)',
158-
},
159-
],
160-
}
161-
}
162-
const zone_list_account: ZoneListParams.Account = {
163-
id: accountId,
164-
}
165-
const zone_list_params: ZoneListParams = {
166-
account: zone_list_account,
167-
}
168-
const result = await client.zones.list(zone_list_params)
169-
return {
170-
content: [
171-
{
172-
type: 'text',
173-
text: JSON.stringify({
174-
result,
175-
}),
176-
},
177-
],
178-
}
179-
} catch (error) {
180-
return {
181-
content: [
182-
{
183-
type: 'text',
184-
text: `Error fetching DNS report: ${error instanceof Error && error.message}`,
185-
},
186-
],
187-
}
188-
}
189-
}
190-
)
191142
}

0 commit comments

Comments
 (0)