script_projects_versions_create
Create a new version for a Google Apps Script project by specifying the script ID and version description, enabling version control and project management within the Google Apps Script MCP Server.
Instructions
Creates a new version of a Google Apps Script project.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | A description for the new version. | |
| scriptId | Yes | The ID of the script project. |
Implementation Reference
- Main handler function that executes the Google Apps Script API call to create a new project version using OAuth authentication.const executeFunction = async ({ scriptId, description }) => { const baseUrl = 'https://script.googleapis.com'; const url = `${baseUrl}/v1/projects/${scriptId}/versions`; const startTime = Date.now(); const body = JSON.stringify({ description }); try { logger.info('VERSION_CREATE', 'Starting version creation', { scriptId, description }); // Get OAuth access token const token = await getOAuthAccessToken(); // Set up headers for the request const headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': `Bearer ${token}` }; logger.logAPICall('POST', url, headers, { description }); // Perform the fetch request const fetchStartTime = Date.now(); const response = await fetch(url, { method: 'POST', headers, body }); const fetchDuration = Date.now() - fetchStartTime; const responseSize = response.headers.get('content-length') || 'unknown'; logger.logAPIResponse('POST', url, 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, errorResponse: errorData, duration: Date.now() - startTime, scriptId, description, timestamp: new Date().toISOString() }; logger.error('VERSION_CREATE', '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('VERSION_CREATE', 'Successfully created version', { scriptId, versionNumber: data.versionNumber, description, duration: Date.now() - startTime }); console.log('✅ Successfully created version'); return data; } catch (error) { const errorDetails = { message: error.message, stack: error.stack, scriptId, description, duration: Date.now() - startTime, timestamp: new Date().toISOString(), errorType: error.name || 'Unknown' }; logger.error('VERSION_CREATE', 'Error creating version', errorDetails); console.error('❌ Error creating version:', errorDetails); // Return detailed error information for debugging return { error: true, message: error.message, details: errorDetails, rawError: { name: error.name, stack: error.stack } }; } };
- Tool definition including schema for input parameters (scriptId and description) and references the handler function.const apiTool = { function: executeFunction, definition: { type: 'function', function: { name: 'script_projects_versions_create', description: 'Creates a new version of a Google Apps Script project.', parameters: { type: 'object', properties: { scriptId: { type: 'string', description: 'The ID of the script project.' }, description: { type: 'string', description: 'A description for the new version.' } }, required: ['scriptId', 'description'] } } } };
- lib/tools.js:8-64 (registration)Dynamic registration of all MCP tools by loading apiTool exports from files listed in toolPaths (which includes this tool's file).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:4-4 (registration)Lists the path to this tool's implementation file for dynamic loading during registration.'google-app-script-api/apps-script-api/script-projects-versions-create.js',