PR feedback fixes

This commit is contained in:
Shyju Krishnankutty
2026-03-18 14:56:43 -07:00
parent c8991857b0
commit 2fe2f4400a
6 changed files with 66 additions and 20 deletions
@@ -409,7 +409,22 @@ internal static class BuiltInFunctions
getInputsAndOutputs: true,
cancellation: functionContext.CancellationToken);
return metadata?.ReadOutputAs<DurableWorkflowResult>()?.Result;
if (metadata is null)
{
throw new InvalidOperationException($"Workflow orchestration '{instanceId}' returned no metadata.");
}
if (metadata.RuntimeStatus is OrchestrationRuntimeStatus.Failed)
{
throw new InvalidOperationException($"Workflow orchestration '{instanceId}' failed: {metadata.ReadOutputAs<string>()}");
}
if (metadata.RuntimeStatus is not OrchestrationRuntimeStatus.Completed)
{
throw new InvalidOperationException($"Workflow orchestration '{instanceId}' ended with unexpected status '{metadata.RuntimeStatus}'.");
}
return metadata.ReadOutputAs<DurableWorkflowResult>()?.Result;
}
/// <summary>
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json.Nodes;
using Microsoft.Agents.AI.DurableTask;
using Microsoft.Azure.Functions.Worker.Core.FunctionMetadata;
@@ -112,28 +113,49 @@ internal static class FunctionMetadataFactory
var functionName = $"{BuiltInFunctions.McpToolPrefix}{workflowName}";
var toolDescription = description ?? $"Run the {workflowName} workflow";
const string ToolProperties =
"""[{\"propertyName\":\"input\",\"propertyType\":\"string\",\"description\":\"The input to the workflow.\",\"isRequired\":true,\"isArray\":false}]""";
var toolProperties = new JsonArray(new JsonObject
{
["propertyName"] = "input",
["propertyType"] = "string",
["description"] = "The input to the workflow.",
["isRequired"] = true,
["isArray"] = false,
});
var TriggerBinding =
$$"""{"name":"context","type":"mcpToolTrigger","direction":"In","toolName":"{{workflowName}}","description":"{{toolDescription}}","toolProperties":"{{ToolProperties}}"}""";
var triggerBinding = new JsonObject
{
["name"] = "context",
["type"] = "mcpToolTrigger",
["direction"] = "In",
["toolName"] = workflowName,
["description"] = toolDescription,
["toolProperties"] = toolProperties.ToJsonString(),
};
const string InputBinding =
"""{"name":"input","type":"mcpToolProperty","direction":"In","propertyName":"input","description":"The input to the workflow","isRequired":true,"dataType":"String","propertyType":"string"}""";
var inputBinding = new JsonObject
{
["name"] = "input",
["type"] = "mcpToolProperty",
["direction"] = "In",
["propertyName"] = "input",
["description"] = "The input to the workflow",
["isRequired"] = true,
["dataType"] = "String",
["propertyType"] = "string",
};
const string ClientBinding =
"""{"name":"client","type":"durableClient","direction":"In"}""";
var clientBinding = new JsonObject
{
["name"] = "client",
["type"] = "durableClient",
["direction"] = "In",
};
return new DefaultFunctionMetadata
{
Name = functionName,
Language = "dotnet-isolated",
RawBindings =
[
TriggerBinding,
InputBinding,
ClientBinding
],
RawBindings = [triggerBinding.ToJsonString(), inputBinding.ToJsonString(), clientBinding.ToJsonString()],
EntryPoint = BuiltInFunctions.RunWorkflowMcpToolFunctionEntryPoint,
ScriptFile = BuiltInFunctions.ScriptFile,
};
@@ -29,7 +29,7 @@ public static class DurableWorkflowOptionsExtensions
}
/// <summary>
/// Adds a workflow and optionally exposes a status HTTP endpoint and/or an MCP tool trigger.
/// Adds a workflow and configures whether to expose a status HTTP endpoint and/or an MCP tool trigger.
/// </summary>
/// <param name="options">The workflow options to add the workflow to.</param>
/// <param name="workflow">The workflow instance to add.</param>