# Deploy a Next.js app

## Problem

You have a Next.js app in a git repo and you want it running on Lessly — the framework build detected, your environment variables in place, and a live URL — without writing a Dockerfile or a CI pipeline.

## UI

1. In `app.lessly.com`, create an app and connect the git repo you want to deploy.
2. Choose the branch to ship. Lessly detects Next.js and fills in the build — the build command, the output directory, and the Node version — so a standard project needs no configuration.
3. Open the environment's variables and add the entries from your `.env`. Mark passwords and API keys as secrets so their values stay hidden.
4. Click **Deploy**. Lessly streams the build log as it runs.
5. When the build finishes, the app's page shows the live production URL. Open it — your app is live.

## MCP

The same flow through the Lessly MCP server in your agent. Token scope: a key with deploy access to the app. If you haven't installed the MCP yet, see [Install](/get-started/install).

Open the repo in your agent and ask in plain language:

> "Deploy the main branch of this repo to my staging environment."

Your agent calls [`deployment_service_create`](/reference/mcp-tools/deployment_service_create). It reads the repo, detects Next.js, picks the build, and starts the deploy — the new service comes up in an initializing state while the build runs.

Add your variables next. They live on the **environment** and are shared by every service in it:

> "Set the variables from my .env on staging, and mark the secrets."

The agent calls [`deployment_variable_set_env`](/reference/mcp-tools/deployment_variable_set_env) once per entry, hiding any you flag as secret. Then roll the service so it picks them up:

> "Redeploy staging so it uses the new variables."

That calls [`deployment_service_redeploy`](/reference/mcp-tools/deployment_service_redeploy).

## Verify it works

Ask your agent for the deploy's status:

> "What's the status of that deploy?"

The agent calls [`deployment_deployment_get`](/reference/mcp-tools/deployment_deployment_get) and reports `building`, then `ready` (or `error`), along with the URL. In the dashboard, the build log finishes and the app's page shows the same URL. Open it — the app answers on its Lessly URL.

## Variations

**What Lessly detects.** For a Next.js app, Lessly reads the framework, the build command, the output directory, and the Node version from your project, so a standard `create-next-app` builds with no extra configuration.

**`NEXT_PUBLIC_` variables.** Next.js inlines any `NEXT_PUBLIC_` value into the bundle at build time, not at run time. Set these **before** you deploy — or add them and then [`deployment_service_redeploy`](/reference/mcp-tools/deployment_service_redeploy), because a variable added after the build isn't in the shipped bundle. To see what's already set, ask your agent to list the environment's variables; it calls [`deployment_variable_list_env`](/reference/mcp-tools/deployment_variable_list_env), with secret values masked.

**When a deploy doesn't come up.** If the status comes back `error`, start with the build log in the dashboard — look for the failing step, such as a missing dependency, a bad build script, or a variable the build needed but didn't have. If the build completed but the app won't start, read its runtime output with [`deployment_service_logs`](/reference/mcp-tools/deployment_service_logs).

## Next steps

- [Your first deploy](/get-started/first-deploy) — the same flow, guided, at tutorial pace.
- [Roll back a deploy](/ship/rollback) — promote the last good deploy if a release goes wrong.
- [Add a custom domain](/ship/custom-domain) — serve the app on a domain you own.
