Skip to main content
Glama
mohalmah

Google Apps Script MCP Server

by mohalmah

get_script_metrics

Retrieve performance and usage metrics for Google Apps Script projects to monitor execution patterns and identify optimization opportunities.

Instructions

Get metrics data for Google Apps Script projects.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptIdYesThe ID of the script project.
deploymentIdYesThe ID of the deployment to filter metrics.
metricsGranularityYesThe granularity of the metrics data.
fieldsYesSelector specifying which fields to include in a partial response.
keyYesAPI key for the request.
access_tokenYesOAuth access token for authorization.
oauth_tokenYesOAuth 2.0 token for the current user.
prettyPrintNoWhether to return the response with indentations and line breaks.

Implementation Reference

  • The executeFunction that implements the core logic of the get_script_metrics tool by making an API request to the Google Apps Script metrics endpoint.
    const executeFunction = async ({ scriptId, deploymentId, metricsGranularity, fields, key, access_token, oauth_token, prettyPrint = true }) => {
      const baseUrl = 'https://script.googleapis.com';
      const token = process.env.GOOGLE_APP_SCRIPT_API_API_KEY;
    
      try {
        // Construct the URL with query parameters
        const url = new URL(`${baseUrl}/v1/projects/${scriptId}/metrics`);
        url.searchParams.append('metricsFilter.deploymentId', deploymentId);
        url.searchParams.append('metricsGranularity', metricsGranularity);
        url.searchParams.append('fields', fields);
        url.searchParams.append('alt', 'json');
        url.searchParams.append('key', key);
        url.searchParams.append('$.xgafv', '1');
        url.searchParams.append('access_token', access_token);
        url.searchParams.append('oauth_token', oauth_token);
        url.searchParams.append('prettyPrint', prettyPrint.toString());
    
        // Set up headers for the request
        const headers = {
          'Accept': 'application/json'
        };
    
        // If a token is provided, add it to the Authorization header
        if (token) {
          headers['Authorization'] = `Bearer ${token}`;
        }
    
        // Perform the fetch request
        const response = await fetch(url.toString(), {
          method: 'GET',
          headers
        });
    
        // Check if the response was successful
        if (!response.ok) {
          const errorData = await response.json();
          throw new Error(errorData);
        }
    
        // Parse and return the response data
        const data = await response.json();
        return data;
      } catch (error) {
        const errorDetails = {
          message: error.message,
          stack: error.stack,
          scriptId,
          deploymentId,
          timestamp: new Date().toISOString(),
          errorType: error.name || 'Unknown'
        };
    
        logger.error('METRICS_GET', 'Error getting metrics data', errorDetails);
        
        console.error('❌ Error getting metrics data:', errorDetails);
        
        // Return detailed error information for debugging
        return { 
          error: true,
          message: error.message,
          details: errorDetails,
          rawError: {
            name: error.name,
            stack: error.stack
          }
        };
      }
    };
  • The schema definition for the get_script_metrics tool, including input parameters and their types.
      type: 'function',
      function: {
        name: 'get_script_metrics',
        description: 'Get metrics data for Google Apps Script projects.',
        parameters: {
          type: 'object',
          properties: {
            scriptId: {
              type: 'string',
              description: 'The ID of the script project.'
            },
            deploymentId: {
              type: 'string',
              description: 'The ID of the deployment to filter metrics.'
            },
            metricsGranularity: {
              type: 'string',
              description: 'The granularity of the metrics data.'
            },
            fields: {
              type: 'string',
              description: 'Selector specifying which fields to include in a partial response.'
            },
            key: {
              type: 'string',
              description: 'API key for the request.'
            },
            access_token: {
              type: 'string',
              description: 'OAuth access token for authorization.'
            },
            oauth_token: {
              type: 'string',
              description: 'OAuth 2.0 token for the current user.'
            },
            prettyPrint: {
              type: 'boolean',
              description: 'Whether to return the response with indentations and line breaks.'
            }
          },
          required: ['scriptId', 'deploymentId', 'metricsGranularity', 'fields', 'key', 'access_token', 'oauth_token']
        }
      }
    }
  • The apiTool object that bundles the handler and schema, exported for registration in the MCP tools system.
    const apiTool = {
      function: executeFunction,
      definition: {
        type: 'function',
        function: {
          name: 'get_script_metrics',
          description: 'Get metrics data for Google Apps Script projects.',
          parameters: {
            type: 'object',
            properties: {
              scriptId: {
                type: 'string',
                description: 'The ID of the script project.'
              },
              deploymentId: {
                type: 'string',
                description: 'The ID of the deployment to filter metrics.'
              },
              metricsGranularity: {
                type: 'string',
                description: 'The granularity of the metrics data.'
              },
              fields: {
                type: 'string',
                description: 'Selector specifying which fields to include in a partial response.'
              },
              key: {
                type: 'string',
                description: 'API key for the request.'
              },
              access_token: {
                type: 'string',
                description: 'OAuth access token for authorization.'
              },
              oauth_token: {
                type: 'string',
                description: 'OAuth 2.0 token for the current user.'
              },
              prettyPrint: {
                type: 'boolean',
                description: 'Whether to return the response with indentations and line breaks.'
              }
            },
            required: ['scriptId', 'deploymentId', 'metricsGranularity', 'fields', 'key', 'access_token', 'oauth_token']
          }
        }
      }
    };
    
    export { apiTool };
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. 'Get metrics data' implies a read-only operation, but the description doesn't address authentication requirements (despite 3 auth parameters), rate limits, what specific metrics are returned, or whether this is a real-time or historical query. For a tool with 8 parameters including multiple auth options, 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.

Conciseness5/5

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

The description is a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized and front-loaded with the essential information.

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?

For a tool with 8 parameters (7 required) and no output schema, the description is inadequate. It doesn't explain what metrics are returned, how they're formatted, or why multiple authentication parameters exist. With no annotations and complex parameter requirements, the description should provide more context about the tool's behavior and output.

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 all parameters are documented in the schema. The description doesn't add any parameter-specific information beyond what's in the schema. The baseline score of 3 reflects adequate coverage through the schema alone, though the description adds no additional value.

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 verb 'Get' and resource 'metrics data for Google Apps Script projects', making the purpose unambiguous. However, it doesn't differentiate this tool from sibling tools like 'script_projects_get' or 'script_projects_deployments_get', which also retrieve information about scripts.

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 multiple sibling tools that retrieve script-related data (e.g., 'script_projects_get', 'script_projects_deployments_get'), there's no indication of when metrics data is needed versus other script information.

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/mohalmah/google-appscript-mcp-server'

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