script_projects_deployments_create
Create a deployment for a Google Apps Script project by specifying the script ID, manifest file name, version number, and description. Simplifies script project management and deployment processes.
Instructions
Creates a deployment of an Apps Script project.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | A description for the deployment. | |
| manifestFileName | Yes | The name of the manifest file. | |
| scriptId | Yes | The ID of the script to deploy. | |
| versionNumber | Yes | The version number of the script. |
Implementation Reference
- The main handler function that executes the tool logic: makes a POST request to the Google Apps Script API to create a deployment, handles OAuth authentication, logging, error handling, and returns the deployment data or error details.const executeFunction = async ({ scriptId, manifestFileName, versionNumber, description }) => { const baseUrl = 'https://script.googleapis.com'; const url = `${baseUrl}/v1/projects/${scriptId}/deployments`; const startTime = Date.now(); const body = { manifestFileName, versionNumber, description }; try { logger.info('DEPLOYMENT_CREATE', 'Starting deployment creation', { scriptId, versionNumber, description }); // Get OAuth headers const headers = await getAuthHeaders(); headers['Content-Type'] = 'application/json'; logger.logAPICall('POST', url, headers, body); // Perform the fetch request const fetchStartTime = Date.now(); const response = await fetch(url, { method: 'POST', headers, body: JSON.stringify(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, versionNumber, timestamp: new Date().toISOString() }; logger.error('DEPLOYMENT_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('DEPLOYMENT_CREATE', 'Successfully created deployment', { scriptId, deploymentId: data.deploymentId, versionNumber, duration: Date.now() - startTime }); console.log('✅ Successfully created deployment'); 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('DEPLOYMENT_CREATE', 'Error creating deployment', errorDetails); console.error('❌ Error creating deployment:', errorDetails); // Return detailed error information for debugging return { error: true, message: error.message, details: errorDetails, rawError: { name: error.name, stack: error.stack } }; } };
- The JSON Schema defining the input parameters for the tool, including types, descriptions, and required fields.parameters: { type: 'object', properties: { scriptId: { type: 'string', description: 'The ID of the script to deploy.' }, manifestFileName: { type: 'string', description: 'The name of the manifest file.' }, versionNumber: { type: 'number', description: 'The version number of the script.' }, description: { type: 'string', description: 'A description for the deployment.' } }, required: ['scriptId', 'manifestFileName', 'versionNumber', 'description'] }
- tools/google-app-script-api/apps-script-api/script-projects-deployments-create.js:120-153 (registration)The apiTool export that registers the tool with its name 'script_projects_deployments_create', references the handler function, and includes the schema. This is dynamically loaded and registered in lib/tools.js via path listing in tools/paths.js.const apiTool = { function: executeFunction, definition: { type: 'function', function: { name: 'script_projects_deployments_create', description: 'Creates a deployment of an Apps Script project.', parameters: { type: 'object', properties: { scriptId: { type: 'string', description: 'The ID of the script to deploy.' }, manifestFileName: { type: 'string', description: 'The name of the manifest file.' }, versionNumber: { type: 'number', description: 'The version number of the script.' }, description: { type: 'string', description: 'A description for the deployment.' } }, required: ['scriptId', 'manifestFileName', 'versionNumber', 'description'] } } } }; export { apiTool };
- lib/tools.js:8-64 (helper)Dynamic tool discovery function that loads all apiTool exports from paths listed in tools/paths.js, including this tool, wraps handlers with logging, and prepares them for MCP server registration.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; }