Skip to main content
Glama
mohalmah
by mohalmah

script_projects_get_content

Retrieve the content of a Google Apps Script project by specifying the script ID, version number, and optional fields. Integrates with the Google Apps Script API to manage project details.

Instructions

Get the content of a Google Apps Script project.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
access_tokenNoOAuth access token.
altNoData format for response.
fieldsNoSelector specifying which fields to include in a partial response.
keyNoAPI key for the project.
prettyPrintNoReturns response with indentations and line breaks.
scriptIdYesThe ID of the script project to retrieve content for.
versionNumberNoThe version number of the script project.

Implementation Reference

  • The main handler function `executeFunction` that fetches the content of a Google Apps Script project using the Google Apps Script API v1. It handles OAuth authentication, constructs the API URL, makes a GET request, processes the response, and includes comprehensive logging and error handling.
    const executeFunction = async ({ scriptId, versionNumber, fields, alt = "json", key, access_token, prettyPrint = "true" }) => { const baseUrl = 'https://script.googleapis.com'; const startTime = Date.now(); try { logger.info('SCRIPT_GET_CONTENT', 'Starting script content retrieval', { scriptId, versionNumber }); // Get OAuth access token const token = await getOAuthAccessToken(); // Construct the URL with query parameters const url = new URL(`${baseUrl}/v1/projects/${scriptId}/content`); if (versionNumber) url.searchParams.append('versionNumber', versionNumber); if (fields) url.searchParams.append('fields', fields); url.searchParams.append('alt', alt); if (key) url.searchParams.append('key', key); if (prettyPrint) url.searchParams.append('prettyPrint', prettyPrint); logger.debug('SCRIPT_GET_CONTENT', 'Constructed API URL', { url: url.toString(), pathSegments: url.pathname.split('/'), queryParams: Object.fromEntries(url.searchParams) }); // Set up headers for the request const headers = { 'Accept': 'application/json', 'Authorization': `Bearer ${token}` }; logger.logAPICall('GET', url.toString(), headers); // Perform the fetch request const fetchStartTime = Date.now(); const response = await fetch(url.toString(), { method: 'GET', headers }); const fetchDuration = Date.now() - fetchStartTime; const responseSize = response.headers.get('content-length') || 'unknown'; logger.logAPIResponse('GET', url.toString(), response.status, fetchDuration, responseSize); // Check if the response was successful if (!response.ok) { const errorText = await response.text(); let errorData; try { errorData = JSON.parse(errorText); } catch (parseError) { errorData = { message: errorText }; } const detailedError = { status: response.status, statusText: response.statusText, url: url.toString(), errorResponse: errorData, duration: Date.now() - startTime, scriptId, versionNumber, timestamp: new Date().toISOString() }; logger.error('SCRIPT_GET_CONTENT', 'API request failed', detailedError); console.error('❌ API Error Details:', JSON.stringify(detailedError, null, 2)); throw new Error(`API Error (${response.status}): ${errorData.error?.message || errorData.message || 'Unknown error'}`); } // Parse and return the response data const data = await response.json(); logger.info('SCRIPT_GET_CONTENT', 'Successfully retrieved script content', { scriptId, versionNumber, filesCount: data.files?.length || 0, duration: Date.now() - startTime }); console.log('✅ Successfully retrieved script content'); return data; } catch (error) { const errorDetails = { message: error.message, stack: error.stack, scriptId, versionNumber, duration: Date.now() - startTime, timestamp: new Date().toISOString(), errorType: error.name || 'Unknown' }; logger.error('SCRIPT_GET_CONTENT', 'Error getting script project content', errorDetails); console.error('❌ Error getting script project content:', errorDetails); // Return detailed error information for debugging return { error: true, message: error.message, details: errorDetails, rawError: { name: error.name, stack: error.stack } }; } };
  • The `apiTool` object that registers the tool, including its name 'script_projects_get_content', description, input schema (parameters with required 'scriptId'), and reference to the handler function `executeFunction`. This is exported for use in the MCP tool registry.
    /** * Tool configuration for getting the content of a Google Apps Script project. * @type {Object} */ const apiTool = { function: executeFunction, definition: { type: 'function', function: { name: 'script_projects_get_content', description: 'Get the content of a Google Apps Script project.', parameters: { type: 'object', properties: { scriptId: { type: 'string', description: 'The ID of the script project to retrieve content for.' }, versionNumber: { type: 'string', description: 'The version number of the script project.' }, fields: { type: 'string', description: 'Selector specifying which fields to include in a partial response.' }, alt: { type: 'string', description: 'Data format for response.' }, key: { type: 'string', description: 'API key for the project.' }, access_token: { type: 'string', description: 'OAuth access token.' }, prettyPrint: { type: 'string', description: 'Returns response with indentations and line breaks.' } }, required: ['scriptId'] } } } }; export { apiTool };
  • The JSON schema definition for the tool's input parameters, specifying types, descriptions, and the required 'scriptId' field.
    parameters: { type: 'object', properties: { scriptId: { type: 'string', description: 'The ID of the script project to retrieve content for.' }, versionNumber: { type: 'string', description: 'The version number of the script project.' }, fields: { type: 'string', description: 'Selector specifying which fields to include in a partial response.' }, alt: { type: 'string', description: 'Data format for response.' }, key: { type: 'string', description: 'API key for the project.' }, access_token: { type: 'string', description: 'OAuth access token.' }, prettyPrint: { type: 'string', description: 'Returns response with indentations and line breaks.' } }, required: ['scriptId'] }

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