Add $PORT env var overrides for MCP agent port assignment #1

Merged
kyle merged 1 commits from port-env-support into master 2026-03-27 08:13:59 +00:00
Owner

Summary\n\n- Add $PORT and $PORT_GRPC environment variable support to config.Load\n- After TOML and generic env overrides, checks $PORT → overrides Server.ListenAddr, $PORT_GRPC → overrides Server.GRPCAddr\n- Takes precedence over all other config sources (agent-assigned authoritative binding)\n- Handles both config.Base embedding (MCR, MCNS, MCAT) and direct ServerConfig embedding (Metacrypt) via struct tree walking\n\n## Test plan\n\n- [x] TestPortEnvOverridesListenAddr — $PORT sets listen addr\n- [x] TestPortGRPCEnvOverridesGRPCAddr — $PORT_GRPC sets gRPC addr\n- [x] TestPortEnvOverridesTOMLValue — $PORT wins over TOML\n- [x] TestPortEnvOverridesGenericEnv — $PORT wins over generic env overrides\n- [x] TestNoPortEnvNoChange — no $PORT leaves values unchanged\n- [x] TestPortEnvDirectServerConfig — works with Metacrypt-style embedding\n- [x] All 20 config tests pass

## Summary\n\n- Add `$PORT` and `$PORT_GRPC` environment variable support to `config.Load`\n- After TOML and generic env overrides, checks `$PORT` → overrides `Server.ListenAddr`, `$PORT_GRPC` → overrides `Server.GRPCAddr`\n- Takes precedence over all other config sources (agent-assigned authoritative binding)\n- Handles both `config.Base` embedding (MCR, MCNS, MCAT) and direct `ServerConfig` embedding (Metacrypt) via struct tree walking\n\n## Test plan\n\n- [x] `TestPortEnvOverridesListenAddr` — $PORT sets listen addr\n- [x] `TestPortGRPCEnvOverridesGRPCAddr` — $PORT_GRPC sets gRPC addr\n- [x] `TestPortEnvOverridesTOMLValue` — $PORT wins over TOML\n- [x] `TestPortEnvOverridesGenericEnv` — $PORT wins over generic env overrides\n- [x] `TestNoPortEnvNoChange` — no $PORT leaves values unchanged\n- [x] `TestPortEnvDirectServerConfig` — works with Metacrypt-style embedding\n- [x] All 20 config tests pass
kyle added 1 commit 2026-03-27 07:50:15 +00:00
After TOML loading and generic env overrides, config.Load now checks
$PORT and $PORT_GRPC and overrides ServerConfig.ListenAddr and
ServerConfig.GRPCAddr respectively. These take precedence over all
other config sources because they represent agent-assigned authoritative
port bindings.

Handles both Base embedding (MCR, MCNS, MCAT) and direct ServerConfig
embedding (Metacrypt) via struct tree walking.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kyle merged commit cef06bdf63 into master 2026-03-27 08:13:59 +00:00
kyle deleted branch port-env-support 2026-03-27 08:13:59 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mc/mcdsl#1