Skip to main content
Glama
mohalmah
by mohalmah

get_script_metrics

Retrieve detailed metrics for Google Apps Script projects, including data granularity and deployment-specific insights, to monitor and optimize script performance effectively.

Instructions

Get metrics data for Google Apps Script projects.

Input Schema

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

Implementation Reference

  • The executeFunction that implements the core logic: constructs API URL with query params for script metrics, performs authenticated GET request using fetch, parses JSON response, handles errors with detailed logging and returns structured error object.
    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 } }; } };
  • Tool schema definition including name, description, input parameters with types, descriptions, and required fields.
    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'] } } }
  • tools/paths.js:1-18 (registration)
    The toolPaths array includes the path to the get_script_metrics tool file, enabling its dynamic discovery and registration via lib/tools.js discoverTools() function.
    export const toolPaths = [ 'google-app-script-api/apps-script-api/script-projects-deployments-delete.js', 'google-app-script-api/apps-script-api/script-projects-create.js', 'google-app-script-api/apps-script-api/script-projects-versions-create.js', 'google-app-script-api/apps-script-api/script-projects-deployments-create.js', 'google-app-script-api/apps-script-api/script-projects-deployments-update.js', 'google-app-script-api/apps-script-api/script-projects-deployments-list.js', 'google-app-script-api/apps-script-api/script-projects-update-content.js', 'google-app-script-api/apps-script-api/script-projects-deployments-get.js', 'google-app-script-api/apps-script-api/script-scripts-run.js', 'google-app-script-api/apps-script-api/script-projects-get.js', 'google-app-script-api/apps-script-api/script-processes-list-script-processes.js', 'google-app-script-api/apps-script-api/script-projects-get-metrics.js', 'google-app-script-api/apps-script-api/script-projects-get-content.js', 'google-app-script-api/apps-script-api/script-projects-versions-list.js', 'google-app-script-api/apps-script-api/script-projects-versions-get.js', 'google-app-script-api/apps-script-api/script-processes-list.js' ];

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