Purpose
WPFVisualTreeMcp is a Model Context Protocol (MCP) server designed to enable AI coding agents (such as Claude Code, Cursor, GitHub Copilot) to inspect, debug, and drive a running WPF application. It is described as "Snoop + Playwright for AI," exposing capabilities such as the visual tree, data bindings, screenshots, clicks, text input, and keyboard actions through the MCP protocol, all without requiring any source code modifications to the target WPF process.
Main Capabilities
Core Inspection
- Process discovery: List all running WPF applications available for inspection.
- Visual tree navigation: Traverse the complete visual tree hierarchy.
- Logical tree access: Navigate the logical tree structure.
- Property inspection: Read all dependency properties of any UI element.
Bindings and Resources
- Binding analysis: Inspect bindings, with support for converter, StringFormat, FallbackValue, and MultiBinding.
- DataContext inspection: View the DataContext type, properties, INPC status, and inheritance chain.
- Binding error detection: Automatically capture and report binding errors, with classification.
- Resource enumeration: Browse resource dictionaries in any scope.
- Style inspection: View applied styles and templates.
Search and Monitoring
- Element search: Find elements by type, name, or property value.
- Deep search: Search the entire tree, including AdornerLayer and Popup elements.
- Property watching: Monitor property changes in real time.
Interaction and Export
- Screenshot capture: Capture window/element screenshots for AI agents to view.
- Element highlighting: Visually highlight elements within the running app.
- Control clicking (v0.4.0): Click elements via UI Automation (Invoke / Toggle / Select / ExpandCollapse) or real OS mouse clicks.
- Set text (new in v0.5.0): Fill TextBox/ComboBox/PasswordBox via UI Automation IValueProvider.SetValue, with support for TextBox.Text / PasswordBox.Password / reflection Text fallback, or use physical=true to input via the OS keyboard (full Unicode BMP).
- Send keys (new in v0.5.0): Send keyboard shortcuts (Ctrl+S, Alt+F4, F5, Enter, Ctrl+Shift+F, etc.) to an element or the focused window via OS keyboard input.
- Layout information: Get detailed layout metrics.
- Tree export: Export the visual tree to XAML or JSON format.
- Automatic injection: Inject the Inspector into a running WPF process (no source code modifications required); since v0.6.0, multi-architecture is supported—a 64-bit server can inject into a 32-bit WPF app via the bundled WpfInjectorHelper.exe.
Dual-Mode CLI (new in v0.4.0)
The same WpfVisualTreeMcp.Server.exe can run either as an MCP stdio server (no arguments, default) or as a one-shot CLI (any recognized subcommand). This is useful when the MCP server is not connected, for scripting, and for manually verifying the pipeline. Run WpfVisualTreeMcp.Server.exe help to view the full command list. Output is JSON on stdout; diagnostic information is output to stderr.
Usage
Quick Start (60 seconds)
- Download and extract the latest release zip (requires .NET 8 Desktop Runtime).
- Register it in your MCP client—for Claude Code, add to .mcp.json: { "mcpServers": { "wpf-visual-tree": { "command": "C:/path/to/WpfVisualTreeMcp.Server.exe", "args": [] } } }
- Ask the agent: "Look at my running WPF app and tell me why the Save button is disabled."
Prefer the terminal? The same exe is also a complete CLI: WpfVisualTreeMcp.Server.exe help.
Environment Requirements
- .NET 8.0 SDK or later
- A WPF application available for inspection
This package is also published as an MCP server package (PackageType: McpServer), so MCP clients that support NuGet-hosted servers can start it directly.
Installation
Download the latest version from GitHub Releases:
- Download WpfVisualTreeMcp-vX.X.X-win-x64.zip
- Extract to a folder (for example C:\Tools\WpfVisualTreeMcp)
- The MCP server executable is WpfVisualTreeMcp.Server.exe
The server uses the official Microsoft/Anthropic MCP SDK for .NET, ensuring compatibility with Claude Code and other MCP clients.
Configuration Methods
Option 1: Command line (recommended) Use the claude mcp add command to add the server directly, and you can verify that the server has been added.
Option 2: Project-level JSON configuration Create or edit .mcp.json in the project root directory.
Option 3: Global JSON configuration Add to ~/.claude/settings.json.
Important notes:
- Use an absolute path pointing to the built .exe file
- Use forward slashes (/) in Windows paths
- Build in Release mode for production: dotnet build -c Release
- Restart Claude Code after configuration changes
Cursor configuration: Add to Cursor settings (.cursor/mcp.json).
Self-hosted Mode (recommended)
To make a WPF application inspectable, add a reference to the Inspector DLL and initialize it at startup:
- Add a project reference to WpfVisualTreeMcp.Inspector
- Initialize in App.xaml.cs
This enables the MCP server to connect to the application via named pipes for real-time inspection.
Common Operation Examples
- List running WPF applications
- Attach and inspect the visual tree
- Find binding errors
- Searchelements
- Export the visual tree
Use Cases
- Understanding UI structure during code review
- Automatically diagnosing binding errors
- Suggesting fixes for layout issues
- Assisting with UI refactoring tasks
- Analyzing the visual tree hierarchy in real time
- Driving the application to complete operations such as form filling, list selection, and click submission, and explaining the reasons for UI state changes
Limitations
- Requires .NET 8.0 SDK or later, and a WPF application available for inspection.
- Self-hosted mode requires adding an Inspector DLL reference and initialization; automatic injection mode requires no source code modification.
- Compared with other WPF MCP servers based on UI Automation (FlaUI), this server follows the Snoop route and injects at runtime, so it can read the real visual tree and diagnose binding errors and DataContext without installing an in-process probe in the target application.
- UIA-based tools can only see what is exposed through accessibility, and computer-use agents can only see pixels; this project gives agents the same internal view that WPF developers have in Snoop, without installing a probe in the target application, and provides the broadest means of operation through a protocol supported by all AI coding tools.
- Future plans mentioned in the roadmap include: Inspector-only NuGet package (for self-hosted mode, referenced rather than injected), streaming binding error/property change notifications to MCP clients, and WinUI 3 support.
- The project uses the MIT license.
Technical Details
- MCP SDK: Built using the official Microsoft/Anthropic C# MCP SDK
- Protocol: JSON-RPC 2.0 over stdio transport
- Target frameworks: .NET 8.0 (Server) / .NET Framework 4.8 + .NET 8.0-windows (Inspector, dual-targeted)
- IPC: Named pipes for server-to-application communication
- Tools: 28 tools automatically discovered via the [McpServerTool] attribute (22 read-only inspection tools, including wpf_wait_for, wpf_snapshot, wpf_diff, wpf_evaluate_binding, wpf_explain_triggers + 6 stateChange tools: wpf_click_element, wpf_select_item, wpf_set_text, wpf_send_keys, wpf_set_property, wpf_revert_property)
- CLI: the same executable runs as a one-shot CLI when given a subcommand (Program.cs routes via CliRunner.IsCliCommand)
Development Setup
- Clone the repository: git clone https://github.com/faze79/WpfVisualTreeMcp.git cd WpfVisualTreeMcp
- Open in Visual Studio 2022 or VS Code: code . # or start WpfVisualTreeMcp.sln
- Build and run tests: dotnet build dotnet test
- Run the sample WPF app for testing: dotnet run --project samples/SampleWpfApp
Acknowledgements
- Inspired by Snoop WPF—the original WPF spy tool
- Built on Anthropic's Model Context Protocol
- Thanks to the .NET and WPF communities
This project is licensed under the MIT License—see the LICENSE file for details.