Skip to content

Fix #148: MCP volume mounts, run-state, force-remove, command split - #149

Merged
japperJ merged 3 commits into
masterfrom
japperj-sturdy-spoon
Aug 26, 2026
Merged

japperJ merged 3 commits into
masterfrom
japperj-sturdy-spoon

Conversation

@japperJ

@japperJ japperJ commented Aug 26, 2026

Copy link
Copy Markdown
Owner

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

  • Volume mounts now appear in inspect output. WSLC's container inspect omits Mounts even when a volume is attached. EnrichInspectWithMounts recovers the real mounts from ContainerConfigStore (recorded at creation) and injects them in both InspectContainer and RunContainer. Injects only when WSLC returned no mounts of its own.
  • Accurate run state.
    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.
  • Command/entrypoint whitespace splitting. WslcCommands.Run splits the command into argv tokens so command:"sleep 300" execs as [sleep, 300] rather than a single nonexistent executable.
  • Force-remove.
    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.
  • Removed phantom tools.
    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.
  • Docs aligned. README MCP tool table rewritten to the real snake_case names (added inspect_network, dropped restart/rename, added WSLC caveat) and AI-Assistant-chat-flow.md corrected.

Notes

  • Image upload (chunked base64) was fixed in an earlier commit on this branch and verified: all-A base64 (zero-padded tars) is accepted and a minimal image uploads and loads.
  • The chunk upload protocol is strict-ordered; chunks must be sent one at a time, not in parallel.
  • A prior session evaluation of the downloadable deploying-to-wincontainer skill, WincontainerPrompts.cs, and ContainerAgent.cs found them already accurate; only the public docs above needed fixing.

Testing

  • dotnet test tests/WinContainers.Tests.Unit/WinContainers.Tests.Unit.csproj -c Debug --nologo -v q (218 passed)
  • dotnet test tests/WinContainers.Tests.Integration/WinContainers.Tests.Integration.csproj -c Debug --nologo -v q (18 passed, 1 pre-existing skip)
  • dotnet build WinContainers.slnx -c Debug --nologo -v q (0 warnings, 0 errors)
  • Live MCP smoke check against the elevated app: 27 tools served, no restart/rename, inspect_network present, volume-mount path verified end to end.

japperJ and others added 3 commits August 26, 2026 09:34
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>
Copilot AI lite review requested due to automatic review settings August 26, 2026 11:57
@japperJ
japperJ merged commit cb12b8b into master Aug 26, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_container state reporting, adds inspect_network, and introduces a force option for remove_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 id to inspect/logs without validating non-empty input. Rejecting blank ids early provides clearer errors and avoids accidental wslc calls 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))
Comment on lines +99 to +106
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}")
};
Comment on lines +500 to +524
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();
Comment on lines +49 to +51
{
var inspect = await driver.InspectImageAsync(name, ct);
return
Comment on lines +20 to +22
{
var inspect = await driver.InspectContainerAsync(id, ct);
return
Comment thread README.md
| `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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants