# Netlify published-preview environment check Version 1.0, November 24, 2026. Companion guide: https://jwatte.com/blog/change-live-mcp-connector-without-breaking-it/ Written by J.A. Watte, jwatte.com. Free to copy, adapt and ship. No attribution required. Use this before any release that "publishes the tested draft" on Netlify, and add its live check to your release script. It applies to any site with Netlify Functions, including an MCP server hosted as a function. Replace every ALL-CAPS placeholder. Never print, paste or commit variable values: this check needs names only. ## 1. What can go wrong A common release pattern is: deploy a draft, test it, then publish that exact draft. In our releases, a deploy-preview draft that was later published kept the deploy-preview context's environment variables. Functions that needed production-only variables lost them, and a staff page answered 503 "Not configured" for about three minutes. What Netlify documents: variables can have a different value per deploy context (Production, Deploy Previews, Branch deploys, Preview server, Local development) and per branch, and for functions, "Each deploy, including Deploy Previews and branch deploys, uses the environment variable values that were set at the time of deployment." Publishing an older deploy "doesn't trigger a new deploy but instead publishes a previous atomic deploy." We found no sentence saying which context's variables a published deploy preview uses. Treat the behavior above as what we saw, and check your own site. **Production-only** means a variable name that has a value in the production context and none in the context your draft was built in. A function that reads such a name works in production and fails in a published draft. ## 2. List the names by context Run in the site's folder (or add `--site SITE_ID`). The JSON output contains values, so it goes straight into a filter that prints names only. The filter accepts either an object keyed by name or a list of objects with a `key` field. ```bash names() { # names() CONTEXT -> sorted variable names, values never printed netlify env:list --context "$1" --json --site SITE_ID \ | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const o=JSON.parse(s);const k=Array.isArray(o)?o.map(v=>v.key):Object.keys(o);console.log(k.sort().join("\n"))})' } names production > env-names-production.txt names deploy-preview > env-names-deploy-preview.txt comm -23 env-names-production.txt env-names-deploy-preview.txt > env-names-production-only.txt wc -l < env-names-production-only.txt ``` Use `--scope functions` as well if your plan supports scopes and you only care about what functions read. If your draft is built with a different `--context` (for example `branch-deploy` or `branch:BRANCH_NAME`), compare production against that context instead. Then find which of those names your functions read: ```bash while read -r n; do grep -rlw --exclude-dir=node_modules -- "$n" . && echo " reads $n"; done < env-names-production-only.txt ``` A count of 0 means nothing if either list command failed. Check both files are non-empty before you read the result. Record the result (names only): | Site | Production-only names read by functions | Published deploy's context now | |---|---|---| | SITE_NAME | NONE or COUNT (NAME_1, NAME_2) | production / deploy-preview | ## 3. Check what context is published now ```bash netlify api getSite --data '{"site_id":"SITE_ID"}' \ | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const d=JSON.parse(s).published_deploy||{};console.log(d.id, d.context)})' ``` If the published deploy is already preview-context and the functions read no variables, your site has been running that way already, and restoring a draft changes nothing about the environment. ## 4. Decision rule | Functions read a production-only name? | Release method | |---|---| | No (or no function variables at all) | Publishing the tested draft is fine. | | Yes | Ship a **production-context deploy** of the tested commit (for example `netlify deploy --prod` from a fresh clone of that commit, through your normal build and gates). Do not publish the draft. | In our case three of six sites had production-only variables and had to ship as production-context deploys. The other three had no function variables at all, and their published deploys were already preview-context. A production-context deploy is a new build, so prove it equals what you tested: build from the same commit in a fresh clone, compare its generated output or its answers with the draft, and only then deploy. ## 5. The live check to add Add a check of everything that reads the environment, run it first after publishing, and restore the previous deploy at once if it fails: - [ ] PAGE_OR_ENDPOINT_THAT_READS_THE_ENVIRONMENT answers 200. - [ ] Its body does not contain the text your code shows when a variable is missing (for us, "Not configured"). - [ ] For an MCP server that reads no variables, one `initialize` (or the discovery request of newer protocol versions) and one `tools/list` still answer as recorded. Optional: the deploy record from `netlify api getDeploy --data '{"deploy_id":"DEPLOY_ID"}'` shows the deploy's `context`. We also found that a function instance id read from the hosting record showed whether carried-over functions kept their production instance. Field names for that are not documented, so treat it as a clue, not a gate. ## 6. Release record - Names compared on DATE for contexts production and DRAFT_CONTEXT: COUNT production-only, COUNT read by functions. - Release method chosen: DRAFT PUBLISH / PRODUCTION-CONTEXT DEPLOY. - Live check of PAGE_OR_ENDPOINT after publish: PASS / FAIL at TIME_UTC. ## Sources and what was checked - Deploy contexts for variable values: https://docs.netlify.com/build/environment-variables/overview/ (read November 24, 2026). - Functions use the values set at the time of deployment: https://docs.netlify.com/build/functions/environment-variables/ (read November 24, 2026). - Publishing a previous deploy and locking auto publishing: https://docs.netlify.com/deploy/manage-deploys/manage-deploys-overview/ (read November 24, 2026). - `netlify env:list` flags `--context` ("production", "deploy-preview", "branch-deploy", "dev" or `branch:NAME`), `--scope`, `--json`, `--plain`, `--site`: https://cli.netlify.com/commands/env/ (read November 24, 2026). `netlify api METHOD --data JSON`: https://cli.netlify.com/commands/api/. `netlify deploy` creates a draft unless `--prod` is given: https://cli.netlify.com/commands/deploy/. - The JSON shape of `env:list --json` is not described in the documentation, so the filter handles both shapes. The shell blocks were syntax-checked with `bash -n` and the inline filter was run on sample input of both shapes. We did not run `env:list` for this kit. - The published-preview behavior and the instance-id clue are our own observations from November 23 and 24, 2026, described in the companion guide. *Informational only. Netlify is named for identification; no affiliation is implied. Re-check Netlify's current documentation before you rely on this.*