Add environment variable discovery and injection for repository providers#9
Merged
Merged
Conversation
Real-world MCP repos (e.g. felipfr/linkedin-mcpserver) load secrets via tsx --env-file=.env at server start, so the cloned workdir needs a populated .env. Reuse the existing Secrets manager: parse .env.example after clone, declare the keys in repository.env_keys, and materialise <workdir>/.env from os.environ / MCP_ENV_FILE before every build and every subprocess spawn. - frontend: /api/clone-and-build parses .env.example, returns env_keys even when a build command fails (so the wizard can still drive the user to the Secrets step). New /api/scan-env-example endpoint for the editor's re-scan button. - server: materialize_repository writes <workdir>/.env BEFORE running build commands so dotenv-style scripts see the values on first build. - process_runner: ProcessSession accepts env_keys, refreshes them from MCP_ENV_FILE on every _start so new secrets picked up without restart. - _extract_secret_env_keys now folds in repository.env_keys, so the missing-secrets badge and Secrets modal work unchanged. - Wizard: build failures no longer abort — placeholder tool is inserted, user proceeds to fill secrets, next restart's materialize_repository succeeds. Help text clarifies build vs spawn command. - Editor: env-keys list + "↻ Re-scan .env.example" button. - README: "Secrets from .env.example" and "Build failures while secrets are missing" sections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for auto-discovering environment variables from
.env.examplefiles in cloned repositories and injecting them as secrets through the proxy's Secrets UI. Repository providers can now declare which environment keys their build commands and spawn process require, with values supplied via the proxy's existing secrets mechanism.Key Changes
_parse_env_example()to extract KEY names from.env.example,.env.sample, or.env.templatefiles in repository workdirs_write_workdir_env_file()to write a.envfile into the cloned repository containing only the environment variables that are actually set, allowing dotenv-style loaders to pick them upenv_keyslist that gets auto-discovered during clone/build and can be manually edited/api/clone-and-buildto parse.env.exampleafter cloning but before building, and return discovered env_keys even when build commands fail (allowing users to populate secrets and retry on next restart)/api/scan-env-exampleendpoint: Allows re-scanning.env.examplewithout re-running the full buildProcessSessionto acceptenv_keysand read fresh values fromMCP_ENV_FILEon each spawn, enabling secrets added via the UI after server start to be picked up without a full restartmaterialize_repository()to write.envfiles before running build commands, ensuring build scripts that require secrets can access themImplementation Details
.envif they have non-empty values in the current process environment, preventing unset placeholders from leakingenv_keystuple to ensure different env-key sets get distinct subprocesses_build_env()method in ProcessSession re-readsMCP_ENV_FILEon each spawn to pick up secrets added via the UI after server starthttps://claude.ai/code/session_01R2Vi6NE4wGxwv6rZ2HEXji