|
| 1 | +import { z } from "zod"; |
| 2 | +import { tool } from "../../tool.js"; |
| 3 | +import { toContent } from "../../util.js"; |
| 4 | +import { getFirebaseProjectPage } from "../../../management/projects.js"; |
| 5 | + |
| 6 | +const PROJECT_LIST_PAGE_SIZE = 20; |
| 7 | + |
| 8 | +export const list_projects = tool( |
| 9 | + { |
| 10 | + name: "list_projects", |
| 11 | + description: "Retrieves a list of Firebase projects up to the specified total count.", |
| 12 | + inputSchema: z.object({ |
| 13 | + page_size: z |
| 14 | + .number() |
| 15 | + .min(1) |
| 16 | + .default(PROJECT_LIST_PAGE_SIZE) |
| 17 | + .describe("the number of projects to list per page (defaults to 1000)"), |
| 18 | + page_token: z.string().optional().describe("the page token to start listing from"), |
| 19 | + }), |
| 20 | + annotations: { |
| 21 | + title: "List Firebase Projects", |
| 22 | + readOnlyHint: true, |
| 23 | + idempotentHint: true, |
| 24 | + }, |
| 25 | + _meta: { |
| 26 | + requiresAuth: true, |
| 27 | + }, |
| 28 | + }, |
| 29 | + async ({ page_size, page_token }) => { |
| 30 | + try { |
| 31 | + const projectPage = await getFirebaseProjectPage(page_size, page_token); |
| 32 | + |
| 33 | + return toContent( |
| 34 | + { |
| 35 | + projects: projectPage.projects, |
| 36 | + next_page_token: projectPage.nextPageToken, |
| 37 | + }, |
| 38 | + { |
| 39 | + contentPrefix: `Here are ${projectPage.projects.length} Firebase projects${page_token ? " (continued)" : ""}:\n\n`, |
| 40 | + contentSuffix: projectPage.nextPageToken |
| 41 | + ? "\nThere are more projects available. To see the next page, call this tool again with the next_page_token shown above." |
| 42 | + : "", |
| 43 | + }, |
| 44 | + ); |
| 45 | + } catch (err: any) { |
| 46 | + const originalMessage = err.original ? `: ${err.original.message}` : ""; |
| 47 | + throw new Error(`Failed to list Firebase projects${originalMessage}`); |
| 48 | + } |
| 49 | + }, |
| 50 | +); |
0 commit comments