- I don't think the issue is that copilot studio doesn't support it, i think it is to do with the fact that copilot studio sends the ID out in string format, but the SDK responds in a integer. It should be solveable with
's idea.. But can i hell as get the custom code to accept the modified return response. (it is almost like MCP does not want to see a manipulated return).
This is the proxy code (i have tried to boil it down to absolute basics) - I cannot get it to work -
public class Script : ScriptBase
{
public override async Task<HttpResponseMessage> ExecuteAsync()
{
// Check if the operation ID matches what is specified in the OpenAPI definition of the connector
//if (this.Context.OperationId == "InvokeMCP")
//{
// Use the context to forward/send an HTTP request
HttpResponseMessage response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
// Do the transformation if the response was successful, otherwise return error responses as-is
if (response.IsSuccessStatusCode)
{
var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false);
// Example case: response string is some JSON object
var result = JObject.Parse(responseString);
// Example transformation: convert the "id" field from a number to a string
// Ensure the "id" field exists and is a number before transforming
//if (!result.ContainsKey("id") || result["id"] == null || !(result["id"] is JValue) || ((JValue)result["id"]).Type != JTokenType.Integer)
//{
// If the "id" field is not present or not a number, return an error response
// HttpResponseMessage errorResponse = new HttpResponseMessage(HttpStatusCode.BadRequest);
// errorResponse.Content = CreateJsonContent("The 'id' field is missing or not a number.");
// return errorResponse;
//}
// Convert the "id" field to a string
var num = (JValue)result["id"];
result["id"] = num.ToString();
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = CreateJsonContent(result.ToString());
}
return response;
//}
// Handle an invalid operation ID
//HttpResponseMessage responsefail = new HttpResponseMessage(HttpStatusCode.BadRequest);
//responsefail.Content = CreateJsonContent($"Unknown operation ID '{this.Context.OperationId}'");
//return responsefail;
}
}