script_projects_get
Retrieve metadata for a Google Apps Script project by providing the script ID. Automates OAuth authentication and supports partial response fields for efficient data fetching.
Instructions
Get metadata of a Google Apps Script project. OAuth authentication is handled automatically.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| alt | No | Data format for response. | json |
| fields | No | Selector specifying which fields to include in a partial response. | |
| prettyPrint | No | Returns response with indentations and line breaks. | |
| quotaUser | No | Arbitrary string assigned to a user for quota purposes. | |
| scriptId | Yes | The ID of the script project to retrieve. |
Implementation Reference
- The handler function that performs the HTTP GET request to the Google Apps Script API endpoint `/v1/projects/{scriptId}` to retrieve project metadata, handles OAuth authentication, error handling, and logging.const executeFunction = async ({ scriptId, fields, alt = 'json', quotaUser, prettyPrint = true }) => { const baseUrl = 'https://script.googleapis.com'; try { console.log('🔍 Getting script project metadata for:', scriptId); // Validate required parameters if (!scriptId) { throw new Error('scriptId is required'); } // Construct the URL with query parameters const url = new URL(`${baseUrl}/v1/projects/${scriptId}`); // Only add parameters that have values if (fields) url.searchParams.append('fields', fields); if (alt) url.searchParams.append('alt', alt); if (quotaUser) url.searchParams.append('quotaUser', quotaUser); if (prettyPrint !== undefined) url.searchParams.append('prettyPrint', prettyPrint.toString()); console.log('🌐 API URL:', url.toString()); // Get OAuth headers - this automatically handles token refresh const headers = await getAuthHeaders(); console.log('🔐 Authorization headers obtained successfully'); // Perform the fetch request const response = await fetch(url.toString(), { method: 'GET', headers }); console.log('📡 API Response Status:', response.status, response.statusText); // 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(), error: errorData, timestamp: new Date().toISOString() }; 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(); console.log('✅ Successfully retrieved script project metadata'); return data; } catch (error) { console.error('❌ Error getting script project metadata:', { message: error.message, stack: error.stack, scriptId, timestamp: new Date().toISOString() }); // Return detailed error information for debugging return { error: true, message: error.message, details: { scriptId, timestamp: new Date().toISOString(), errorType: error.name || 'Unknown' } }; } };
- The JSON schema definition for the tool, including input parameters with types, descriptions, defaults, and required fields.definition: { type: 'function', function: { name: 'script_projects_get', description: 'Get metadata of a Google Apps Script project. OAuth authentication is handled automatically.', parameters: { type: 'object', properties: { scriptId: { type: 'string', description: 'The ID of the script project to retrieve.' }, fields: { type: 'string', description: 'Selector specifying which fields to include in a partial response.' }, alt: { type: 'string', enum: ['json'], description: 'Data format for response.', default: 'json' }, quotaUser: { type: 'string', description: 'Arbitrary string assigned to a user for quota purposes.' }, prettyPrint: { type: 'boolean', description: 'Returns response with indentations and line breaks.', default: true } }, required: ['scriptId'] } } }
- lib/tools.js:8-64 (registration)The discoverTools function dynamically imports and registers all apiTool exports from files listed in toolPaths, wrapping them with logging. This is how 'script_projects_get' is registered.export async function discoverTools() { logger.info('DISCOVERY', `Starting tool discovery for ${toolPaths.length} tool paths`); const toolPromises = toolPaths.map(async (file) => { try { logger.debug('DISCOVERY', `Loading tool from: ${file}`); const module = await import(`../tools/${file}`); if (!module.apiTool) { logger.warn('DISCOVERY', `Tool file missing apiTool export: ${file}`); return null; } const toolName = module.apiTool.definition?.function?.name; if (!toolName) { logger.warn('DISCOVERY', `Tool missing function name: ${file}`); return null; } // Wrap the original function with logging const originalFunction = module.apiTool.function; const wrappedFunction = withLogging(toolName, originalFunction); logger.debug('DISCOVERY', `Successfully loaded tool: ${toolName}`, { file, toolName, description: module.apiTool.definition?.function?.description }); return { ...module.apiTool, function: wrappedFunction, path: file, }; } catch (error) { logger.error('DISCOVERY', `Failed to load tool: ${file}`, { file, error: { message: error.message, stack: error.stack } }); return null; } }); const tools = (await Promise.all(toolPromises)).filter(Boolean); logger.info('DISCOVERY', `Tool discovery completed`, { totalPaths: toolPaths.length, successfullyLoaded: tools.length, failed: toolPaths.length - tools.length, toolNames: tools.map(t => t.definition?.function?.name).filter(Boolean) }); return tools; }
- tools/paths.js:11-11 (registration)The path to the implementation file is listed in toolPaths array, enabling its discovery and registration by lib/tools.js.'google-app-script-api/apps-script-api/script-projects-get.js',