Skip to main content
Glama
wonyoungseong

GA4 MCP Server

ga4_custom_dimensions_metrics

Retrieve custom dimensions and metrics from a GA4 property to discover available definitions before running reports.

Instructions

Retrieves the custom dimensions and metrics defined for a GA4 property. Use this to discover what custom definitions are available before running reports.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdYesThe Google Analytics property ID

Implementation Reference

  • The actual implementation of getCustomDimensionsAndMetrics function that retrieves custom dimensions and metrics for a GA4 property by calling the Analytics Data API's getMetadata endpoint and filtering for customDefinition === true
    export async function getCustomDimensionsAndMetrics(propertyId: string): Promise<ToolResponse> {
      try {
        const client = await getAnalyticsDataClient();
        const propertyName = constructPropertyResourceName(propertyId);
    
        const response = await client.properties.getMetadata({
          name: `${propertyName}/metadata`,
        });
    
        const data = response.data;
    
        // Filter for custom dimensions and metrics
        const customDimensions = (data.dimensions || []).filter(
          dim => dim.customDefinition === true
        );
    
        const customMetrics = (data.metrics || []).filter(
          metric => metric.customDefinition === true
        );
    
        return createSuccessResponse({
          propertyId: propertyName,
          customDimensions: customDimensions,
          customMetrics: customMetrics,
          customDimensionsCount: customDimensions.length,
          customMetricsCount: customMetrics.length,
        });
      } catch (error) {
        return createErrorResponse(`Failed to get custom dimensions and metrics for ${propertyId}`, error);
      }
    }
  • Tool registration definition for ga4_custom_dimensions_metrics with name, description, and input schema specifying propertyId as required parameter
    {
      name: "ga4_custom_dimensions_metrics",
      description: "Retrieves the custom dimensions and metrics defined for a GA4 property. Use this to discover what custom definitions are available before running reports.",
      inputSchema: {
        type: "object" as const,
        properties: {
          propertyId: {
            type: "string",
            description: "The Google Analytics property ID",
          },
        },
        required: ["propertyId"],
      },
    },
  • Tool routing logic that maps the ga4_custom_dimensions_metrics tool name to the getCustomDimensionsAndMetrics handler function
    case "ga4_custom_dimensions_metrics":
      return await getCustomDimensionsAndMetrics(args.propertyId as string);
Behavior3/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. It describes the retrieval behavior and its purpose in a workflow, but lacks details on permissions, rate limits, or response format. This is adequate but has gaps for a tool with no annotation coverage.

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 two sentences with zero waste: the first states the purpose, and the second provides usage guidance. It is appropriately sized and front-loaded, with every sentence earning its place.

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

Completeness4/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 mostly complete for its purpose. However, it lacks details on behavioral aspects like permissions or output structure, which would be beneficial since no annotations or output schema exist.

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 the single parameter 'propertyId'. The description does not add any meaning beyond what the schema provides, such as format examples or constraints, resulting in the baseline score of 3.

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

Purpose5/5

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

The description clearly states the specific action ('Retrieves') and resource ('custom dimensions and metrics defined for a GA4 property'), and distinguishes it from siblings by mentioning its role in discovery before running reports, unlike other tools that fetch summaries, links, annotations, details, or run reports.

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

Usage Guidelines5/5

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

It explicitly states when to use this tool ('to discover what custom definitions are available before running reports'), providing clear context and distinguishing it from alternatives like ga4_run_report, which is implied as the next step after discovery.

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