script_projects_deployments_create
Deploy Google Apps Script projects by creating new deployments with specified versions and descriptions.
Instructions
Creates a deployment of an Apps Script project.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scriptId | Yes | The ID of the script to deploy. | |
| manifestFileName | Yes | The name of the manifest file. | |
| versionNumber | Yes | The version number of the script. | |
| description | Yes | A description for the deployment. |
Implementation Reference
- The main handler function `executeFunction` that executes the tool logic: constructs the API URL, prepares the request body, fetches with OAuth headers from `getAuthHeaders`, handles responses, errors, logging, 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 `apiTool` configuration object that registers the tool with MCP-compatible schema: includes reference to the handler function, tool name 'script_projects_deployments_create', description, input parameters schema with types and required fields.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'] } } } };