Skip to main content
Glama
mohalmah

Google Apps Script MCP Server

by mohalmah

script_projects_versions_create

Create a new version of a Google Apps Script project to track changes, manage deployments, and maintain project history.

Instructions

Creates a new version of a Google Apps Script project.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptIdYesThe ID of the script project.
descriptionYesA description for the new version.

Implementation Reference

  • The handler function that executes the tool's core logic: authenticates via OAuth, makes a POST request to the Google Apps Script API to create a new project version, handles responses and errors with detailed logging.
    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
          }
        };
      }
    };
  • The tool schema defining the function name, description, input parameters (scriptId and description as required strings), and structure used for MCP tool validation.
    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']
    }
  • The apiTool export object that bundles the handler function reference and tool definition (name, schema). This object is dynamically imported and registered by lib/tools.js during tool discovery in the MCP server.
    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']
          }
        }
      }
    };
    
    export { apiTool };
  • lib/tools.js:8-64 (registration)
    The discoverTools function dynamically imports all apiTool exports from toolPaths (including this tool's path), wraps handlers with logging, and returns the list of tools used by the MCP server for 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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this is a creation operation, implying mutation, but doesn't cover critical aspects like required permissions, whether this action is reversible, rate limits, or what happens to existing versions. For a mutation tool with zero annotation coverage, this is a significant gap in behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any fluff or redundancy. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns, error conditions, or behavioral nuances like side effects. With 2 parameters and 100% schema coverage, the parameter aspect is covered, but the overall context for safe and effective use is lacking.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with both parameters ('scriptId' and 'description') clearly documented in the schema. The description adds no additional parameter information beyond what the schema provides, so it meets the baseline of 3 for adequate but not additive parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Creates') and resource ('a new version of a Google Apps Script project'), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling tools like 'script_projects_create' or 'script_projects_deployments_create', which also create things in the script ecosystem.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing script project), when not to use it, or how it differs from similar creation tools in the sibling list, leaving the agent to infer usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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