Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions DataverseDevToolsMcpServer/Helpers/DataManagementHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public static string CleanRequestUrl(string requestUrl)
}
return requestUrl;
}

public static Dictionary<string, List<string>>? ConvertCustomHeaders(Dictionary<string, string>? customHeaders)
{
return customHeaders?.ToDictionary(h => h.Key, h => new List<string> { h.Value });
}
}


Expand Down
25 changes: 15 additions & 10 deletions DataverseDevToolsMcpServer/Tools/DataManagementTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task<string> ExecuteWebApi(
[Description(@"Web API request URL (relative to the service root URL).Request url should not contain /api/data/v9.*/.
The path and query parameters that you wish to pass onto the Web API")] string requestUrl,
[Description("Request body in JSON format (for POST and PATCH requests)")] string requestBody = null,
[Description("Additional headers")] Dictionary<String, List<String>> customHeaders = null,
[Description("Additional headers")] Dictionary<string, string> customHeaders = null,
[Description("Content Type")] string contentType = "application/json"
)
{
Expand All @@ -123,7 +123,8 @@ public async Task<string> ExecuteWebApi(
{
var method = new System.Net.Http.HttpMethod(httpMethod.ToUpper());
requestUrl =DataManagementHelper.CleanRequestUrl(requestUrl);
var response = await serviceClient.ExecuteWebRequestAsync(method, requestUrl, requestBody, customHeaders, contentType);
var convertedHeaders = DataManagementHelper.ConvertCustomHeaders(customHeaders);
var response = await serviceClient.ExecuteWebRequestAsync(method, requestUrl, requestBody, convertedHeaders, contentType);
if (response.IsSuccessStatusCode)
{
//append response headers to result
Expand Down Expand Up @@ -163,7 +164,7 @@ public async Task<string> CreateRecord(
[Description(@"Record data in JSON format.
Prepare the payload based on field/column type.
For lookup columns,find the field/column schema name using entity metadata and use the <<field/column's schema name>>@odata.bind in payload")] string recordDataJson,
[Description("Additional headers")] Dictionary<String, List<String>> customHeaders = null,
[Description("Additional headers")] Dictionary<string, string> customHeaders = null,
[Description("Content Type")] string contentType = "application/json"
)
{
Expand All @@ -174,7 +175,8 @@ Prepare the payload based on field/column type.
try
{
//var requestUrl = $"/api/data/v9.2/{entitySetName}";
var response = await serviceClient.ExecuteWebRequestAsync(new System.Net.Http.HttpMethod("POST"), entitySetName, recordDataJson, customHeaders, contentType);
var convertedHeaders = DataManagementHelper.ConvertCustomHeaders(customHeaders);
var response = await serviceClient.ExecuteWebRequestAsync(new System.Net.Http.HttpMethod("POST"), entitySetName, recordDataJson, convertedHeaders, contentType);
if (response.IsSuccessStatusCode)
{
if (response.Headers.Contains("OData-EntityId"))
Expand Down Expand Up @@ -211,7 +213,7 @@ public async Task<string> UpdateRecord(
[Description(@"Record data in JSON format.
Prepare the payload based on field/column type.
For lookup columns,find the field/column schema name using entity metadata and use the <<field/column's schema name>>@odata.bind in payload")] string recordDataJson,
[Description("Additional headers")] Dictionary<String, List<String>> customHeaders = null,
[Description("Additional headers")] Dictionary<string, string> customHeaders = null,
[Description("Content Type")] string contentType = "application/json"
)
{
Expand All @@ -224,7 +226,8 @@ Prepare the payload based on field/column type.
try
{
//var requestUrl = $"/api/data/v9.2/{entitySetName}";
var response = await serviceClient.ExecuteWebRequestAsync(new System.Net.Http.HttpMethod("PATCH"), entitySetName, recordDataJson, customHeaders, contentType);
var convertedHeaders = DataManagementHelper.ConvertCustomHeaders(customHeaders);
var response = await serviceClient.ExecuteWebRequestAsync(new System.Net.Http.HttpMethod("PATCH"), entitySetName, recordDataJson, convertedHeaders, contentType);
if (response.IsSuccessStatusCode)
{

Expand Down Expand Up @@ -260,7 +263,7 @@ public async Task<string> UpsertRecord(
[Description(@"Record data in JSON format.
Prepare the payload based on field/column type.
For lookup columns,find the field/column schema name using entity metadata and use the <<field/column's schema name>>@odata.bind in payload")] string recordDataJson,
[Description("Additional headers")] Dictionary<String, List<String>> customHeaders = null,
[Description("Additional headers")] Dictionary<string, string> customHeaders = null,
[Description("Content Type")] string contentType = "application/json"
)
{
Expand All @@ -274,7 +277,8 @@ Prepare the payload based on field/column type.
try
{
//var requestUrl = $"/api/data/v9.2/{entitySetName}";
var response = await serviceClient.ExecuteWebRequestAsync(new System.Net.Http.HttpMethod("PATCH"), entitySetName, recordDataJson, customHeaders, contentType);
var convertedHeaders = DataManagementHelper.ConvertCustomHeaders(customHeaders);
var response = await serviceClient.ExecuteWebRequestAsync(new System.Net.Http.HttpMethod("PATCH"), entitySetName, recordDataJson, convertedHeaders, contentType);
if (response.IsSuccessStatusCode)
{

Expand All @@ -299,7 +303,7 @@ public async Task<string> DeleteRecord(
ServiceClient serviceClient,
[Description("Entity Set Name from Entity metadata")] string entitySetName,
[Description("Record Id")] string recordId,
[Description("Additional headers")] Dictionary<String, List<String>> customHeaders = null,
[Description("Additional headers")] Dictionary<string, string> customHeaders = null,
[Description("Content Type")] string contentType = "application/json"
)
{
Expand All @@ -311,7 +315,8 @@ public async Task<string> DeleteRecord(
try
{
//var requestUrl = $"/api/data/v9.2/{entitySetName}";
var response = await serviceClient.ExecuteWebRequestAsync(new System.Net.Http.HttpMethod("DELETE"), entitySetName, null, customHeaders, contentType);
var convertedHeaders = DataManagementHelper.ConvertCustomHeaders(customHeaders);
var response = await serviceClient.ExecuteWebRequestAsync(new System.Net.Http.HttpMethod("DELETE"), entitySetName, null, convertedHeaders, contentType);
if (response.IsSuccessStatusCode)
{
result = $"Record deleted successfully. Entity ID: {recordId}";
Expand Down