WPFVisualTreeMcp

faze79/WPFVisualTreeMcp

3.3

If you are the rightful owner of WPFVisualTreeMcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

WpfVisualTreeMcp is an MCP server designed to enable AI agents to inspect and interact with WPF application visual trees, facilitating real-time debugging and analysis.

Tools
13
Resources
0
Prompts
0

WpfVisualTreeMcp

Build Release .NET License: MIT MCP Compatible

MCP server for inspecting WPF application Visual Trees - enables AI agents to debug and analyze WPF UI hierarchies in real-time

📢 Latest Updates: See for recent improvements including IPC deadlock fixes, UTF-8 BOM handling, and the new max_results parameter.

Overview

WpfVisualTreeMcp is a Model Context Protocol (MCP) server that allows AI coding agents (Claude Code, Cursor, GitHub Copilot) to inspect and interact with running WPF applications. Think of it as giving your AI assistant the same capabilities as tools like Snoop WPF or Visual Studio's Live Visual Tree.

Why This Matters

Debugging WPF UI issues traditionally requires manual inspection with specialized tools. This project bridges that gap by exposing WPF inspection capabilities through MCP, enabling AI agents to:

  • Understand UI structure during code reviews
  • Diagnose binding errors automatically
  • Suggest fixes for layout issues
  • Assist with UI refactoring tasks
  • Analyze visual tree hierarchies in real-time

Features

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

Binding & Resources

  • Binding Analysis - Inspect data bindings with their current status
  • Binding Error Detection - Automatically find and report binding errors
  • Resource Enumeration - Browse resource dictionaries at any scope
  • Style Inspection - View applied styles and templates

Search & Monitoring

  • Element Search - Find elements by type, name, or property values
  • Property Watching - Monitor property changes in real-time
  • Tree Diff - Compare visual tree snapshots to detect changes

Interaction & Export

  • Element Highlighting - Visually highlight elements in the running app
  • Layout Information - Get detailed layout metrics
  • Tree Export - Export visual tree to XAML or JSON format

Quick Start

Prerequisites

  • Windows 10/11
  • .NET 8.0 SDK or later
  • A WPF application to inspect

Installation

Option 1: Download Release (Recommended)

Download the latest release from GitHub Releases:

  1. Download WpfVisualTreeMcp-vX.X.X-win-x64.zip
  2. Extract to a folder (e.g., C:\Tools\WpfVisualTreeMcp)
  3. The MCP server executable is at server\WpfVisualTreeMcp.Server.exe
Option 2: Build from Source
git clone https://github.com/faze79/WpfVisualTreeMcp.git
cd WpfVisualTreeMcp
dotnet build -c Release
Option 3: .NET Tool (Coming Soon)
dotnet tool install -g WpfVisualTreeMcp

Configuration

The server uses the official Microsoft/Anthropic MCP SDK for .NET, providing guaranteed compatibility with Claude Code and other MCP clients.

Claude Code

Option 1: Command Line (Recommended)

Use the claude mcp add command to add the server directly:

# Add to current project only
claude mcp add wpf-visual-tree -- C:/path/to/WpfVisualTreeMcp/src/WpfVisualTreeMcp.Server/bin/Release/net8.0/WpfVisualTreeMcp.Server.exe

# Add globally (available in all projects)
claude mcp add --scope user wpf-visual-tree -- C:/path/to/WpfVisualTreeMcp/src/WpfVisualTreeMcp.Server/bin/Release/net8.0/WpfVisualTreeMcp.Server.exe

You can verify the server was added:

claude mcp list

Option 2: Project-level JSON Configuration

Create or edit .mcp.json in your project root:

{
  "mcpServers": {
    "wpf-visual-tree": {
      "command": "C:/path/to/WpfVisualTreeMcp/src/WpfVisualTreeMcp.Server/bin/Release/net8.0/WpfVisualTreeMcp.Server.exe",
      "args": []
    }
  }
}

Option 3: Global JSON Configuration

Add to ~/.claude/settings.json:

{
  "mcpServers": {
    "wpf-visual-tree": {
      "command": "C:/path/to/WpfVisualTreeMcp/src/WpfVisualTreeMcp.Server/bin/Release/net8.0/WpfVisualTreeMcp.Server.exe",
      "args": []
    }
  }
}

Important Notes:

  • Use absolute paths to the built .exe file
  • Use forward slashes (/) in paths on Windows
  • Build in Release mode for production: dotnet build -c Release
  • Restart Claude Code after configuration changes
Cursor

Add to your Cursor settings (.cursor/mcp.json):

{
  "mcpServers": {
    "wpf-visual-tree": {
      "command": "C:/path/to/WpfVisualTreeMcp/src/WpfVisualTreeMcp.Server/bin/Release/net8.0/WpfVisualTreeMcp.Server.exe",
      "args": []
    }
  }
}

Self-Hosted Mode (Recommended)

For your WPF application to be inspectable, add a reference to the Inspector DLL and initialize it on startup:

  1. Add a project reference to WpfVisualTreeMcp.Inspector

  2. In your App.xaml.cs:

using System.Diagnostics;
using System.Windows;
using WpfVisualTreeMcp.Inspector;

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        // Initialize the WPF Visual Tree Inspector
        InspectorService.Initialize(Process.GetCurrentProcess().Id);
    }

    protected override void OnExit(ExitEventArgs e)
    {
        InspectorService.Instance?.Dispose();
        base.OnExit(e);
    }
}

This enables the MCP server to connect to your application via named pipes for real-time inspection.

Usage Examples

List Running WPF Applications

Use the wpf_list_processes tool to show all running WPF applications.

Attach and Inspect Visual Tree

Attach to the MyApp.exe WPF application and show me the visual tree of the main window.

Find Binding Errors

Check the attached WPF application for any binding errors and explain what's causing them.

Search for Elements

Find all Button elements in the visual tree that have IsEnabled set to false.

Export Visual Tree

Export the visual tree of the current window to JSON format so I can analyze the structure.

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    AI Agent (Claude Code)                    │
└─────────────────────────┬───────────────────────────────────┘
                          │ MCP Protocol (stdio)
                          ▼
┌─────────────────────────────────────────────────────────────┐
│                 WpfVisualTreeMcp Server                      │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────┐  │
│  │   MCP Handler   │  │  Tree Navigator │  │   Injector  │  │
│  │  (Tools/Res.)   │  │   & Inspector   │  │   Manager   │  │
│  └────────┬────────┘  └────────┬────────┘  └──────┬──────┘  │
└───────────┼────────────────────┼───────────────────┼────────┘
            │                    │                   │
            └────────────────────┼───────────────────┘
                                 │ Named Pipes / IPC
                                 ▼
┌─────────────────────────────────────────────────────────────┐
│                   Target WPF Application                     │
│  ┌─────────────────────────────────────────────────────────┐│
│  │              Injected Inspector DLL                      ││
│  │  • VisualTreeHelper access                              ││
│  │  • LogicalTreeHelper access                             ││
│  │  • Property/Binding inspection                          ││
│  │  • Resource dictionary enumeration                      ││
│  └─────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────┘

For detailed architecture documentation, see .

Available Tools

ToolDescription
wpf_list_processesList all running WPF applications
wpf_attachAttach to a WPF application by process ID or name
wpf_get_visual_treeGet the visual tree hierarchy
wpf_get_element_propertiesGet all dependency properties of an element
wpf_find_elementsSearch for elements by criteria
wpf_get_bindingsGet data bindings for an element
wpf_get_binding_errorsList all binding errors
wpf_get_resourcesEnumerate resource dictionaries
wpf_get_stylesGet applied styles and templates
wpf_watch_propertyMonitor a property for changes
wpf_highlight_elementVisually highlight an element
wpf_get_layout_infoGet layout information
wpf_export_treeExport visual tree to XAML or JSON

For complete tool documentation, see .

Roadmap

Phase 1: Core Inspection ✅

  • Project structure and architecture
  • Process discovery and enumeration
  • Basic process attachment
  • Visual tree navigation
  • Property inspection
  • Element search

Phase 2: Advanced Features ✅

  • IPC communication via named pipes
  • Binding analysis and error detection
  • Resource dictionary enumeration
  • Style and template inspection
  • Property change monitoring (with notifications)

Phase 3: Interaction & Diagnostics (In Progress)

  • Element highlighting overlay
  • XAML/JSON export
  • Visual tree diff/comparison
  • Performance diagnostics

Future Considerations

  • DLL injection for external processes (currently self-hosted mode)
  • Visual tree modification capabilities

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

  1. Clone the repository:

    git clone https://github.com/faze79/WpfVisualTreeMcp.git
    cd WpfVisualTreeMcp
    
  2. Open in Visual Studio 2022 or VS Code:

    code .
    # or
    start WpfVisualTreeMcp.sln
    
  3. Build and run tests:

    dotnet build
    dotnet test
    
  4. Run the sample WPF app for testing:

    dotnet run --project samples/SampleWpfApp
    

Project Structure

WpfVisualTreeMcp/
├── src/
│   ├── WpfVisualTreeMcp.Server/      # MCP Server (.NET 8) - Uses official MCP SDK
│   │   ├── Program.cs                # Server initialization with MCP SDK
│   │   ├── WpfTools.cs               # 13 WPF inspection tools
│   │   └── Services/                 # Process & IPC management
│   ├── WpfVisualTreeMcp.Inspector/   # Injected DLL (.NET Framework 4.8)
│   ├── WpfVisualTreeMcp.Injector/    # Native injector
│   └── WpfVisualTreeMcp.Shared/      # Shared models
├── samples/
│   └── SampleWpfApp/                 # Test application
├── tests/
│   └── WpfVisualTreeMcp.Tests/       # Unit tests
└── docs/                             # Documentation

Technical Details

  • MCP SDK: Built with the official C# MCP SDK from Microsoft/Anthropic
  • Protocol: JSON-RPC 2.0 over stdio transport
  • Target Framework: .NET 8.0 (Server) / .NET Framework 4.8 (Inspector)
  • IPC: Named Pipes for server-to-application communication
  • Tools: 13 inspection tools auto-discovered via [McpServerTool] attributes

Acknowledgments

License

This project is licensed under the MIT License - see the file for details.