.NET: Expose workflows as MCP tools when hosting on Azure functions#4768
.NET: Expose workflows as MCP tools when hosting on Azure functions#4768
Conversation
There was a problem hiding this comment.
Pull request overview
Exposes durable workflows hosted in Azure Functions as MCP (Model Context Protocol) tools, enabling MCP clients to discover and invoke workflows through the Functions MCP webhook endpoint.
Changes:
- Add MCP tool trigger registration via function metadata transformation + built-in executor support.
- Add unit + integration tests validating MCP tool metadata and end-to-end tool invocation.
- Add a new Azure Functions sample demonstrating two workflows exposed as MCP tools.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/Workflows/DurableWorkflowsFunctionMetadataTransformer.cs | Registers MCP tool trigger functions per workflow when enabled in options. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/Workflows/DurableWorkflowOptionsExtensions.cs | Adds an AddWorkflow overload to opt into status endpoint and/or MCP tool trigger. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/FunctionsDurableOptions.cs | Tracks which workflows enable MCP tool triggers. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/FunctionsApplicationBuilderExtensions.cs | Ensures middleware/executor registration covers MCP tool entry point. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/FunctionMetadataFactory.cs | Creates function metadata for MCP tool trigger functions. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/BuiltInFunctions.cs | Implements RunWorkflowMcpToolAsync to run workflows via MCP invocation. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/BuiltInFunctionExecutor.cs | Dispatches MCP tool invocations to the new built-in entry point. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/CHANGELOG.md | Notes the new MCP tool trigger support in Unreleased. |
| dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests/FunctionMetadataFactoryTests.cs | Adds unit tests for MCP tool trigger metadata generation. |
| dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/WorkflowSamplesValidation.cs | Adds an integration test that lists and calls MCP tools exposed by the host. |
| dotnet/samples/04-hosting/DurableWorkflows/README.md | Lists the new MCP tool sample. |
| dotnet/samples/04-hosting/DurableWorkflows/AzureFunctions/04_WorkflowMcpTool/* | New sample app demonstrating workflows exposed as MCP tools. |
| dotnet/agent-framework-dotnet.slnx | Includes the new sample project in the solution. |
dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/BuiltInFunctions.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/BuiltInFunctions.cs
Show resolved
Hide resolved
...src/Microsoft.Agents.AI.Hosting.AzureFunctions/Workflows/DurableWorkflowOptionsExtensions.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/FunctionMetadataFactory.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/FunctionMetadataFactory.cs
Outdated
Show resolved
Hide resolved
...sts/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/WorkflowSamplesValidation.cs
Outdated
Show resolved
Hide resolved
...sts/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/WorkflowSamplesValidation.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/CHANGELOG.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Adds opt-in support for exposing Durable Workflows hosted in Microsoft.Agents.AI.Hosting.AzureFunctions as MCP (Model Context Protocol) tools, enabling MCP clients to discover and invoke workflows via the Functions MCP webhook endpoint.
Changes:
- Introduces workflow-level configuration (
exposeMcpToolTrigger) and internal tracking to register MCP tool triggers for selected workflows. - Adds MCP tool trigger function metadata generation and a built-in executor path that runs a workflow and returns its serialized result.
- Adds unit/integration coverage plus a new Azure Functions sample demonstrating MCP tool invocation for workflows.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/Workflows/DurableWorkflowsFunctionMetadataTransformer.cs | Registers MCP tool-trigger functions for workflows when enabled. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/Workflows/DurableWorkflowOptionsExtensions.cs | Adds AddWorkflow(..., exposeMcpToolTrigger) overload to enable MCP triggers. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/FunctionsDurableOptions.cs | Tracks which workflows have MCP tool triggers enabled. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/FunctionsApplicationBuilderExtensions.cs | Ensures built-in middleware/executor routing includes the MCP workflow entry point. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/FunctionMetadataFactory.cs | Adds factory method to generate MCP tool trigger bindings for workflows. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/BuiltInFunctions.cs | Adds RunWorkflowMcpToolAsync to schedule and await workflow completion for MCP calls. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/BuiltInFunctionExecutor.cs | Routes the new MCP workflow entry point to the corresponding built-in handler. |
| dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/CHANGELOG.md | Adds an unreleased changelog entry for workflow MCP tool trigger support. |
| dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests/FunctionMetadataFactoryTests.cs | New unit tests validating function metadata factory output (incl. MCP workflow trigger). |
| dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/WorkflowSamplesValidation.cs | Adds an integration test that connects via MCP, lists tools, and invokes workflow tools. |
| dotnet/samples/04-hosting/DurableWorkflows/README.md | Links the new workflow MCP tool sample from the samples index. |
| dotnet/samples/04-hosting/DurableWorkflows/AzureFunctions/04_WorkflowMcpTool/* | New Azure Functions sample app demonstrating two workflows exposed as MCP tools. |
| dotnet/agent-framework-dotnet.slnx | Adds the new sample project to the solution. |
dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/BuiltInFunctions.cs
Outdated
Show resolved
Hide resolved
| if (registeredFunctions.Add(mcpToolFunctionName)) | ||
| { | ||
| this._logger.LogRegisteringWorkflowTrigger(workflow.Key, mcpToolFunctionName, "mcpTool"); | ||
| original.Add(FunctionMetadataFactory.CreateWorkflowMcpToolTrigger(workflow.Key, workflow.Value.Description)); |
There was a problem hiding this comment.
Is it possible for an agent and a workflow to have the same key value? And if so, does that mean it's possible to have a duplicate MCP function name if both enable MCP triggering?
There was a problem hiding this comment.
Currently, this fails during worker indexing (at app startup). The resulting error message is not very helpful for the user.
Error indexing method 'Functions.dafx-Joker'. Microsoft.Azure.WebJobs.Host: Method overloads are not supported. There are multiple methods with the name 'Host.Functions.dafx-Joker'."
The root cause is that we use the same prefix (dafx-) for both agents and workflows, which leads to duplicate function names. This issue also exists for HTTP triggers when an agent and a workflow share the same name.
One potential solution is to use a different prefix for workflows (e.g., dafxw-). We can address that separately once we decide on the approach. Let me follow up offline on this.
While validating this scenario, I also discovered another bug where having both workflows and agents together did not behave as expected in azure functions hosting scenario. I’ve fixed this issue and added a new sample to demonstrate the correct behavior.
Motivation and Context
This PR adds support for exposing durable workflows as MCP (Model Context Protocol) tools in
Microsoft.Agents.AI.Hosting.AzureFunctions. This mirrors the existing agent MCP tool support (AddAIAgent(enableMcpToolTrigger: true)) but for workflows.When enabled, the Azure Functions host automatically registers an MCP tool trigger for the workflow at the
/runtime/webhooks/mcpendpoint, allowing MCP-compatible clients todiscover and invoke the workflow as a tool.
Usage
New Public APIs
DurableWorkflowOptionsExtensionsAddWorkflow(DurableWorkflowOptions, Workflow, bool exposeStatusEndpoint, bool exposeMcpToolTrigger)Implementation details
FunctionsDurableOptions— Tracks which workflows have MCP tool triggers enabled (internal, mirrors status endpoint pattern)FunctionMetadataFactory.CreateWorkflowMcpToolTrigger— Generates function metadata usingSystem.Text.Json.Nodes.JsonObject(AOT-safe, no manual string escaping)BuiltInFunctions.RunWorkflowMcpToolAsync— Schedules an orchestration, waits for completion, validatesRuntimeStatus, and returns theDurableWorkflowResult.ResultBuiltInFunctionExecutor— Routes the new entry point toRunWorkflowMcpToolAsyncDurableWorkflowsFunctionMetadataTransformer— Registers the MCP tool trigger when enabledFunctionsApplicationBuilderExtensions— Adds the new entry point to the middleware filterSample app
Added
04_WorkflowMcpToolunderdotnet/samples/04-hosting/DurableWorkflows/AzureFunctions/with two workflows:Tests
FunctionMetadataFactoryTests.cs) — 7 tests covering all factory methods, including JSON validity validation viaJsonDocument.Parse()WorkflowSamplesValidation.cs) — Connects via MCP client (HttpClientTransport), lists tools, invokes both workflows, and asserts resultsContribution Checklist