feat: env var session defaults and setup --format mcp-json#268
Open
ichoosetoaccept wants to merge 1 commit intogetsentry:mainfrom
Open
feat: env var session defaults and setup --format mcp-json#268ichoosetoaccept wants to merge 1 commit intogetsentry:mainfrom
ichoosetoaccept wants to merge 1 commit intogetsentry:mainfrom
Conversation
d2a2f70 to
95d7d4d
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| return { ...(fileDefaults ?? {}), ...(overrideDefaults ?? {}) }; | ||
| const envDefaults = readEnvSessionDefaults(opts.env ?? process.env); | ||
| if (!overrideDefaults && !fileDefaults && !envDefaults) return undefined; | ||
| return { ...(envDefaults ?? {}), ...(fileDefaults ?? {}), ...(overrideDefaults ?? {}) }; |
Contributor
There was a problem hiding this comment.
Env not stored, lost on session defaults refresh
Medium Severity
initConfigStore accepts an env parameter and passes it through to resolveSessionDefaults, but env is never stored in ConfigStoreState. When refreshResolvedSessionFields() is later called (via persistSessionDefaultsPatch or persistActiveSessionDefaultsProfile), it calls resolveSessionDefaults without env, falling back to process.env. If the original env differed from process.env, the env-based session defaults silently change after any session defaults patch.
Additional Locations (1)
- Add readEnvSessionDefaults() to parse all 15 session default env vars (XCODEBUILDMCP_WORKSPACE_PATH, XCODEBUILDMCP_SCHEME, etc.) - Wire env layer into resolveSessionDefaults() with precedence: tool overrides > config file > env vars - Add --format mcp-json flag to xcodebuildmcp setup: outputs a ready-to-paste MCP client config JSON block instead of writing config.yaml - Update CONFIGURATION.md: env vars documented as recommended method for MCP client integration, remove 'legacy' label, add layering section - Add tests for env var parsing and file-over-env precedence - Add test for --format mcp-json output Closes getsentry#267
95d7d4d to
7e35021
Compare
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
Closes #267.
Config file discovery via
process.cwd()is unreliable across MCP clients (Windsurf setscwd=/, Codex has the same issue, Claude Desktop has nocwdfield). Environment variables are the de facto standard for MCP server configuration — every client implements theenvfield. This PR closes the gap for session defaults and makes env vars the documented primary path for MCP client integration.Changes
src/utils/config-store.tsreadEnvSessionDefaults()— parses all 15 session default env vars:XCODEBUILDMCP_WORKSPACE_PATH,XCODEBUILDMCP_PROJECT_PATH,XCODEBUILDMCP_SCHEME,XCODEBUILDMCP_CONFIGURATION,XCODEBUILDMCP_SIMULATOR_NAME,XCODEBUILDMCP_SIMULATOR_ID,XCODEBUILDMCP_DEVICE_ID,XCODEBUILDMCP_DERIVED_DATA_PATH,XCODEBUILDMCP_PLATFORM,XCODEBUILDMCP_BUNDLE_ID,XCODEBUILDMCP_USE_LATEST_OS,XCODEBUILDMCP_SUPPRESS_WARNINGS,XCODEBUILDMCP_PREFER_XCODEBUILD,XCODEBUILDMCP_ARCH,XCODEBUILDMCP_SIMULATOR_PLATFORMresolveSessionDefaults()with explicit precedence:session_set_defaultstool > config file > env varssrc/cli/commands/setup.ts--formatoption (yaml|mcp-json) toxcodebuildmcp setup--format mcp-json: runs the same interactive wizard but prints a ready-to-paste MCP client config JSON block instead of writingconfig.yamldocs/CONFIGURATION.mdxcodebuildmcp setup --format mcp-jsonreferenceCHANGELOG.md[Unreleased]entries for the new env var support and--format mcp-jsonTesting
reads session defaults from env vars— verifies all string/bool env vars are parsed correctlyfile config session defaults take precedence over env var session defaults— verifies file wins over envoutputs MCP config JSON when format is mcp-json— verifies JSON structure, command, args, and env fieldsExample
This replaces a
config.yamlentirely:{ "mcpServers": { "XcodeBuildMCP": { "command": "npx", "args": ["-y", "xcodebuildmcp@latest", "mcp"], "env": { "XCODEBUILDMCP_ENABLED_WORKFLOWS": "simulator,macos,debugging,logging", "XCODEBUILDMCP_WORKSPACE_PATH": "/path/to/MyApp.xcworkspace", "XCODEBUILDMCP_SCHEME": "MyApp", "XCODEBUILDMCP_PLATFORM": "macOS" } } } }Or generate it interactively: