ga4_account_summaries
Retrieve a list of all Google Analytics 4 accounts and their properties accessible to the authenticated user. This tool helps users quickly identify available GA4 resources for reporting and management.
Instructions
Retrieves information about the user's Google Analytics accounts and properties. Returns a list of all GA4 accounts and their associated properties that the authenticated user has access to.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/admin.ts:16-42 (handler)The getAccountSummaries function implements the actual tool logic. It retrieves account summaries from Google Analytics Admin API using pagination, collects all summaries, and returns a success response with the count and data.export async function getAccountSummaries(): Promise<ToolResponse> { try { const client = await getAnalyticsAdminClient(); const allSummaries: unknown[] = []; let pageToken: string | undefined | null = undefined; do { const response: { data: AccountSummariesResponse } = await client.accountSummaries.list({ pageToken: pageToken || undefined, pageSize: 200, }); const data = response.data; if (data.accountSummaries) { allSummaries.push(...data.accountSummaries); } pageToken = data.nextPageToken; } while (pageToken); return createSuccessResponse({ accountSummaries: allSummaries, totalCount: allSummaries.length, }); } catch (error) { return createErrorResponse("Failed to get account summaries", error); } }
- src/tools/index.ts:32-39 (registration)Tool registration and schema definition for ga4_account_summaries. Defines the tool name, description, and input schema (which has no required properties).name: "ga4_account_summaries", description: "Retrieves information about the user's Google Analytics accounts and properties. Returns a list of all GA4 accounts and their associated properties that the authenticated user has access to.", inputSchema: { type: "object" as const, properties: {}, required: [], }, },
- src/tools/index.ts:256-257 (registration)Handler routing in the switch statement that maps 'ga4_account_summaries' tool calls to the getAccountSummaries() function.case "ga4_account_summaries": return await getAccountSummaries();
- src/utils/helpers.ts:46-55 (helper)createSuccessResponse helper function used by getAccountSummaries to format the successful MCP response with JSON data.export function createSuccessResponse(data: unknown): ToolResponse { return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; }
- src/utils/helpers.ts:60-82 (helper)createErrorResponse helper function used by getAccountSummaries to format error responses with detailed error messages.export function createErrorResponse(message: string, error?: unknown): ToolResponse { let errorMessage = message; if (error) { if (error instanceof Error) { errorMessage += `: ${error.message}`; } else if (typeof error === "string") { errorMessage += `: ${error}`; } else { errorMessage += `: ${JSON.stringify(error)}`; } } return { content: [ { type: "text", text: errorMessage, }, ], isError: true, }; }