Use this guide when you need to drive AXSG preview outside the packaged VS Code workflow.
Typical cases:
This guide is specifically about the preview host:
dotnet run --project src/XamlToCSharpGenerator.PreviewerHost -- --mcpIt is not the same thing as:
axsg-mcp, which is the standalone workspace MCP hostXamlSourceGenRuntimeMcpServer, which is the in-process runtime MCP host inside a running Avalonia appThe preview host owns one preview session at a time.
It exposes:
The host uses the same shared AXSG preview protocol contracts as the lightweight helper transport and the VS Code preview bridge. The MCP mode adds MCP tools/resources on top of that shared session layer; it does not introduce a separate preview engine.
Run it from source:
dotnet run --project src/XamlToCSharpGenerator.PreviewerHost -- --mcp
The host runs over JSON-RPC stdio, so a client typically launches it as a child process and then sends the MCP handshake:
initializenotifications/initializedtools/list and resources/listOnce initialized, the preview host supports:
notifications/tools/list_changednotifications/resources/list_changedresources/subscribenotifications/resources/updatedThat matters because the preview tool/resource catalog changes when a session becomes active or stops.
The preview MCP host starts in an idle state.
Before a session exists, the useful tool is:
axsg.preview.startAfter a session starts, the host dynamically adds:
axsg.preview.hotReloadaxsg.preview.updateaxsg.preview.stopIt also adds the dynamic resource:
axsg://preview/session/currentWhen the session stops or the preview host exits, those dynamic tools/resources disappear again, and the host publishes the appropriate list-changed notifications.
axsg.preview.startStarts the preview session and returns:
Required arguments:
hostAssemblyPathpreviewerToolPathsourceAssemblyPathxamlFileProjectPathxamlTextCommon optional arguments:
dotNetCommandruntimeConfigPathdepsFilePathsourceFilePathpreviewCompilerModepreviewWidthpreviewHeightpreviewScalepreviewCompilerMode accepts:
sourceGeneratedavaloniaautoFor most custom AXSG preview clients, sourceGenerated is the right default when you want AXSG live-preview semantics.
axsg.preview.hotReloadThis is the preferred mutation tool when you need a real in-process apply result.
It:
Arguments:
xamlTexttimeoutMsUse this tool when your client wants “apply and wait”.
This is the MCP operation that closes the gap between preview lifecycle control and real source-generated in-process live preview updates.
axsg.preview.updateThis is the lower-level dispatch tool.
It:
Use this when:
axsg.preview.stopStops the active preview session and removes the session-specific tool/resource catalog entries.
axsg://preview/session/statusThe current session lifecycle snapshot.
This resource includes fields such as:
phaseisSessionActivepreviewUrlsessionIdtransportPortpreviewPortpreviewCompilerModesourceAssemblyPathxamlFileProjectPathlastUpdateSucceededlastErrorlastExceptionupdatedAtUtcaxsg://preview/session/eventsRecent bounded preview lifecycle and log events.
This is the resource to subscribe to when you want:
axsg://preview/session/currentThe dynamic “current session” snapshot.
This resource only exists while a session is active.
Use this split:
axsg.preview.start once per sessionaxsg.preview.hotReload when you need a synchronous live-apply resultaxsg.preview.update only when you intentionally want fire-and-forget dispatchaxsg://preview/session/statusaxsg://preview/session/eventsnotifications/tools/list_changed or notifications/resources/list_changedFor a custom editor or agent, hotReload is usually the correct update operation. update is mostly the compatibility/low-level transport operation.
High-level flow:
axsg.preview.startaxsg.preview.hotReloadaxsg.preview.stop when doneExample tools/call for axsg.preview.hotReload:
{
"jsonrpc": "2.0",
"id": 31,
"method": "tools/call",
"params": {
"name": "axsg.preview.hotReload",
"arguments": {
"xamlText": "<UserControl xmlns=\"https://github.com/avaloniaui\" />",
"timeoutMs": 2500
}
}
}
Typical successful response shape:
{
"jsonrpc": "2.0",
"id": 31,
"result": {
"structuredContent": {
"succeeded": true,
"error": null,
"exception": null,
"completedAtUtc": "2026-03-16T12:34:56.789+00:00"
}
}
}
The normal VS Code extension preview path does not require you to launch the preview MCP host manually.
The packaged extension still owns:
The preview MCP host exists for:
Use axsg.preview.hotReload, not axsg.preview.update.
hotReload or stopRelist tools after notifications/tools/list_changed. Those tools are only present while a preview session is active.
axsg://preview/session/current before starting previewThat resource is dynamic and only exists while a session is active.
Use the workspace MCP host first:
axsg-mcp --workspace /path/to/workspace
and call axsg.preview.projectContext.