Skip to main content
Glama
wonyoungseong

GA4 MCP Server

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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); } }
  • 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: [], }, },
  • Handler routing in the switch statement that maps 'ga4_account_summaries' tool calls to the getAccountSummaries() function.
    case "ga4_account_summaries": return await getAccountSummaries();
  • 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), }, ], }; }
  • 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, }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wonyoungseong/ga4-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server