Add route declarations and automatic port allocation #1

Merged
kyle merged 1 commits from mcp-routes-port-allocation into master 2026-03-27 08:16:20 +00:00
Owner

Summary\n\n- Service definitions can now declare [[components.routes]] instead of manual port mappings\n- Agent allocates free host ports at deploy time (random 10000-60000, availability check)\n- Containers receive $PORT / $PORT_<NAME> env vars with assigned ports\n- Backward compatible: components with old-style ports= work unchanged\n\n## Changes\n\n- Proto: RouteSpec message, routes + env fields on ComponentSpec\n- Servicedef: RouteDef parsing and validation from TOML\n- Registry: component_routes table with host_port tracking\n- Runtime: Env field on ContainerSpec, -e flag in BuildRunArgs()\n- Agent: PortAllocator with mutex serialization, deploy wiring for route→port mapping + env injection\n\n## Test plan\n\n- [x] Servicedef: route parsing, validation (duplicate names, missing port, invalid mode), proto round-trip\n- [x] Registry: route CRUD, cascade delete, host_port updates\n- [x] Runtime: BuildRunArgs with env vars\n- [x] Port allocator: allocation, release, double-allocation returns different ports\n- [x] Agent deploy: deploy with routes (verify -p and -e args), deploy with old-style ports (backward compat)\n- [x] All tests pass (go test ./...)

## Summary\n\n- Service definitions can now declare `[[components.routes]]` instead of manual port mappings\n- Agent allocates free host ports at deploy time (random 10000-60000, availability check)\n- Containers receive `$PORT` / `$PORT_<NAME>` env vars with assigned ports\n- Backward compatible: components with old-style `ports=` work unchanged\n\n## Changes\n\n- **Proto**: `RouteSpec` message, `routes` + `env` fields on `ComponentSpec`\n- **Servicedef**: `RouteDef` parsing and validation from TOML\n- **Registry**: `component_routes` table with `host_port` tracking\n- **Runtime**: `Env` field on `ContainerSpec`, `-e` flag in `BuildRunArgs()`\n- **Agent**: `PortAllocator` with mutex serialization, deploy wiring for route→port mapping + env injection\n\n## Test plan\n\n- [x] Servicedef: route parsing, validation (duplicate names, missing port, invalid mode), proto round-trip\n- [x] Registry: route CRUD, cascade delete, host_port updates\n- [x] Runtime: BuildRunArgs with env vars\n- [x] Port allocator: allocation, release, double-allocation returns different ports\n- [x] Agent deploy: deploy with routes (verify -p and -e args), deploy with old-style ports (backward compat)\n- [x] All tests pass (`go test ./...`)
kyle added 1 commit 2026-03-27 08:05:31 +00:00
Service definitions can now declare routes per component instead of
manual port mappings:

  [[components.routes]]
  name = "rest"
  port = 8443
  mode = "l4"

The agent allocates free host ports at deploy time and injects
$PORT/$PORT_<NAME> env vars into containers. Backward compatible:
components with old-style ports= work unchanged.

Changes:
- Proto: RouteSpec message, routes + env fields on ComponentSpec
- Servicedef: RouteDef parsing and validation from TOML
- Registry: component_routes table with host_port tracking
- Runtime: Env field on ContainerSpec, -e flag in BuildRunArgs
- Agent: PortAllocator (random 10000-60000, availability check),
  deploy wiring for route→port mapping and env injection

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kyle merged commit 5a802bceb6 into master 2026-03-27 08:16:20 +00:00
kyle deleted branch mcp-routes-port-allocation 2026-03-27 08:16:21 +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/mcp#1