deploy_to_heroku
Deploy applications to Heroku by automating git push workflows. Use to create or update apps, configure team or private space deployments, and set environment-specific settings. Requires valid app.json for dynamic configurations.
Instructions
Deploy projects to Heroku, replaces manual git push workflows. Use this tool when you need to: 1) Deploy a new application with specific app.json configuration, 2) Update an existing application with new code, 3) Configure team or private space deployments, or 4) Set up environment-specific configurations. The tool handles app creation, source code deployment, and environment setup. Requires valid app.json in workspace or provided via configuration. Supports team deployments, private spaces, and custom environment variables.Use apps_list tool with the "all" param to get a list of apps for the user to choose from when deploying to an existing app and the app name was not provided.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appJson | No | Stringified app.json configuration for deployment. Used for dynamic configurations or converted projects. The app.json string must be valid and conform to the following schema: {"default":{"$schema":"http://json-schema.org/draft-07/schema#","title":"Heroku app.json Schema","description":"app.json is a manifest format for describing web apps. It declares environment variables, add-ons, and other information required to run an app on Heroku. Used for dynamic configurations or converted projects","type":"object","properties":{"name":{"type":"string","pattern":"^[a-zA-Z-_\\.]+","maxLength":300},"description":{"type":"string"},"keywords":{"type":"array","items":{"type":"string"}},"website":{"$ref":"#/definitions/uriString"},"repository":{"$ref":"#/definitions/uriString"},"logo":{"$ref":"#/definitions/uriString"},"success_url":{"type":"string"},"scripts":{"$ref":"#/definitions/scripts"},"env":{"$ref":"#/definitions/env"},"formation":{"$ref":"#/definitions/formation"},"addons":{"$ref":"#/definitions/addons"},"buildpacks":{"$ref":"#/definitions/buildpacks"},"environments":{"$ref":"#/definitions/environments"},"stack":{"$ref":"#/definitions/stack"},"image":{"type":"string"}},"additionalProperties":false,"definitions":{"uriString":{"type":"string","format":"uri"},"scripts":{"type":"object","properties":{"postdeploy":{"type":"string"},"pr-predestroy":{"type":"string"}},"additionalProperties":false},"env":{"type":"object","patternProperties":{"^[A-Z][A-Z0-9_]*$":{"type":"object","properties":{"description":{"type":"string"},"value":{"type":"string"},"required":{"type":"boolean"},"generator":{"type":"string","enum":["secret"]}},"additionalProperties":false}}},"dynoSize":{"type":"string","enum":["free","eco","hobby","basic","standard-1x","standard-2x","performance-m","performance-l","private-s","private-m","private-l","shield-s","shield-m","shield-l"]},"formation":{"type":"object","patternProperties":{"^[a-zA-Z0-9_-]+$":{"type":"object","properties":{"quantity":{"type":"integer","minimum":0},"size":{"$ref":"#/definitions/dynoSize"}},"required":["quantity"],"additionalProperties":false}}},"addons":{"type":"array","items":{"oneOf":[{"type":"string"},{"type":"object","properties":{"plan":{"type":"string"},"as":{"type":"string"},"options":{"type":"object"}},"required":["plan"],"additionalProperties":false}]}},"buildpacks":{"type":"array","items":{"type":"object","properties":{"url":{"type":"string"}},"required":["url"],"additionalProperties":false}},"environmentConfig":{"type":"object","properties":{"env":{"type":"object"},"formation":{"type":"object"},"addons":{"type":"array"},"buildpacks":{"type":"array"}}},"environments":{"type":"object","properties":{"test":{"allOf":[{"$ref":"#/definitions/environmentConfig"},{"type":"object","properties":{"scripts":{"type":"object","properties":{"test":{"type":"string"}},"additionalProperties":false}}}]},"review":{"$ref":"#/definitions/environmentConfig"},"production":{"$ref":"#/definitions/environmentConfig"}},"additionalProperties":false},"stack":{"type":"string","enum":["heroku-18","heroku-20","heroku-22","heroku-24"]}}}} | |
| env | No | Key-value pairs of environment variables for the deployment that override the ones in app.json | |
| internalRouting | No | Enables internal routing within private spaces. Use this flag when you need to configure private spaces for internal routing. | |
| name | Yes | Heroku application name for deployment target. If omitted, a new app will be created with a random name. If supplied and the app does not exist, the tool will create a new app with the given name. | |
| rootUri | Yes | The absolute path of the user's workspace unless otherwise specified by the user. Must be a string that can be resolved to a valid directory using node's path module. | |
| spaceId | No | Heroku private space identifier for space-scoped deployments. Use spaces_list tool to get a list of spaces if needed. | |
| tarballUri | No | The URL of the tarball to deploy. If not provided, the rootUri must be provided and the tool will create a new tarball from the contents of the rootUri. | |
| teamId | No | Heroku team identifier for team-scoped deployments. Use teams_list tool to get a list of teams if needed. |
Implementation Reference
- src/tools/deploy-to-heroku.ts:611-639 (handler)The handler function registered for the 'deploy_to_heroku' tool. It processes input parameters, instantiates DeployToHeroku class, executes the deployment, and returns MCP tool response.async (options: DeployToHerokuParams): Promise<McpToolResponse> => { const deployToHeroku = new DeployToHeroku(); const result = await deployToHeroku.run({ rootUri: options.rootUri, tarballUri: options.tarballUri, name: options.name, teamId: options.teamId, spaceId: options.spaceId, internalRouting: options.internalRouting, env: options.env as EnvironmentVariables, appJson: options.appJson ? new TextEncoder().encode(options.appJson) : undefined }); if (result?.errorMessage) { return { success: false, message: result.errorMessage, content: [{ type: 'text', text: result.errorMessage }] }; } const successMessage = `Successfully deployed to ${result?.name ?? 'Heroku'}`; return { success: true, message: successMessage, content: [{ type: 'text', text: successMessage }], data: result }; }
- Zod schema defining the input parameters for the deploy_to_heroku tool, including app name, workspace path, tarball URI, team/space IDs, routing, env vars, and app.json config.export const deployToHerokuSchema = z .object({ name: z.string().min(5).max(30).describe('App name for deployment. Creates new app if not exists.'), rootUri: z.string().min(1).describe('Workspace root directory path.'), tarballUri: z.string().optional().describe('URL of deployment tarball. Creates from rootUri if not provided.'), teamId: z.string().optional().describe('Team ID for team deployments.'), spaceId: z.string().optional().describe('Private space ID for space deployments.'), internalRouting: z.boolean().optional().describe('Enable internal routing in private spaces.'), env: z.record(z.string(), z.any()).optional().describe('Environment variables overriding app.json values'), appJson: z .string() .describe(`App.json config for deployment. Must follow schema: ${JSON.stringify(appJsonSchema, null, 0)}`) }) .strict();
- src/tools/deploy-to-heroku.ts:605-641 (registration)Registration function for the deploy_to_heroku tool that calls server.tool() with name, description, schema, and handler.export const registerDeployToHerokuTool = (server: McpServer): void => { server.tool( 'deploy_to_heroku', 'Use for all deployments. Deploys new/existing apps, with or without teams/spaces, and env vars to Heroku. ' + 'Ask for app name if missing. Requires valid app.json via appJson param.', deployToHerokuSchema.shape, async (options: DeployToHerokuParams): Promise<McpToolResponse> => { const deployToHeroku = new DeployToHeroku(); const result = await deployToHeroku.run({ rootUri: options.rootUri, tarballUri: options.tarballUri, name: options.name, teamId: options.teamId, spaceId: options.spaceId, internalRouting: options.internalRouting, env: options.env as EnvironmentVariables, appJson: options.appJson ? new TextEncoder().encode(options.appJson) : undefined }); if (result?.errorMessage) { return { success: false, message: result.errorMessage, content: [{ type: 'text', text: result.errorMessage }] }; } const successMessage = `Successfully deployed to ${result?.name ?? 'Heroku'}`; return { success: true, message: successMessage, content: [{ type: 'text', text: successMessage }], data: result }; } ); };
- src/index.ts:99-99 (registration)Invocation of the registerDeployToHerokuTool function to register the tool with the main MCP server.deployToHeroku.registerDeployToHerokuTool(server);
- src/tools/deploy-to-heroku.ts:249-298 (handler)Core handler method in DeployToHeroku class that performs the actual Heroku deployment: tarball handling, app setup/build creation, git remote addition.protected async deployToHeroku(): Promise<(Build & { name: string }) | null> { const { tarballUri, rootUri, appJson } = this.deploymentOptions; let blobUrl = tarballUri?.toString(); // Create and use an amazon s3 bucket and // then upload the newly created tarball // from the local sources if no tarballUri was provided. if (!blobUrl) { const generatedAppJson = appJson ? [{ relativePath: './app.json', contents: appJson }] : []; const tarball = await packSources(rootUri!, generatedAppJson); const { source_blob: sourceBlob } = await this.sourcesService.create(this.requestInit); blobUrl = sourceBlob!.get_url!; try { const response = await fetch(sourceBlob!.put_url!, { method: 'PUT', body: tarball }); if (!response.ok) { const uploadErrorMessage = `Error uploading tarball to S3 bucket. The server responded with: ${response.status} - ${response.statusText}`; throw new Error(uploadErrorMessage); } } catch (error) { throw new DeploymentError((error as Error).message); } } // The user has right-clicked on a // Procfile or app.json or has used // the deploy to heroku decorator button // and we have apps in the remote. Ask // the user where to deploy. const result = this.isExistingDeployment ? await this.createNewBuildForExistingApp(blobUrl, this.deploymentOptions.name ?? '') : await this.setupNewApp(blobUrl); // This is a new app setup and needs a git remote // added to the workspace. if (!this.isExistingDeployment && result) { // Add the new remote to the workspace const app = await this.appService.info(result.name, this.requestInit); try { execSync(`git remote add heroku-${result.name} ${app.git_url!}`, { cwd: rootUri! }); } catch { // Ignore } } return result; }