Self healing plugins in Dataverse using Claude, MCP and Github
A while back I posted a video to LinkedIn, showing how Claude Code could be used to ‘self heal’ Dataverse plugins. The post was a little sparse on detail, so in this blog post my intention is to provide a step-by-step instruction on how to get this demo up and running in your own environment.
Step 1 - Setting up a local Dataverse MCP Server
Although there is a great MCP Server for Dataverse available from Microsoft, for this particular demo I have created my own MCP Server that can be found here. It has two tools:
- WhoAmI - Executes a
WhoAmI
request and returns the result. - ExecuteFetch - Executes a FetchXml request and returns the result.
So, clone this repo, modify Program.cs
and provide your own environment URL, Client ID and Client Secret. It is assumed that the Client ID is setup as an application user in your environment, with sufficient security roles.
Build the MCP Server and make a note of the location of McpServer.csproj
file. This will be used later to setup the MCP Server in Claude Code.
Now let’s make sure that the MCP Server works! A simple way is to use the MCP Inspector. Do a WhoAmI-request to make sure everything is running:
Step 2 - Fork the repo
The repo containing the code and configurations for the demo can be found here. Go ahead and fork the repo and clone it locally. The repo contains a Dataverse plugin that formats a mobile phone number, but that has a subtle bug that throws exception in certain situations.
Now, update dataverseMcp.sh
to point to the location of your McpServer.csproj
file, from the previous step. This makes sure that Claude Code can access the MCP Server in the next step.
Step 3 - Get Claude Code running
Claude Code is a CLI tool from Anthropic, that is included in the Claude Pro-subscription (and Claude Max also, if you can afford that…) and that can be used - among other things - to utilize MCP Servers. At this time, Claude Code cannot run natively in Windows - it requires Windows Subsystem for Linux (WSL):
- Instructions on how to install WSL can be found here.
- Setup instructions for Claude Code can be found here.
Make sure that Node is installed, fire up WSL and run the following command to install Claude Code globally:
npm install -g @anthropic-ai/claude-code
Then, navigate to where you cloned the repo and start claude
. If you get a question to use existing MCP configurations, say yes. You can now check that the MCP Server is working:
Is MCP working? Great!
Step 4 - Build and deploy the plugin with the issue
Run dotnet build
to build the plugin assembly. If you don’t have the Power Platform CLI, install it. Then start the Plugin Registration Tool using the command pac tool prt
and register PluginTest.dll
on updates of the mobilephone field of the the Contact table:
We have now deployed a plugin with a subtle issue - if the mobilephone number +-()_ is entered, an exception is thrown:
Make sure that plugin in tracing is enabled, as described here, so that the AI can analyze the exceptions thrown by the plugin.
Step 5 - Overview of the repo, and some additional config.
Before proceeding, make sure that you have Github CLI set up locally.
If you go to github and review the repo that you forked, you can see that it has two Actions defined under .github/workflows
:
claude.yml
- Contains a configuration for running Claude as an agent it Github, as shown in the LinkedIn video. It requires some additional configuration in the repo settings, as is described here.test.yml
- An Action that builds and tests the plugin if a pull request is created. Since Dataverse plugins are .NET 4.6.2, this requires some special configuration.
You can run the tests manually to make sure they work:
To be able to update the plugin automatically in Dataverse, the file updatePlugin.sh
needs to be updated with the ID of the plugin assembly, and the location of the plugin file on disk. The easiest way of getting the assembly ID, is to enter the following URL into the address bar:
https://[EnvironmentName].dynamics.com/api/data/v9.0/pluginassemblies?$select=pluginassemblyid,name
Step 6 - Use Claude Code to find the plugin issue
Review Claude.MD
, it gives specific instructions to Claude Code on how to find plugin issues and fix them.
You can now ask Claude if there are any issues, and the AI should identify them, fix the issue, scaffold and run a test and then create a PR:
If you look in your repo, you should see that a PR has been opened, and that the tests are running automatically, and once they succeed the PR is ready to be merged:
Once the merge has been completed, you can tell Claude to get the latest code and update the assembly in Dataverse:
That’s it!