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);

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