Skip to content

Commit b84cd41

Browse files
committed
Move API calls in to mcp-common
1 parent 628d00d commit b84cd41

31 files changed

+4162
-629
lines changed

apps/workers-observability/src/tools/account.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,6 @@
11
import { z } from "zod";
22
import type { MyMCP } from "../index";
3-
4-
const AccountSchema = z.object({
5-
id: z.string(),
6-
name: z.string(),
7-
created_on: z.string(),
8-
});
9-
type AccountsListResponseSchema = z.infer<typeof AccountsListResponseSchema>;
10-
const AccountsListResponseSchema = z.object({
11-
result: z.array(AccountSchema),
12-
success: z.boolean(),
13-
errors: z.array(z.any()),
14-
messages: z.array(z.any()),
15-
});
16-
17-
export async function handleAccountsList({
18-
apiToken,
19-
}: {
20-
apiToken: string;
21-
}): Promise<AccountsListResponseSchema["result"]> {
22-
// Currently limited to 50 accounts
23-
const response = await fetch("https://api.cloudflare.com/client/v4/accounts?per_page=50", {
24-
method: "GET",
25-
headers: {
26-
Authorization: `Bearer ${apiToken}`,
27-
Accept: "application/javascript",
28-
},
29-
});
30-
31-
if (!response.ok) {
32-
const error = await response.text();
33-
throw new Error(`Cloudflare API request failed: ${error}`);
34-
}
35-
36-
return AccountsListResponseSchema.parse(await response.json()).result;
37-
}
3+
import { handleAccountsList } from "@repo/mcp-common/src/api/account"
384

395
export function registerAccountTools(agent: MyMCP) {
406
// Tool to list all accounts

0 commit comments

Comments
 (0)