Skip to content

Move API calls in to mcp-common #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 1 addition & 35 deletions apps/workers-observability/src/tools/account.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
import { z } from "zod";
import type { MyMCP } from "../index";

const AccountSchema = z.object({
id: z.string(),
name: z.string(),
created_on: z.string(),
});
type AccountsListResponseSchema = z.infer<typeof AccountsListResponseSchema>;
const AccountsListResponseSchema = z.object({
result: z.array(AccountSchema),
success: z.boolean(),
errors: z.array(z.any()),
messages: z.array(z.any()),
});

export async function handleAccountsList({
apiToken,
}: {
apiToken: string;
}): Promise<AccountsListResponseSchema["result"]> {
// Currently limited to 50 accounts
const response = await fetch("https://api.cloudflare.com/client/v4/accounts?per_page=50", {
method: "GET",
headers: {
Authorization: `Bearer ${apiToken}`,
Accept: "application/javascript",
},
});

if (!response.ok) {
const error = await response.text();
throw new Error(`Cloudflare API request failed: ${error}`);
}

return AccountsListResponseSchema.parse(await response.json()).result;
}
import { handleAccountsList } from "@repo/mcp-common/src/api/account"

export function registerAccountTools(agent: MyMCP) {
// Tool to list all accounts
Expand Down
Loading