Skip to main content
Glama

list_accounts

Retrieve Google Analytics 4 accounts and properties to identify which property ID to use for data analysis.

Instructions

GA4のアカウントとプロパティの一覧を取得します。どのプロパティIDを使うべきか確認する際に便利です。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function that fetches and processes GA4 accounts and their properties using the admin client, returning structured output.
    export async function listAccounts(): Promise<ListAccountsOutput> { const client = getAdminClient(); const accounts: Account[] = []; // アカウント一覧を取得 const [accountsResponse] = await client.listAccounts({}); for (const account of accountsResponse || []) { if (!account.name || !account.displayName) continue; const accountId = account.name.replace("accounts/", ""); const accountData: Account = { accountId, accountName: account.displayName, properties: [], }; // このアカウントのプロパティ一覧を取得 try { const [propertiesResponse] = await client.listProperties({ filter: `parent:accounts/${accountId}`, }); for (const property of propertiesResponse || []) { if (!property.name || !property.displayName) continue; accountData.properties.push({ propertyId: extractPropertyId(property.name), propertyName: property.displayName, }); } } catch (error) { // プロパティの取得に失敗しても続行 console.error(`Failed to fetch properties for account ${accountId}:`, error); } accounts.push(accountData); } return { accounts }; }
  • src/server.ts:62-71 (registration)
    Registers the list_accounts tool in the MCP server's tools array, including name, description, and input schema (empty object).
    { name: "list_accounts", description: "GA4のアカウントとプロパティの一覧を取得します。どのプロパティIDを使うべきか確認する際に便利です。", inputSchema: { type: "object" as const, properties: {}, required: [], }, },
  • Defines the output schema for list_accounts tool, including Account, Property interfaces and ListAccountsOutput type.
    // list_accounts export interface Account { accountId: string; accountName: string; properties: Property[]; } export interface Property { propertyId: string; propertyName: string; } export interface ListAccountsOutput { accounts: Account[]; }
  • src/server.ts:571-572 (registration)
    Dispatches the list_accounts tool call to the listAccounts handler function in the server's handleToolCall switch statement.
    case "list_accounts": return await listAccounts();
  • Re-exports the listAccounts function for easy import from the basic tools index.
    export { listAccounts } from "./listAccounts.js";

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/Shin-sibainu/ga4-mcp-server'

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