XamlMcp: an MCP server for XAML apps
XamlMcp lets Claude Code, Codex, GitHub Copilot, and other AI coding assistants inspect and drive live Avalonia, WPF, WinUI 3, and .NET MAUI applications. Use the Model Context Protocol to read the UI tree, properties, styles, and resources; capture screenshots; send input; and run automation actions.
Debug visual state, inspect control properties, reproduce interactions, or verify a UI change.
A small in-process framework agent connects to the xamlmcp server over an authenticated local transport.
Supported XAML frameworks
The same protocol covers four UI frameworks. Some operations depend on platform or runtime capabilities; check the full feature matrix for exact limits.
In-process agent for applications targeting .NET 8 or later.
WPF modern .NET →Windows desktop agent for one application dispatcher.
WinUI 3 unpackaged x64 →Self-contained applications using Windows App SDK 2.3.1.
.NET MAUI 10.0.80 →Logical agent for unpackaged Windows and debuggable Android apps.
Install the XAML MCP server
The application references one framework agent. Your development environment also needs the xamlmcp MCP server tool.
Install a framework agent
Choose the package that matches the application.
dotnet add package XamlMcp.Avalonia --version VERSION
dotnet add package XamlMcp.Wpf --version VERSION
dotnet add package XamlMcp.WinUI --version VERSION
dotnet add package XamlMcp.Maui --version VERSIONChoose how to run the MCP server
The client setup below runs the pinned package with dnx and needs no global installation. If you prefer a permanent xamlmcp command, install the .NET tool:
dotnet tool install --global XamlMcp.Server --version VERSIONAttach the agent
Select your framework for the exact startup code and release-gating behavior.
Add the fluent attachment in BuildAvaloniaApp. This form stays inert unless XAML_MCP=1 exists at launch.
using XamlMcp.Avalonia;
AppBuilder.Configure<App>()
.UsePlatformDetect()
.AttachXamlMcp();For hard exclusion from Release binaries, wrap .AttachXamlMcp() in your own #if DEBUG.
Attach from Application.OnStartup. The call site disappears from Release builds because the method is conditional on DEBUG.
using XamlMcp.Wpf;
protected override void OnStartup(StartupEventArgs e)
{
this.AttachXamlMcp();
base.OnStartup(e);
}Keep the session and registration in application fields. Attach on the UI thread, register each window, and dispose both when the window closes.
private WinUiXamlMcpSession? _xamlMcp;
private IDisposable? _windowRegistration;
#if DEBUG
var session = WinUiXamlMcp.Attach();
_xamlMcp = session;
_windowRegistration = session.RegisterWindow(window);
window.Closed += async (_, _) =>
{
_windowRegistration?.Dispose();
await session.DisposeAsync();
};
#endifWinUI support requires self-contained unpackaged win-x64 output and one DispatcherQueue.
Call UseXamlMcp() while building the app. The same package works on Windows and Android.
using XamlMcp.Maui;
#if DEBUG
builder.UseXamlMcp();
#endifAndroid requires API 24 or later. Screenshots require API 26 or later. iOS and Mac Catalyst are unsupported.
Configure Claude, Codex, and GitHub Copilot
XamlMcp runs as a local stdio MCP server. Your client starts it when needed; you do not run a persistent server process. The commands below pin the published preview and require the .NET 10 SDK.
Add XamlMcp for your Claude Code user account. Use --scope project instead if you want a committable project configuration.
claude mcp add --scope user xamlmcp -- dnx XamlMcp.Server@VERSIONRun claude mcp list to confirm the server is registered. Claude Code MCP documentation ↗
Add the server once. Codex CLI, the Codex app, and the IDE extension share the same MCP configuration.
codex mcp add xamlmcp -- dnx XamlMcp.Server@VERSIONRun codex mcp list or use /mcp inside Codex to verify the connection. Codex MCP documentation ↗
Create .vscode/mcp.json in the repository.
{
"servers": {
"xamlmcp": {
"command": "dnx",
"args": ["XamlMcp.Server@VERSION"]
}
}
}Select Start above the server entry, then open Copilot Chat in Agent mode and enable its tools. GitHub Copilot MCP documentation ↗
For clients that use the common mcpServers configuration shape, register the executable directly.
{
"mcpServers": {
"xamlmcp": {
"command": "dnx",
"args": ["XamlMcp.Server@VERSION"]
}
}
}Configuration filenames and top-level keys vary by client. Use stdio transport. If you install XamlMcp.Server globally, you can replace the dnx command and arguments with xamlmcp.
Verify the XamlMcp connection
Launch the instrumented application first. For Avalonia's fluent attachment form, launch it with XAML_MCP=1. Then open Claude Code or Codex with the XamlMcp server enabled and ask:
Use XamlMcp to list the running applications, attach to my app, and show its UI tree.The client performs this tool sequence:
list-apps→attach(instanceId)→treeIf the client returns the application's UI tree, the framework package, discovery transport, MCP server, authentication, and client configuration are working together. These are MCP tool calls made by the AI client, not terminal commands.
Native dialogs and windows
A native file picker or message box is a separate Win32 window. It does not belong to the application's XAML tree, so it will not appear in tree and ordinary XamlMcp input cannot address it.
The optional Windows Driver runs inside XamlMcp.Server to cover that boundary. It is disabled by default. Enable it in the command registered with your MCP client:
claude mcp add --scope user xamlmcp -- dnx XamlMcp.Server@VERSION --enable-driver
codex mcp add xamlmcp -- dnx XamlMcp.Server@VERSION --enable-driverdialog-wait and dialog-act handle app-opened native dialogs. window-list and window-act inspect and manage the application's top-level windows.
The Driver only accepts windows owned by the attached process. Dialogs must appear after a mutating XamlMcp call, file paths must stay inside configured roots, and elevated applications and non-interactive sessions are rejected.
XAML inspection and automation tools
XamlMcp exposes a consistent tool surface across frameworks. The capability map returned by attach is authoritative for the current process.
| Tools | Purpose |
|---|---|
tree, search, ancestors | Navigate visual or logical UI nodes. |
props, set-prop | Read properties, value sources, automation patterns, and command slots; write or clear local values. |
styles, resources | Inspect style information and resolved resources. |
screenshot | Capture a window or node as an MCP image. |
input, action | Send input or use automation patterns and bound commands. |
assets, open-asset | Enumerate and read framework assets through safe identifiers. |
dialog-*, window-* | Optional Windows driver for app-owned native dialogs and windows. |