Add route declarations and automatic port allocation to MCP agent

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>
This commit is contained in:
2026-03-27 01:04:47 -07:00
parent 503c52dc26
commit 777ba8a0e1
14 changed files with 1101 additions and 222 deletions

View File

@@ -36,6 +36,13 @@ service McpAgentService {
// --- Service lifecycle ---
message RouteSpec {
string name = 1; // route name (used for $PORT_<NAME>)
int32 port = 2; // external port on mc-proxy
string mode = 3; // "l4" or "l7"
string hostname = 4; // optional public hostname override
}
message ComponentSpec {
string name = 1;
string image = 2;
@@ -45,6 +52,8 @@ message ComponentSpec {
repeated string ports = 6;
repeated string volumes = 7;
repeated string cmd = 8;
repeated RouteSpec routes = 9;
repeated string env = 10;
}
message ServiceSpec {