Skip to main content
Glama
Shin-sibainu

GA4 MCP Server

by Shin-sibainu

get_metadata

Retrieve available dimensions and metrics for Google Analytics 4 reports to identify usable items in run_report analysis.

Instructions

利用可能なディメンションとメトリクスの一覧を取得します。run_reportで使える項目を確認できます。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdNoGA4プロパティID(省略時は環境変数を使用)

Implementation Reference

  • The core handler function that fetches and formats GA4 metadata (dimensions and metrics) from the API.
    export async function getMetadata(input: PropertyId): Promise<GetMetadataOutput> {
      const propertyId = getPropertyId(input.propertyId);
      const property = formatPropertyPath(propertyId);
    
      const client = getDataClient();
      const [response] = await client.getMetadata({
        name: `${property}/metadata`,
      });
    
      const dimensions: MetadataItem[] = [];
      const metrics: MetadataItem[] = [];
    
      // ディメンション情報を整形
      for (const dim of response.dimensions || []) {
        dimensions.push({
          apiName: dim.apiName || "",
          uiName: dim.uiName || "",
          description: dim.description || "",
          category: dim.category || "",
        });
      }
    
      // メトリクス情報を整形
      for (const metric of response.metrics || []) {
        metrics.push({
          apiName: metric.apiName || "",
          uiName: metric.uiName || "",
          description: metric.description || "",
          category: metric.category || "",
        });
      }
    
      return { dimensions, metrics };
    }
  • TypeScript interfaces defining the output structure (GetMetadataOutput) and MetadataItem for the get_metadata tool.
    // get_metadata
    export interface MetadataItem {
      apiName: string;
      uiName: string;
      description: string;
      category: string;
    }
    
    export interface GetMetadataOutput {
      dimensions: MetadataItem[];
      metrics: MetadataItem[];
    }
  • src/server.ts:188-202 (registration)
    MCP tool registration including name, description, and input schema definition.
    {
      name: "get_metadata",
      description:
        "利用可能なディメンションとメトリクスの一覧を取得します。run_reportで使える項目を確認できます。",
      inputSchema: {
        type: "object" as const,
        properties: {
          propertyId: {
            type: "string",
            description: "GA4プロパティID(省略時は環境変数を使用)",
          },
        },
        required: [],
      },
    },
  • src/server.ts:614-617 (registration)
    Dispatch handler in the server that calls the getMetadata function for the 'get_metadata' tool.
    case "get_metadata":
      return await getMetadata({
        propertyId: args.propertyId as string | undefined,
      });

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