Repository navigation
Fix #148: MCP volume mounts, run-state, force-remove, command split - #149
Conversation
Populate the previously empty Resources, Resource Templates, and Prompts panels of MCP clients by exposing the live Wincontainer runtime. - Add WincontainerResources: dynamic resources/list (one entry per live container, image, volume, network), resources/read by URI scheme, and a static resourceTemplates/list with the four fixed templates. - Add WincontainerPrompts: four string-returning prompts (summarize/diagnose container, explain image, summarize runtime) that pull live driver data. - Wire both into ServiceHost via WithPrompts/WithListResourcesHandler/ WithReadResourceHandler/WithListResourceTemplatesHandler. - Add unit tests covering resource listing, read dispatch, templates, and prompt bodies using a scripted IWslcDriver. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add MCP resources (list/read/templates) and four prompts. Fix peer-AI evaluation defects: add missing inspect_network tool (IWslcDriver + WslcDriver + InspectNetwork MCP tool) and reject blank identifiers (container id, image id, volume/network name) at the MCP boundary via a RequireNonEmpty guard that surfaces as a rejected promise instead of a silent success or orphaned resource. Update test fakes and add guard unit tests. Verified live against the elevated app. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…mmand split - Inject real volume mounts into inspect output (WSLC omits Mounts) via ContainerConfigStore enrichment, used by InspectContainer and RunContainer. - Poll the container state after create+start so run_container reports the true Status/Running/ExitCode instead of a transient Running:true. - Split run command/entrypoint on whitespace into argv tokens so 'sleep 300' execs correctly. - Add force parameter to remove_container (stops then removes a running container); WslcCommands.ContainerRemove appends --force. - Remove Restart/Rename MCP and in-app assistant tools: WSLC does not support restart or rename, so they were phantom operations. - Update README MCP tool table and AI-Assistant-chat-flow docs to match the real snake_case surface (added inspect_network, dropped restart/rename). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Several concrete correctness issues remain (quoted command tokenization, Windows drive-letter mount parsing, network resource read dispatch, and a docs inconsistency) that can cause incorrect runtime behavior or misleading MCP outputs.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the Wincontainer MCP server and related app/AI surfaces to better match WSLC capabilities and to expose the missing MCP Resource/Prompt surfaces requested in #148, while also improving container run/inspect correctness (mount enrichment, stable state reporting) and adding force-remove/network inspection support.
Changes:
- Adds MCP prompts, resource templates, resources/list, and resources/read handlers, and wires them into the service host.
- Improves MCP runtime correctness: injects saved volume mounts into inspect output, stabilizes
run_containerstate reporting, addsinspect_network, and introduces aforceoption forremove_container. - Removes unsupported “phantom” restart tooling from MCP/assistant/app UI surfaces and aligns documentation/tooling names to snake_case.
File summaries
| File | Description |
|---|---|
| tests/WinContainers.Tests.Unit/WinContainers.Tests.Unit.csproj | Suppresses MCP analyzer warnings for unit test project. |
| tests/WinContainers.Tests.Unit/RuntimeContractTests.cs | Adds/updates contract tests for new driver methods and command building behavior. |
| tests/WinContainers.Tests.Unit/McpSurfaceTests.cs | New tests validating MCP resources/templates/prompts surfaces using a scripted driver. |
| tests/WinContainers.Tests.Unit/ContainerAccessServiceTests.cs | Updates test driver stubs for new remove/run signatures and network inspect. |
| tests/WinContainers.Tests.Unit/Ai/Fakes.cs | Extends FakeDriver to record force-removes and run entrypoint/command parameters. |
| tests/WinContainers.Tests.Unit/Ai/ContainerAgentTests.cs | Verifies agent tool registry no longer exposes rename and supports force removal. |
| tests/WinContainers.Tests.Integration/UnitTest1.cs | Updates integration driver stub for new signatures and network inspect. |
| src/WinContainers.Service/Mcp/WincontainerTools.cs | Adds input validation, force-remove, inspect mount enrichment, and run-state stabilization. |
| src/WinContainers.Service/Mcp/WincontainerResources.cs | Implements MCP resources/templates/list/read handlers. |
| src/WinContainers.Service/Mcp/WincontainerPrompts.cs | Adds MCP prompt handlers that embed live runtime data. |
| src/WinContainers.Service/Host/ServiceHost.cs | Registers MCP prompts/resources handlers; removes restart route; extends run request schema. |
| src/WinContainers.Runtime/WslcDriver.cs | Updates driver interface implementation for force-remove, inspect-network, and run args. |
| src/WinContainers.Runtime/IWslcDriver.cs | Updates runtime contract (remove force, inspect network, run entrypoint/command). |
| src/WinContainers.Runtime/ContainerConfigStore.cs | Persists entrypoint/command with container run config. |
| src/WinContainers.Runtime/ContainerAccessService.cs | Preserves entrypoint/command when recreating containers for LAN access changes. |
| src/WinContainers.Core/WslcCommands.cs | Adds --force support and command/entrypoint handling for wslc run. |
| src/WinContainers.App/ViewModels/TerminalViewModel.cs | Removes restart command from terminal actions list. |
| src/WinContainers.App/ViewModels/QuickActionsViewModel.cs | Adjusts container config construction formatting (and preserves save behavior). |
| src/WinContainers.App/ViewModels/ImagesViewModel.cs | Preserves entrypoint/command when recreating containers for an updated image. |
| src/WinContainers.App/ViewModels/ContainerDetailViewModel.cs | Removes restart state/action from container details. |
| src/WinContainers.App/Services/WslcServiceClient.cs | Extends run request payload with entrypoint/command; removes restart API call. |
| src/WinContainers.App/Services/IWslcServiceClient.cs | Updates service client contract for new run signature; removes restart. |
| src/WinContainers.App/Pages/DashboardPage.xaml(.cs) | Removes restart button/wiring from dashboard detail actions. |
| src/WinContainers.App/Pages/ContainerDetailPage.xaml(.cs) | Removes restart button/wiring from container detail page. |
| src/WinContainers.AI/AgentToolRegistry.cs | Removes restart/rename tools; adds force remove; allows passing run command override. |
| README.md | Updates tool table to snake_case and documents MCP surface constraints. |
| AI-Assistant-chat-flow.md | Removes restart/rename from assistant tool docs and adds guidance note. |
Review details
Suppressed comments (1)
src/WinContainers.Service/Mcp/WincontainerPrompts.cs:36
- This prompt forwards
idto inspect/logs without validating non-empty input. Rejecting blank ids early provides clearer errors and avoids accidentalwslccalls with empty identifiers.
{
var inspect = await driver.InspectContainerAsync(id, ct);
var logs = await driver.GetContainerLogsAsync(id, 200, ct);
- Files reviewed: 28/29 changed files
- Comments generated: 6
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (!string.IsNullOrWhiteSpace(entrypoint)) | ||
| sb.Append($" --entrypoint {Quote(entrypoint)}"); | ||
| sb.Append($" {Quote(image)}"); | ||
| if (!string.IsNullOrWhiteSpace(command)) |
| string json = scheme switch | ||
| { | ||
| "container" => await driver.InspectContainerAsync(id, cancellationToken), | ||
| "image" => await driver.InspectImageAsync(id, cancellationToken), | ||
| "volume" => await driver.InspectVolumeAsync(id, cancellationToken), | ||
| "network" => await driver.GetNetworksAsync(cancellationToken), | ||
| _ => throw new InvalidOperationException($"Unsupported resource URI scheme: {uri}") | ||
| }; |
| var mounts = new JsonArray(); | ||
| foreach (var entry in config.Volumes) | ||
| { | ||
| var parts = entry.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
| if (parts.Length < 2) | ||
| continue; | ||
|
|
||
| var source = parts[0]; | ||
| var target = parts[1]; | ||
| var mode = parts.Length >= 3 ? parts[2] : string.Empty; | ||
| var isBind = source.Contains('/') || (source.Contains(':', StringComparison.Ordinal) && !source.EndsWith(':')); | ||
| var readOnly = string.Equals(mode, "ro", StringComparison.OrdinalIgnoreCase); | ||
|
|
||
| mounts.Add(new JsonObject | ||
| { | ||
| ["Type"] = isBind ? "bind" : "volume", | ||
| ["Source"] = source, | ||
| ["Target"] = target, | ||
| ["ReadOnly"] = readOnly, | ||
| ["Mode"] = mode | ||
| }); | ||
| } | ||
|
|
||
| containerNode["Mounts"] = mounts; | ||
| return root.ToJsonString(); |
| { | ||
| var inspect = await driver.InspectImageAsync(name, ct); | ||
| return |
| { | ||
| var inspect = await driver.InspectContainerAsync(id, ct); | ||
| return |
| | `health_check` | Check whether the wslc runtime is available and return its version | | ||
| | `get_version` | Get the wslc runtime version | | ||
|
|
||
| > Note: WSLC does not support `restart` or `rename` operations, so there is no `restart_container` or `rename_container` MCP tool. To restart, stop then start (or remove and re-run). |
Why
Issue #148 tracks the defects surfaced by independent peer-AI evaluations of the Wincontainer MCP server. Those evaluations found phantom tools (restart/rename unsupported by WSLC), volume mounts silently dropped from inspect output, run_container reporting a transient Running:true for short-lived images, broken base64 image-upload for zero-padded tars, no force-remove, and an inconsistent/placeholder response schema. This PR resolves the confirmed defects so the MCP surface is correct and self-consistent.
What changed
un_container now polls the container state after create+start and reports the true Status/Running/ExitCode instead of a transient Running:true for images like
ode:20.
emove_container gains a orce parameter (WSLC container rm --force) that stops then removes a running container. Without force it correctly refuses a running container.
estart_container/
ename_container were removed from the MCP surface and the in-app assistant because WSLC has no
estart/
ename command (confirmed via wslc container rename --help). This avoids silent backend failures.
Notes
Testing