Skip to main content
Glama
wonyoungseong

GA4 MCP Server

ga4_property_annotations

Retrieve annotations for Google Analytics 4 properties to track events like releases, campaigns, and traffic changes by date or period.

Instructions

Returns annotations for a GA4 property. Annotations are notes that mark specific dates or periods, typically used to record events like releases, campaigns, or traffic changes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdYesThe Google Analytics property ID. Accepted formats: '123456789' or 'properties/123456789'

Implementation Reference

  • The main handler function for ga4_property_annotations tool. It accepts a propertyId parameter and returns information about the API limitation - annotations require v1alpha API which is not fully supported in the googleapis Node.js library, so it returns a message explaining this limitation with suggestions for alternatives.
    export async function listPropertyAnnotations(propertyId: string): Promise<ToolResponse> {
      try {
        // Note: The googleapis Node.js library uses v1beta which doesn't include annotations.
        // Annotations require v1alpha which is available in the Python client.
        // For now, we'll return a message explaining this limitation.
        const propertyName = constructPropertyResourceName(propertyId);
    
        return createSuccessResponse({
          message: `Property annotations for ${propertyName} are not available through the googleapis Node.js library. ` +
            `The reportingDataAnnotations API requires the v1alpha version which is not fully supported in this library. ` +
            `To access annotations, please use the Google Analytics Admin API v1alpha directly or the Python client library.`,
          propertyId: propertyName,
          suggestedAlternative: "Use the GA4 web interface to view annotations, or implement direct REST API calls to v1alpha.",
        });
      } catch (error) {
        return createErrorResponse(`Failed to list property annotations for ${propertyId}`, error);
      }
    }
  • Tool registration definition for ga4_property_annotations, including the tool name, description (explains that annotations are notes marking specific dates or periods for events like releases, campaigns, or traffic changes), and input schema requiring a propertyId string.
      name: "ga4_property_annotations",
      description: "Returns annotations for a GA4 property. Annotations are notes that mark specific dates or periods, typically used to record events like releases, campaigns, or traffic changes.",
      inputSchema: {
        type: "object" as const,
        properties: {
          propertyId: {
            type: "string",
            description: "The Google Analytics property ID. Accepted formats: '123456789' or 'properties/123456789'",
          },
        },
        required: ["propertyId"],
      },
    },
  • Routing logic in the handleToolCall switch statement that maps the ga4_property_annotations tool name to the listPropertyAnnotations handler function, passing the propertyId argument.
    case "ga4_property_annotations":
      return await listPropertyAnnotations(args.propertyId as string);
  • Helper function constructPropertyResourceName used by the handler to validate and format the property ID. Accepts numeric or string formats (e.g., '123456789' or 'properties/123456789') and returns the standardized format 'properties/123456789'.
    export function constructPropertyResourceName(propertyId: string | number): string {
      let propertyNum: number | null = null;
    
      if (typeof propertyId === "number") {
        propertyNum = propertyId;
      } else if (typeof propertyId === "string") {
        const trimmed = propertyId.trim();
        if (/^\d+$/.test(trimmed)) {
          propertyNum = parseInt(trimmed, 10);
        } else if (trimmed.startsWith("properties/")) {
          const numericPart = trimmed.split("/")[1];
          if (numericPart && /^\d+$/.test(numericPart)) {
            propertyNum = parseInt(numericPart, 10);
          }
        }
      }
    
      if (propertyNum === null) {
        throw new Error(
          `Invalid property ID: ${propertyId}. ` +
          "A valid property value is either a number or a string starting " +
          "with 'properties/' and followed by a number."
        );
      }
    
      return `properties/${propertyNum}`;
    }
  • Helper function createSuccessResponse used by the handler to format the successful response as an MCP tool response with JSON data.
    export function createSuccessResponse(data: unknown): ToolResponse {
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(data, null, 2),
          },
        ],
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states this is a read operation ('returns'), implying it's non-destructive, but doesn't cover other aspects like authentication needs, rate limits, error handling, or response format. For a tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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

Conciseness5/5

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

The description is appropriately sized and front-loaded: the first sentence states the core purpose, and the second adds useful context about annotations. Every sentence earns its place by clarifying the resource and its typical use, with no redundant or verbose language.

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

Completeness3/5

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

Given the tool's low complexity (1 parameter, no output schema, no annotations), the description is minimally adequate. It explains what annotations are, which helps contextualize the return value, but lacks details on behavioral traits and usage guidelines. For a read-only tool with simple inputs, this is a baseline level of completeness.

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?

The description adds no parameter-specific information beyond what the schema provides. With 100% schema description coverage, the schema already documents the single parameter 'propertyId' with its format details. The baseline score of 3 reflects that the schema does the heavy lifting, and the description doesn't compensate with additional context like examples or constraints.

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: 'Returns annotations for a GA4 property' with a specific verb ('returns') and resource ('annotations for a GA4 property'). It distinguishes annotations from other GA4 data by explaining they are 'notes that mark specific dates or periods' for events like releases or campaigns, though it doesn't explicitly differentiate from sibling tools like 'ga4_property_details'.

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. It doesn't mention sibling tools such as 'ga4_property_details' or 'ga4_run_report', nor does it specify prerequisites, contexts, or exclusions for usage. The explanation of annotations as notes for events is helpful but doesn't translate into actionable usage instructions.

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

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