Skip to main content
Glama
Shin-sibainu

GA4 MCP Server

by Shin-sibainu

get_geo_breakdown

Retrieve geographic breakdown analysis from Google Analytics 4 data by country or city to understand regional traffic patterns and user distribution.

Instructions

地域別(国または市区町村)のアクセス分析結果を取得します。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdNoGA4プロパティID
periodYes集計期間
levelYes地域レベル
limitNo取得件数(デフォルト: 10)

Implementation Reference

  • The main asynchronous handler function that implements the core logic for the get_geo_breakdown tool, querying GA4 for geographic breakdown data by country or city.
    export async function getGeoBreakdown(
      input: GetGeoBreakdownInput
    ): Promise<GetGeoBreakdownOutput> {
      const propertyId = getPropertyId(input.propertyId);
      const property = formatPropertyPath(propertyId);
      const dateRange = periodToDateRange(input.period);
      const limit = input.limit || 10;
    
      // level に応じてディメンションを選択
      const dimension = input.level === "city" ? "city" : "country";
    
      const response = await executeReport({
        property,
        dateRanges: [dateRange],
        dimensions: [{ name: dimension }],
        metrics: [{ name: "totalUsers" }, { name: "sessions" }],
        orderBys: [{ metric: { metricName: "totalUsers" }, desc: true }],
        limit,
      });
    
      // 合計ユーザー数を取得
      const totalUsers =
        response.totals?.[0]?.metricValues?.[0]?.value
          ? parseFloat(response.totals[0].metricValues[0].value)
          : 0;
    
      const locations: LocationData[] = [];
    
      for (const row of response.rows || []) {
        const dimensionValues = row.dimensionValues || [];
        const metricValues = row.metricValues || [];
    
        const getValue = (index: number): number => {
          const value = metricValues[index]?.value;
          return value ? parseFloat(value) : 0;
        };
    
        const users = Math.round(getValue(0));
    
        locations.push({
          name: dimensionValues[0]?.value || "(不明)",
          users,
          sessions: Math.round(getValue(1)),
          percentage: calculatePercentage(users, totalUsers),
        });
      }
    
      return { locations };
    }
  • TypeScript interfaces defining the input (GetGeoBreakdownInput), supporting types (LocationData), and output (GetGeoBreakdownOutput) for the get_geo_breakdown tool.
    // get_geo_breakdown
    export interface GetGeoBreakdownInput extends PropertyId {
      period: ShortPeriod;
      level: "country" | "city";
      limit?: number;
    }
    
    export interface LocationData {
      name: string;
      users: number;
      sessions: number;
      percentage: string;
    }
    
    export interface GetGeoBreakdownOutput {
      locations: LocationData[];
    }
  • src/server.ts:286-310 (registration)
    Registration of the get_geo_breakdown tool in the tools array, defining its name, description, and input schema for MCP.
    {
      name: "get_geo_breakdown",
      description: "地域別(国または市区町村)のアクセス分析結果を取得します。",
      inputSchema: {
        type: "object" as const,
        properties: {
          propertyId: { type: "string", description: "GA4プロパティID" },
          period: {
            type: "string",
            enum: ["7days", "28days", "30days"],
            description: "集計期間",
          },
          level: {
            type: "string",
            enum: ["country", "city"],
            description: "地域レベル",
          },
          limit: {
            type: "number",
            description: "取得件数(デフォルト: 10)",
          },
        },
        required: ["period", "level"],
      },
    },
  • src/server.ts:663-669 (registration)
    Dispatch handler in the switch statement within handleToolCall that routes calls to the get_geo_breakdown tool to its implementation.
    case "get_geo_breakdown":
      return await getGeoBreakdown({
        propertyId: args.propertyId as string | undefined,
        period: args.period as "7days" | "28days" | "30days",
        level: args.level as "country" | "city",
        limit: args.limit as number | undefined,
      });
  • Re-export of the getGeoBreakdown handler from its module, allowing it to be imported in server.ts.
    export { getGeoBreakdown } from "./getGeoBreakdown.js";
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'get' implies a read operation, the description doesn't address authentication requirements, rate limits, pagination behavior (despite having a 'limit' parameter), error conditions, or what format the analysis results take. For a tool with 4 parameters and no output schema, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that gets straight to the point. It's appropriately sized for a tool with clear parameters documented in the schema. There's no wasted language or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 4 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what 'access analysis results' actually contain, how they're structured, or what metrics are included. For an analytical tool in a crowded namespace of 17 sibling tools, more context about the specific type of analysis and its output is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema - it mentions 'region (country or city/ward/town/village)' which aligns with the 'level' parameter's enum values, but doesn't provide additional context about parameter interactions or usage patterns.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'get access analysis results by region (country or city/ward/town/village)'. It specifies the verb ('get') and resource ('access analysis results'), and indicates the regional breakdown dimension. However, it doesn't explicitly differentiate from sibling tools like 'get_traffic_sources' or 'get_device_breakdown' that also provide analytical breakdowns.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With 17 sibling tools including various analytical breakdowns (device, traffic sources, etc.), there's no indication of when geographical analysis is preferred over other dimensions or how this tool relates to broader reporting tools like 'run_report'.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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