Skip to content

Commit 5b541b6

Browse files
authored
environment_run: improve prompts for better accuracy (#143)
Signed-off-by: Andrea Luzzardi <[email protected]>
1 parent 7be9137 commit 5b541b6

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

environment/environment.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ func (env *Environment) RunBackground(ctx context.Context, command, shell string
312312
if errors.As(err, &exitErr) {
313313
return nil, fmt.Errorf("command failed with exit code %d.\nstdout: %s\nstderr: %s", exitErr.ExitCode, exitErr.Stdout, exitErr.Stderr)
314314
}
315+
if errors.Is(err, context.DeadlineExceeded) {
316+
return nil, fmt.Errorf("service failed to start within %s timeout", serviceStartTimeout)
317+
}
315318
return nil, err
316319
}
317320

@@ -335,14 +338,17 @@ func (env *Environment) RunBackground(ctx context.Context, command, shell string
335338
return nil, err
336339
}
337340

338-
externalEndpoint, err := tunnel.Endpoint(ctx, dagger.ServiceEndpointOpts{})
341+
externalEndpoint, err := tunnel.Endpoint(ctx, dagger.ServiceEndpointOpts{
342+
Scheme: "tcp",
343+
})
339344
if err != nil {
340345
return nil, err
341346
}
342347
endpoint.HostExternal = externalEndpoint
343348

344349
internalEndpoint, err := svc.Endpoint(ctx, dagger.ServiceEndpointOpts{
345-
Port: port,
350+
Port: port,
351+
Scheme: "tcp",
346352
})
347353
if err != nil {
348354
return nil, err

environment/service.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ func (env *Environment) startService(ctx context.Context, cfg *ServiceConfig) (*
7575
if errors.As(err, &exitErr) {
7676
return nil, fmt.Errorf("command failed with exit code %d.\nstdout: %s\nstderr: %s", exitErr.ExitCode, exitErr.Stdout, exitErr.Stderr)
7777
}
78+
if errors.Is(err, context.DeadlineExceeded) {
79+
return nil, fmt.Errorf("service failed to start within %s timeout", serviceStartTimeout)
80+
}
7881
return nil, err
7982
}
8083

8184
endpoints := EndpointMappings{}
8285
for _, port := range cfg.ExposedPorts {
8386
endpoint := &EndpointMapping{
84-
EnvironmentInternal: fmt.Sprintf("%s:%d", cfg.Name, port),
87+
EnvironmentInternal: fmt.Sprintf("tcp://%s:%d", cfg.Name, port),
8588
}
8689
endpoints[port] = endpoint
8790

@@ -99,7 +102,9 @@ func (env *Environment) startService(ctx context.Context, cfg *ServiceConfig) (*
99102
return nil, err
100103
}
101104

102-
externalEndpoint, err := tunnel.Endpoint(ctx, dagger.ServiceEndpointOpts{})
105+
externalEndpoint, err := tunnel.Endpoint(ctx, dagger.ServiceEndpointOpts{
106+
Scheme: "tcp",
107+
})
103108
if err != nil {
104109
return nil, fmt.Errorf("failed to get endpoint for service %s: %w", cfg.Name, err)
105110
}

mcpserver/tools.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ var EnvironmentListTool = &Tool{
412412

413413
var EnvironmentRunCmdTool = &Tool{
414414
Definition: mcp.NewTool("environment_run_cmd",
415-
mcp.WithDescription("Run a terminal command inside the environment."),
415+
mcp.WithDescription("Run a terminal command inside a NEW container within the environment."),
416416
mcp.WithString("explanation",
417417
mcp.Description("One sentence explanation for why this command is being run."),
418418
),
@@ -482,7 +482,9 @@ Failure to do so will result in the tool being stuck, awaiting for the command t
482482
return nil, err
483483
}
484484

485-
return mcp.NewToolResultText(fmt.Sprintf(`Command started in the background. Endpoints are %s
485+
return mcp.NewToolResultText(fmt.Sprintf(`Command started in the background in NEW container. Endpoints are %s
486+
487+
To access from the user's machine: use host_external. To access from other commands in this environment: use environment_internal.
486488
487489
Any changes to the container workdir (%s) WILL NOT be committed to container-use/%s
488490
@@ -744,7 +746,7 @@ var EnvironmentAddServiceTool = &Tool{
744746
mcp.Description("The command to start the service. If not provided the image default command will be used."),
745747
),
746748
mcp.WithArray("ports",
747-
mcp.Description("Ports to expose. For each port, returns the environment_internal (for use by environments) and external (for use by the user) address."),
749+
mcp.Description("Ports to expose. For each port, returns the container_internal (for use by environments) and host_external (for use by the user) address."),
748750
mcp.Items(map[string]any{"type": "number"}),
749751
),
750752
mcp.WithArray("envs",

0 commit comments

Comments
 (0)