Sample plugin demonstrating the DataverseMCPToolBox.Extensibility framework by implementing a "Who Am I" tool for Dataverse.
This plugin provides a production-ready MCP tool (who-am-i) that retrieves comprehensive information about the currently authenticated Dataverse user:
- ✅ User Display Name - Full name of the authenticated user
- ✅ User ID - Unique identifier (GUID) of the user
- ✅ Business Unit ID - User's business unit GUID
- ✅ Organization ID - Dataverse organization GUID
- ✅ Environment URL - Full Dataverse environment URL
- ✅ Confirmation Message - Human-readable success message
This sample serves as a reference implementation demonstrating best practices for plugin development:
- ✅ Plugin class structure with
[McpPlugin]attribute - ✅ Strongly-typed tool implementation using
McpToolBase<TInput, TOutput> - ✅ Separation of concerns (plugin vs. tool classes)
- ✅ Proper lifecycle management with
InitializeAsync()andDispose()
- ✅
IDataverseContextusage for accessing service client - ✅ WhoAmIRequest execution (SDK operation)
- ✅ Entity retrieval with QueryExpression
- ✅ Safe attribute value extraction with fallback
- ✅ Kebab-case tool naming (
who-am-i) - ✅ JSON Schema generation for parameters (none required in this case)
- ✅ PascalCase C# properties → camelCase JSON output
- ✅ Structured error handling with
ToolExecutionException
- ✅ Comprehensive error handling with fallback logic
- ✅ Async-only operations with
CancellationTokensupport - ✅ Logging to stderr exclusively (never stdout)
- ✅ Human-readable success messages
- ✅ Detailed XML documentation for IntelliSense
Install directly from NuGet.org:
# .NET CLI
dotnet add package DataverseMCPToolBox.WhoAmI
# Package Manager Console (Visual Studio)
Install-Package DataverseMCPToolBox.WhoAmI- Open Dataverse MCP Toolbox panel in VS Code
- Navigate to Plugins section
- Click Install Plugin
- Enter package ID:
DataverseMCPToolBox.WhoAmI - Click Install
The plugin will be automatically downloaded and loaded.
-
Clone the repository:
git clone https://github.com/tchinnin/dataverse-mcp-toolbox.git cd dataverse-mcp-toolbox/SampleWhoAmIPlugin -
Build the project:
dotnet build --configuration Release
-
Package as NuGet:
dotnet pack --configuration Release -o ./nupkg
-
Locate the package:
nupkg/DataverseMCPToolBox.WhoAmI.1.1.0-alpha.nupkg -
Install locally:
- Copy
.nupkgfile to your plugin directory - Or install via:
dotnet nuget add source ./nupkg -n LocalSource
- Copy
- Dataverse MCP Toolbox Core Server must be running
- An active Dataverse connection must be established
- The plugin must be loaded by the Core Server
Description: Retrieves information about the currently connected Dataverse user
Tool Name: who-am-i (kebab-case, MCP-compliant)
Parameters: None required (empty object {} or null)
Returns: WhoAmIOutput object with the following properties:
interface WhoAmIOutput {
userDisplayName: string; // Full name of the user
userId: string; // User GUID
businessUnitId: string; // Business unit GUID
organizationId: string; // Organization GUID
environmentUrl: string; // Dataverse environment URL
message: string; // Confirmation message
}Example Response:
{
"userDisplayName": "John Doe",
"userId": "12345678-1234-1234-1234-123456789abc",
"businessUnitId": "87654321-4321-4321-4321-cba987654321",
"organizationId": "abcdef12-ab12-ab12-ab12-abcdef123456",
"environmentUrl": "https://org.crm.dynamics.com",
"message": "Successfully retrieved information for user 'John Doe'"
}{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "who-am-i",
"arguments": {}
}
}In VS Code with GitHub Copilot:
@workspace Use the who-am-i tool to get the current user information
- Open Dataverse MCP Toolbox panel
- Navigate to Tools section
- Find
who-am-itool - Click Execute
- View results in output panel
SampleWhoAmIPlugin/
├── WhoAmI.csproj # Project file with package metadata
├── WhoAmIPlugin.cs # Main plugin class and tool implementation
├── Models/
│ └── WhoAmIOutput.cs # Output DTO with PascalCase properties
├── README.md # This documentation (included in NuGet)
└── nupkg/ # Generated NuGet packages (not in repo)
The main plugin class decorated with [McpPlugin] attribute:
[McpPlugin("sample-whoami", "1.0.0",
Author = "TCH",
Description = "Sample plugin demonstrating Dataverse user information retrieval")]
public class WhoAmIPlugin : PluginBase
{
// Plugin lifecycle and tool registration
}Strongly-typed tool implementation:
public class WhoAmITool : McpToolBase<object, WhoAmIOutput>
{
public WhoAmITool()
: base("who-am-i", "Retrieves information about the currently connected Dataverse user...")
{
}
protected override async Task<WhoAmIOutput> ExecuteAsync(
object? parameters,
IDataverseContext context,
CancellationToken cancellationToken)
{
// Implementation
}
}Data transfer object with PascalCase properties (converted to camelCase in JSON):
public class WhoAmIOutput
{
public string UserDisplayName { get; set; }
public Guid UserId { get; set; }
public Guid BusinessUnitId { get; set; }
public Guid OrganizationId { get; set; }
public string EnvironmentUrl { get; set; }
public string Message { get; set; }
}The plugin uses two primary Dataverse operations:
var whoAmIRequest = new WhoAmIRequest();
var whoAmIResponse = (WhoAmIResponse)await context.ServiceClient
.ExecuteAsync(whoAmIRequest, cancellationToken);Retrieves:
UserId- Unique identifier of the authenticated userBusinessUnitId- User's business unitOrganizationId- Dataverse organization
var user = await context.ServiceClient.RetrieveAsync(
"systemuser",
whoAmIResponse.UserId,
new ColumnSet("fullname"),
cancellationToken);Fetches:
fullnameattribute fromsystemusertable- Fallback to "Unknown User" if retrieval fails
-
Structured Exceptions: All errors thrown as
ToolExecutionExceptionwith:- Error code (e.g.,
DATAVERSE_ERROR) - User-friendly message
- Additional context (details object)
- Error code (e.g.,
-
Graceful Degradation: If display name retrieval fails:
- Operation continues
- Returns "Unknown User" as fallback
- Logs warning to stderr
-
Cancellation Support: All async operations respect
CancellationToken -
Logging: All errors and warnings logged to stderr only
✅ Naming:
- Tool name:
who-am-i(kebab-case, enforced) - C# properties: PascalCase (
UserDisplayName) - JSON output: camelCase (
userDisplayName)
✅ Async/Await:
- All operations async with
Task<T> - CancellationToken passed to all SDK calls
- No blocking
.Resultor.Wait()calls
✅ Logging:
- Console.Error.WriteLine() for all logs
- Never write to stdout (reserved for data)
✅ Resource Management:
- Proper disposal patterns
- Lifecycle managed by Core Server
-
Install the plugin:
# From source cd SampleWhoAmIPlugin dotnet pack -c Release # Install via VS Code Extension UI
-
Create a Dataverse connection:
- Open VS Code Extension
- Add new connection
- Authenticate with OAuth device flow
-
Execute the tool:
- Via Extension UI: Click "Execute" on
who-am-itool - Via Copilot: Ask "Use who-am-i tool"
- Via direct JSON-RPC call
- Via Extension UI: Click "Execute" on
-
Verify output:
- Check user display name matches your account
- Verify all GUIDs are valid
- Confirm environment URL is correct
Success Case:
{
"userDisplayName": "Your Name",
"userId": "valid-guid",
"businessUnitId": "valid-guid",
"organizationId": "valid-guid",
"environmentUrl": "https://your-org.crm.dynamics.com",
"message": "Successfully retrieved information for user 'Your Name'"
}Error Case (No Connection):
{
"error": {
"code": "DATAVERSE_ERROR",
"message": "Failed to retrieve user information",
"details": { /* error context */ }
}
}This plugin automatically includes:
- DataverseMCPToolBox.Extensibility (v0.1.0-alpha)
- Extensibility framework
- Base classes and interfaces
- JSON Schema generation
- .NET 8.0 - Target framework
- Microsoft.PowerPlatform.Dataverse.Client (v1.1.32)
- Included transitively via Extensibility package
- Dataverse SDK operations
- NJsonSchema (v11.0.2)
- JSON Schema generation and validation
- Newtonsoft.Json (v13.0.3)
- JSON serialization
- Enhanced error messages with more context
- Improved fallback handling for display name retrieval
- Updated documentation with comprehensive examples
- Code cleanup and optimization
- Initial release
- Basic WhoAmI functionality
- Strongly-typed implementation with McpToolBase
- Complete Dataverse user information retrieval
- Package ID: DataverseMCPToolBox.WhoAmI
- Version: 1.1.0-alpha
- Author: Théophile CHIN-NIN
- License: MIT
- Target Framework: .NET 8.0
- Language: C# 12
This plugin is useful for:
- Identity Verification: Confirm which user account is currently authenticated
- Debugging: Verify connection context during development
- Auditing: Track which user performed operations
- Reference Implementation: Learn plugin development patterns
- Testing: Validate Dataverse connection and permissions
MIT License - See LICENSE file for details.
Comprehensive guides:
GitHub: https://github.com/tchinnin/dataverse-mcp-toolbox
For issues, questions, or feature requests:
- Issues: GitHub Issues
- Discussions: GitHub Discussions
This is a sample plugin for demonstration purposes. Feel free to:
- Use it as a template for your own plugins
- Submit improvements via pull requests
- Report issues or suggest enhancements
See CONTRIBUTING.md for guidelines.
- DataverseMCPToolBox.Runtime - Core Server and Bridge binaries
- DataverseMCPToolBox.Extensibility - Plugin development SDK
Théophile CHIN-NIN
- GitHub: @tchinnin
Note: This is an alpha release. APIs and behavior may change in future versions. Use in production environments at your own discretion.