Skip to main content
Glama

deploy_file_contents

Deploy files directly to Cloud Run by providing their contents in a chat context. Specify filenames and content for quick deployment without local file storage.

Instructions

Deploy files to Cloud Run by providing their contents directly. Takes an array of file objects containing filename and content. Use this tool if the files only exist in the current chat context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filesYesArray of file objects containing filename and content
projectYesGoogle Cloud project ID. Leave unset for the app to be deployed in a new project. If provided, make sure the user confirms the project ID they want to deploy to.
regionNoRegion to deploy the service toeurope-west1
serviceNoName of the Cloud Run service to deploy toapp

Implementation Reference

  • The tool handler function: checks GCP credentials via gcpTool, validates project and files inputs, creates progress callback, invokes deploy helper, returns deployment URL or error.
      },
      gcpTool(
        options.gcpCredentialsAvailable,
        async ({ project, region, service, files }, { sendNotification }) => {
          if (typeof project !== 'string') {
            throw new Error(
              'Project must specified, please prompt the user for a valid existing Google Cloud project ID.'
            );
          }
          if (typeof files !== 'object' || !Array.isArray(files)) {
            throw new Error('Files must be specified');
          }
          if (files.length === 0) {
            throw new Error('No files specified for deployment');
          }
    
          // Validate that each file has either content
          for (const file of files) {
            if (!file.content) {
              throw new Error(`File ${file.filename} must have content`);
            }
          }
    
          const progressCallback = createProgressCallback(sendNotification);
    
          // Deploy to Cloud Run
          try {
            await progressCallback({
              data: `Starting deployment of file contents for service ${service} in project ${project}...`,
            });
            const response = await deploy({
              projectId: project,
              serviceName: service,
              region: region,
              files: files,
              skipIamCheck: options.skipIamCheck, // Pass the new flag
              progressCallback,
            });
            return {
              content: [
                {
                  type: 'text',
                  text: `Cloud Run service ${service} deployed in project ${project}\nCloud Console: https://console.cloud.google.com/run/detail/${region}/${service}?project=${project}\nService URL: ${response.uri}`,
                },
              ],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Error deploying to Cloud Run: ${error.message || error}`,
                },
              ],
            };
          }
        }
      )
    );
  • Zod input schema and description for the deploy_file_contents tool, defining parameters: project, region, service, files array.
    {
      description:
        'Deploy files to Cloud Run by providing their contents directly. Takes an array of file objects containing filename and content. Use this tool if the files only exist in the current chat context.',
      inputSchema: {
        project: z
          .string()
          .describe(
            'Google Cloud project ID. Leave unset for the app to be deployed in a new project. If provided, make sure the user confirms the project ID they want to deploy to.'
          )
          .default(options.defaultProjectId),
        region: z
          .string()
          .optional()
          .default(options.defaultRegion)
          .describe('Region to deploy the service to'),
        service: z
          .string()
          .optional()
          .default(options.defaultServiceName)
          .describe('Name of the Cloud Run service to deploy to'),
        files: z
          .array(
            z.object({
              filename: z
                .string()
                .describe(
                  'Name and path of the file (e.g. "src/index.js" or "data/config.json")'
                ),
              content: z
                .string()
                .optional()
                .describe('Text content of the file'),
            })
          )
          .describe('Array of file objects containing filename and content'),
      },
  • registerDeployFileContentsTool: registers the 'deploy_file_contents' tool on the server with schema and handler.
    function registerDeployFileContentsTool(server, options) {
      server.registerTool(
        'deploy_file_contents',
        {
          description:
            'Deploy files to Cloud Run by providing their contents directly. Takes an array of file objects containing filename and content. Use this tool if the files only exist in the current chat context.',
          inputSchema: {
            project: z
              .string()
              .describe(
                'Google Cloud project ID. Leave unset for the app to be deployed in a new project. If provided, make sure the user confirms the project ID they want to deploy to.'
              )
              .default(options.defaultProjectId),
            region: z
              .string()
              .optional()
              .default(options.defaultRegion)
              .describe('Region to deploy the service to'),
            service: z
              .string()
              .optional()
              .default(options.defaultServiceName)
              .describe('Name of the Cloud Run service to deploy to'),
            files: z
              .array(
                z.object({
                  filename: z
                    .string()
                    .describe(
                      'Name and path of the file (e.g. "src/index.js" or "data/config.json")'
                    ),
                  content: z
                    .string()
                    .optional()
                    .describe('Text content of the file'),
                })
              )
              .describe('Array of file objects containing filename and content'),
          },
        },
        gcpTool(
          options.gcpCredentialsAvailable,
          async ({ project, region, service, files }, { sendNotification }) => {
            if (typeof project !== 'string') {
              throw new Error(
                'Project must specified, please prompt the user for a valid existing Google Cloud project ID.'
              );
            }
            if (typeof files !== 'object' || !Array.isArray(files)) {
              throw new Error('Files must be specified');
            }
            if (files.length === 0) {
              throw new Error('No files specified for deployment');
            }
    
            // Validate that each file has either content
            for (const file of files) {
              if (!file.content) {
                throw new Error(`File ${file.filename} must have content`);
              }
            }
    
            const progressCallback = createProgressCallback(sendNotification);
    
            // Deploy to Cloud Run
            try {
              await progressCallback({
                data: `Starting deployment of file contents for service ${service} in project ${project}...`,
              });
              const response = await deploy({
                projectId: project,
                serviceName: service,
                region: region,
                files: files,
                skipIamCheck: options.skipIamCheck, // Pass the new flag
                progressCallback,
              });
              return {
                content: [
                  {
                    type: 'text',
                    text: `Cloud Run service ${service} deployed in project ${project}\nCloud Console: https://console.cloud.google.com/run/detail/${region}/${service}?project=${project}\nService URL: ${response.uri}`,
                  },
                ],
              };
            } catch (error) {
              return {
                content: [
                  {
                    type: 'text',
                    text: `Error deploying to Cloud Run: ${error.message || error}`,
                  },
                ],
              };
            }
          }
        )
      );
    }
  • Core deploy helper function called by the tool handler: handles zipping file contents, GCS upload, Cloud Build submission, and Cloud Run service creation/update.
    export async function deploy({
      projectId,
      serviceName,
      region,
      files,
      progressCallback,
      skipIamCheck,
    }) {
      if (!projectId) {
        const errorMsg =
          'Error: projectId is required in the configuration object.';
        await logAndProgress(errorMsg, progressCallback, 'error');
        throw new Error(errorMsg);
      }
    
      if (!serviceName) {
        const errorMsg =
          'Error: serviceName is required in the configuration object.';
        await logAndProgress(errorMsg, progressCallback, 'error');
        throw new Error(errorMsg);
      }
    
      if (!files || !Array.isArray(files) || files.length === 0) {
        const errorMsg =
          'Error: files array is required in the configuration object.';
        await logAndProgress(errorMsg, progressCallback, 'error');
        if (typeof process !== 'undefined' && process.exit) {
          process.exit(1);
        } else {
          throw new Error(errorMsg);
        }
      }
    
      const path = await import('path');
      const fs = await import('fs');
      const { Storage } = await import('@google-cloud/storage');
      const { CloudBuildClient } = await import('@google-cloud/cloudbuild');
      const { ArtifactRegistryClient } = await import(
        '@google-cloud/artifact-registry'
      );
      const { v2: CloudRunV2Module } = await import('@google-cloud/run');
      const { ServicesClient } = CloudRunV2Module;
      const { ServiceUsageClient } = await import('@google-cloud/service-usage');
      const { Logging } = await import('@google-cloud/logging');
    
      try {
        const context = {
          storage: new Storage({ projectId }),
          cloudBuildClient: new CloudBuildClient({ projectId }),
          artifactRegistryClient: new ArtifactRegistryClient({ projectId }),
          runClient: new ServicesClient({ projectId }),
          serviceUsageClient: new ServiceUsageClient({ projectId }),
          loggingClient: new Logging({ projectId }),
        };
    
        await ensureApisEnabled(
          context,
          projectId,
          REQUIRED_APIS_FOR_SOURCE_DEPLOY,
          progressCallback
        );
    
        const bucketName = `${projectId}-source-bucket`;
        const imageUrl = `${region}-docker.pkg.dev/${projectId}/${REPO_NAME}/${serviceName}:${IMAGE_TAG}`;
    
        await logAndProgress(`Project: ${projectId}`, progressCallback);
        await logAndProgress(`Region: ${region}`, progressCallback);
        await logAndProgress(`Service Name: ${serviceName}`, progressCallback);
        await logAndProgress(`Files to deploy: ${files.length}`, progressCallback);
    
        let hasDockerfile = false;
        if (
          files.length === 1 &&
          typeof files[0] === 'string' &&
          fs.statSync(files[0]).isDirectory()
        ) {
          // Handle folder deployment: check for Dockerfile inside the folder
          const dockerfilePath = path.join(files[0], 'Dockerfile');
          const dockerfilePathLowerCase = path.join(files[0], 'dockerfile');
          if (
            fs.existsSync(dockerfilePath) ||
            fs.existsSync(dockerfilePathLowerCase)
          ) {
            hasDockerfile = true;
          }
        } else {
          // Handle file list deployment or file content deployment
          for (const file of files) {
            if (typeof file === 'string') {
              if (path.basename(file).toLowerCase() === 'dockerfile') {
                hasDockerfile = true;
                break;
              }
            } else if (typeof file === 'object' && file.filename) {
              if (path.basename(file.filename).toLowerCase() === 'dockerfile') {
                hasDockerfile = true;
                break;
              }
            }
          }
        }
        await logAndProgress(`Dockerfile: ${hasDockerfile}`, progressCallback);
    
        const bucket = await ensureStorageBucketExists(
          context,
          bucketName,
          region,
          progressCallback
        );
    
        const zipBuffer = await zipFiles(files, progressCallback);
        await uploadToStorageBucket(
          context,
          bucket,
          zipBuffer,
          ZIP_FILE_NAME,
          progressCallback
        );
        await logAndProgress('Source code uploaded successfully', progressCallback);
    
        await ensureArtifactRegistryRepoExists(
          context,
          projectId,
          region,
          REPO_NAME,
          'DOCKER',
          progressCallback
        );
    
        const buildResult = await triggerCloudBuild(
          context,
          projectId,
          region,
          bucketName,
          ZIP_FILE_NAME,
          REPO_NAME,
          imageUrl,
          hasDockerfile,
          progressCallback
        );
    
        const builtImageUrl = buildResult.results.images[0].name;
    
        const service = await deployToCloudRun(
          context,
          projectId,
          region,
          serviceName,
          builtImageUrl,
          progressCallback,
          skipIamCheck
        );
    
        await logAndProgress(`Deployment Completed Successfully`, progressCallback);
        return service;
      } catch (error) {
        const deployFailedMessage = `Deployment Failed: ${error.message}`;
        console.error(`Deployment Failed`, error);
        await logAndProgress(deployFailedMessage, progressCallback, 'error');
        throw error;
      }
    }
  • tools/tools.js:37-37 (registration)
    Invocation of registerDeployFileContentsTool in the main registerTools function.
    registerDeployFileContentsTool(server, options);
Behavior3/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 mentions the deployment action but doesn't describe critical behavioral aspects like whether this is a destructive operation (overwrites existing files?), authentication requirements, rate limits, or what happens on success/failure. The description adds some context about project ID confirmation but lacks comprehensive behavioral details.

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 extremely concise (two sentences) and front-loaded with the core purpose. Every sentence earns its place: the first defines what the tool does, the second provides crucial usage guidance. No wasted words or redundant information.

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

Completeness3/5

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

For a deployment tool with no annotations and no output schema, the description provides adequate purpose and usage guidance but lacks important contextual information about what the tool actually does behaviorally (creates/updates services, potential side effects, error handling). The schema covers parameters well, but the description doesn't compensate for the missing behavioral context that annotations would normally provide.

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?

Schema description coverage is 100%, so the schema already fully documents all 4 parameters. The description mentions 'array of file objects containing filename and content' which aligns with the schema but doesn't add meaningful semantic context beyond what's already in the parameter descriptions. The baseline is 3 when schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the specific action ('Deploy files to Cloud Run') and resource ('files'), and distinguishes it from sibling tools by specifying 'by providing their contents directly' and 'if the files only exist in the current chat context', which differentiates it from deploy_local_files and deploy_local_folder that presumably work with local file systems.

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool ('Use this tool if the files only exist in the current chat context'), providing clear guidance that distinguishes it from alternatives like deploy_local_files or deploy_local_folder, which would be used for files stored locally rather than in chat 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

Related 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/GoogleCloudPlatform/cloud-run-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server