Skip to content

Commit 782d6ce

Browse files
authored
Merge pull request #299420 from ggailey777/build-mcp
[Functions] new MCP bindings articles
2 parents e71955d + 621a36a commit 782d6ce

7 files changed

+358
-2
lines changed

.openpublishing.publish.config.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,30 @@
140140
"branch": "main",
141141
"branch_mapping": {}
142142
},
143+
{
144+
"path_to_root": "remote-mcp-functions-dotnet",
145+
"url": "https://github.com/Azure-Samples/remote-mcp-functions-dotnet",
146+
"branch": "main",
147+
"branch_mapping": {}
148+
},
149+
{
150+
"path_to_root": "remote-mcp-functions-typescript",
151+
"url": "https://github.com/Azure-Samples/remote-mcp-functions-typescript",
152+
"branch": "main",
153+
"branch_mapping": {}
154+
},
155+
{
156+
"path_to_root": "remote-mcp-functions-python",
157+
"url": "https://github.com/Azure-Samples/remote-mcp-functions-python",
158+
"branch": "main",
159+
"branch_mapping": {}
160+
},
161+
{
162+
"path_to_root": "remote-mcp-functions-java",
163+
"url": "https://github.com/Azure-Samples/remote-mcp-functions-java",
164+
"branch": "main",
165+
"branch_mapping": {}
166+
},
143167
{
144168
"path_to_root": "azure-functions-durable-js",
145169
"url": "https://github.com/Azure/azure-functions-durable-js",

articles/azure-functions/TOC.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,14 @@
10151015
- name: Output
10161016
href: functions-bindings-kafka-output.md
10171017
displayName: Kafka
1018+
- name: MCP tool
1019+
items:
1020+
- name: Overview
1021+
href: functions-bindings-mcp.md
1022+
displayName: MCP tool
1023+
- name: Trigger
1024+
href: functions-bindings-mcp-trigger.md
1025+
displayName: MCP tool
10181026
- name: Mobile Apps
10191027
href: functions-bindings-mobile-apps.md
10201028
- name: Notification Hubs
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
---
2+
title: MCP tool trigger for Azure Functions
3+
description: Learn how you can use a trigger endpoint to expose functions as a model content protocol (MCP) server tools in Azure Functions.
4+
ms.topic: reference
5+
ms.date: 05/06/2025
6+
ms.custom:
7+
- build-2025
8+
ai-usage: ai-assisted
9+
ms.collection:
10+
- ce-skilling-ai-copilot
11+
zone_pivot_groups: programming-languages-set-functions
12+
---
13+
14+
# MCP tool trigger for Azure Functions
15+
16+
Use the MCP tool trigger to define tool endpoints in a [Model Content Protocol (MCP)](https://github.com/modelcontextprotocol) server that are accessed by client language models and agents to do specific tasks, such as storing or accessing code snippets. MCP clients can also subscribe to your function app to receive notifications about changes to the exposed tools.
17+
18+
[!INCLUDE [functions-mcp-extension-preview-note](../../includes/functions-mcp-extension-preview-note.md)]
19+
20+
For information on setup and configuration details, see the [overview](functions-bindings-mcp.md).
21+
22+
## Example
23+
24+
::: zone pivot="programming-language-csharp"
25+
>[!NOTE]
26+
>The Azure Functions MCP extension supports only the [isolated worker model](dotnet-isolated-process-guide.md).
27+
28+
This code creates an endpoint to expose a tool named `GetSnippet` that tries to retrieve a code snippet by name from blob storage.
29+
30+
:::code language="csharp" source="~/remote-mcp-functions-dotnet/src/SnippetsTool.cs" range="10-20" :::
31+
32+
This code creates an endpoint to expose a tool named `SaveSnippet` that tries to persist a named code snippet to blob storage.
33+
34+
:::code language="csharp" source="~/remote-mcp-functions-dotnet/src/SnippetsTool.cs" range="10, 22-34" :::
35+
36+
For the complete code example, see [SnippetTool.cs](https://github.com/Azure-Samples/remote-mcp-functions-dotnet/blob/main/src/SnippetsTool.cs).
37+
::: zone-end
38+
::: zone pivot="programming-language-java"
39+
This code creates an endpoint to expose a tool named `GetSnippets` that tries to retrieve a code snippet by name from blob storage.
40+
41+
:::code language="java" source="~/remote-mcp-functions-java/src/main/java/com/function/Snippets.java" range="128-155" :::
42+
43+
This code creates an endpoint to expose a tool named `SaveSnippets` that tries to persist a named code snippet to blob storage.
44+
45+
:::code language="java" source="~/remote-mcp-functions-java/src/main/java/com/function/Snippets.java" range="85-114" :::
46+
47+
For the complete code example, see [Snippets.java](https://github.com/Azure-Samples/remote-mcp-functions-java/blob/main/src/main/java/com/function/Snippets.java).
48+
::: zone-end
49+
::: zone pivot="programming-language-javascript"
50+
Example code for JavaScript isn't currently available. See the TypeScript examples for general guidance using Node.js.
51+
::: zone-end
52+
::: zone pivot="programming-language-typescript"
53+
This code creates an endpoint to expose a tool named `getsnippet` that tries to retrieve a code snippet by name from blob storage.
54+
55+
:::code language="typescript" source="~/remote-mcp-functions-typescript/src/functions/snippetsMcpTool.ts" range="79-91" :::
56+
57+
This is the code that handles the `getsnippet` trigger:
58+
59+
:::code language="typescript" source="~/remote-mcp-functions-typescript/src/functions/snippetsMcpTool.ts" range="26-48" :::
60+
61+
This code creates an endpoint to expose a tool named `savesnippet` that tries to persist a named code snippet to blob storage.
62+
63+
:::code language="typescript" source="~/remote-mcp-functions-typescript/src/functions/snippetsMcpTool.ts" range="94-111" :::
64+
65+
This is the code that handles the `savesnippet` trigger:
66+
67+
:::code language="typescript" source="~/remote-mcp-functions-typescript/src/functions/snippetsMcpTool.ts" range="51-76" :::
68+
69+
For the complete code example, see [snippetsMcpTool.ts](https://github.com/Azure-Samples/remote-mcp-functions-typescript/blob/main/src/functions/snippetsMcpTool.ts).
70+
::: zone-end
71+
::: zone pivot="programming-language-python"
72+
This code uses the `generic_trigger` decorator to create an endpoint to expose a tool named `get_snippet` that tries to retrieve a code snippet by name from blob storage.
73+
74+
:::code language="python" source="~/remote-mcp-functions-python/src/function_app.py" range="61-82" :::
75+
76+
This code uses the `generic_trigger` decorator to create an endpoint to expose a tool named `save_snippet` that tries to persist a named code snippet to blob storage.
77+
78+
:::code language="python" source="~/remote-mcp-functions-python/src/function_app.py" range="85-106" :::
79+
80+
For the complete code example, see [function_app.py](https://github.com/Azure-Samples/remote-mcp-functions-python/blob/main/src/function_app.py).
81+
::: zone-end
82+
[!INCLUDE [functions-mcp-extension-powershell-note](../../includes/functions-mcp-extension-powershell-note.md)]
83+
::: zone pivot="programming-language-csharp"
84+
## Attributes
85+
86+
C# libraries use `McpToolTriggerAttribute` to define the function trigger.
87+
88+
The attribute's constructor takes the following parameters:
89+
90+
|Parameter | Description|
91+
|---------|----------------------|
92+
|**ToolName**| (Required) name of the tool that's being exposed by the MCP trigger endpoint. |
93+
|**Description**| (Optional) friendly description of the tool endpoint for clients. |
94+
95+
See [Usage](#usage) to learn how to define properties of the endpoint as input parameters.
96+
97+
::: zone-end
98+
::: zone pivot="programming-language-java"
99+
100+
## Annotations
101+
102+
The `McpTrigger` annotation creates a function that exposes a tool endpoint in your remote MCP server.
103+
104+
The annotation supports the following configuration options:
105+
106+
|Parameter | Description|
107+
|---------|----------------------|
108+
| **toolName**| (Required) name of the tool that's being exposed by the MCP trigger endpoint. |
109+
| **description**| (Optional) friendly description of the tool endpoint for clients. |
110+
| **toolProperties** | The JSON string representation of one or more property objects that expose properties of the tool to clients. |
111+
112+
::: zone-end
113+
::: zone pivot="programming-language-python"
114+
## Decorators
115+
116+
_Applies only to the Python v2 programming model._
117+
118+
>[!NOTE]
119+
>At this time, you must use a generic decorator to define an MCP trigger.
120+
121+
The following MCP trigger properties are supported on `generic_trigger`:
122+
123+
| Property | Description |
124+
|-------------|-----------------------------|
125+
| **type** | (Required) Must be set to `mcpToolTrigger` in the `generic_trigger` decorator. |
126+
| **arg_name** | The variable name (usually `context`) used in function code to access the execution context. |
127+
| **toolName** | (Required) The name of the MCP server tool exposed by the function endpoint. |
128+
| **description** | A description of the MCP server tool exposed by the function endpoint. |
129+
| **toolProperties** | The JSON string representation of one or more property objects that expose properties of the tool to clients. |
130+
131+
::: zone-end
132+
::: zone pivot="programming-language-javascript,programming-language-typescript"
133+
## Configuration
134+
135+
The trigger supports these binding options, which are defined in your code:
136+
137+
| Options | Description |
138+
|-----------------------|-------------|
139+
| **type** | Must be set to `mcpToolTrigger`. Only used with generic definitions. |
140+
| **toolName** | (Required) The name of the MCP server tool exposed by the function endpoint. |
141+
| **description** | A description of the MCP server tool exposed by the function endpoint. |
142+
| **toolProperties** | An array of `toolProperty` objects that expose properties of the tool to clients. |
143+
| **extraOutputs** | When defined, sends function output to another binding. |
144+
| **handler** | The method that contains the actual function code. |
145+
146+
::: zone-end
147+
148+
See the [Example section](#example) for complete examples.
149+
150+
## Usage
151+
152+
::: zone pivot="programming-language-csharp"
153+
154+
The MCP protocol enables an MCP server to make known to clients other properties of a tool endpoint. In C#, you can define properties of your tools as either input parameters using the `McpToolProperty` attribute to your trigger function code or by using the `FunctionsApplicationBuilder` when the app starts.
155+
156+
### [`McpToolPropertyAttribute`](#tab/attribute)
157+
158+
You can define one or more tool properties by applying the `McpToolProperty` attribute to input binding-style parameters in your function.
159+
160+
The `McpToolPropertyAttribute` type supports these properties:
161+
162+
| Property | Description |
163+
| ---- | ----- |
164+
| **PropertyName** | Name of the tool property that gets exposed to clients. |
165+
| **PropertyType** | The data type of the tool property, such as `string`. |
166+
| **Description** | (Optional) Description of what the tool property does. |
167+
168+
You can see these attributes used in the `SaveSnippet` tool in the [Examples](#example).
169+
170+
### [`FunctionsApplicationBuilder`](#tab/builder)
171+
172+
You can define tool properties in your entry point (program.cs) file by using the `McpToolBuilder` returned by the `ConfigureMcpTool` method on `FunctionsApplicationBuilder`. This example calls the `WithProperty` method on the builder for the `GetSnippet` tool to set the properties of the tool:
173+
174+
:::code language="csharp" source="~/remote-mcp-functions-dotnet/src/Program.cs" range="5-15" :::
175+
176+
For the complete example, see the [program.cs file](https://github.com/Azure-Samples/remote-mcp-functions-dotnet/blob/main/src/Program.cs).
177+
178+
---
179+
180+
::: zone-end
181+
::: zone pivot="programming-language-java,programming-language-python"
182+
Properties of a tool exposed by your remote MCP server are defined using tool properties. These properties are returned by the `toolProperties` field, which is a string representation of an array of `ToolProperty` objects.
183+
184+
A `ToolProperty` object has this structure:
185+
186+
```json
187+
{
188+
"propertyName": "Name of the property",
189+
"propertyType": "Type of the property",
190+
"description": "Optional property description",
191+
}
192+
```
193+
::: zone-end
194+
::: zone pivot="programming-language-javascript,programming-language-typescript"
195+
Properties of a tool exposed by your remote MCP server are defined using tool properties. These properties are returned by the `toolProperties` field, which is a string representation of an array of `ToolProperty` objects.
196+
197+
A `ToolProperty` object has this structure:
198+
199+
```json
200+
{
201+
"propertyName": "Name of the property",
202+
"propertyValue": "Type of the property",
203+
"description": "Optional property description",
204+
}
205+
```
206+
::: zone-end
207+
208+
For more information, see [Examples](#example).
209+
210+
## host.json settings
211+
212+
The host.json file contains settings that control MCP trigger behaviors. See the [host.json settings](functions-bindings-mcp.md#hostjson-settings) section for details regarding available settings.
213+
214+
## Related articles
215+
216+
[Azure OpenAI extension for Azure Functions](functions-bindings-openai.md)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: MCP tool bindings for Azure Functions
3+
description: Learn how you can expose your functions as model content protocol (MCP) tools using bindings in Azure Functions.
4+
ms.topic: reference
5+
ms.date: 05/03/2025
6+
ms.custom:
7+
- build-2025
8+
ai-usage: ai-assisted
9+
ms.collection:
10+
- ce-skilling-ai-copilot
11+
zone_pivot_groups: programming-languages-set-functions
12+
---
13+
14+
15+
# MCP tool bindings for Azure Functions overview
16+
17+
The [Model Content Protocol (MCP)](https://github.com/modelcontextprotocol) is a client-server protocol intended to enable language models and agents to more efficiently discover and use external data sources and tools.
18+
19+
[!INCLUDE [functions-mcp-extension-preview-note](../../includes/functions-mcp-extension-preview-note.md)]
20+
21+
The Azure Functions MCP extension allows you to use Azure Functions to create remote MCP servers. Your function app implements a remote MCP server by exposing a set of endpoints that are implemented as MCP tool trigger functions. MCP clients, such as language models and agents, can query and access these tools to do specific tasks, such as storing or accessing code snippets. MCP clients can also subscribe to your app to receive notifications about changes to the exposed tools.
22+
23+
[!INCLUDE [functions-mcp-extension-powershell-note](../../includes/functions-mcp-extension-powershell-note.md)]
24+
## Prerequisites
25+
26+
+ The MCP tool trigger relies on Azure Queue storage provided by the [default host storage account](./storage-considerations.md) (`AzureWebJobsStorage`). When using managed identities, make sure that your function app has at least the equivalent of these role-based permissions in the host storage account: [Storage Queue Data Reader](/azure/role-based-access-control/built-in-roles#storage-queue-data-reader) and [Storage Queue Data Message Processor](/azure/role-based-access-control/built-in-roles#storage-queue-data-message-processor).
27+
+ When running locally, the MCP extension requires version 4.0.7030 of the [Azure Functions Core Tools](functions-run-local.md), or a later version.
28+
::: zone pivot="programming-language-csharp"
29+
+ Requires version 2.0.2 or later of the `Microsoft.Azure.Functions.Worker.Sdk` package.
30+
31+
## Install extension
32+
33+
>[!TIP]
34+
>The Azure Functions MCP extension supports only the [isolated worker model](dotnet-isolated-process-guide.md).
35+
36+
Add the extension to your project by installing this [NuGet package](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Mcp) in your preferred way:
37+
38+
`Microsoft.Azure.Functions.Worker.Extensions.Mcp`
39+
::: zone-end
40+
41+
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-java"
42+
43+
## Install bundle
44+
45+
The MCP extension preview is part of an experimental [extension bundle], which is specified in your host.json project file.
46+
47+
To use this experimental bundle in your app, replace the existing `extensionBundle` object in your project's host.json file with this JSON object:
48+
49+
```json
50+
"extensionBundle": {
51+
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
52+
"version": "[4.*, 5.0.0)"
53+
}
54+
```
55+
56+
::: zone-end
57+
58+
## host.json settings
59+
60+
[!INCLUDE [functions-host-json-section-intro](../../includes/functions-host-json-section-intro.md)]
61+
62+
```json
63+
{
64+
"version": "2.0",
65+
"extensions": {
66+
"mcp": {
67+
"instructions": "Some test instructions on how to use the server",
68+
"serverName": "TestServer",
69+
"serverVersion": "2.0.0"
70+
}
71+
}
72+
}
73+
```
74+
75+
| Property | Description |
76+
| ----- | ----- |
77+
| **instructions** | Describes to clients how to access the remote MCP server. |
78+
| **serverName** | A friendly name for the remote MCP server. |
79+
| **serverVersion** | Current version of the remote MCP server. |
80+
81+
82+
## Related articles
83+
84+
[Create a tool endpoint in your remote MCP server](./functions-bindings-mcp-trigger.md)
85+
86+
87+
[extension bundle]: ./functions-bindings-register.md#extension-bundles

includes/functions-host-json-section-intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
author: ggailey777
33
ms.service: azure-functions
44
ms.topic: include
5-
ms.date: 10/05/2021
5+
ms.date: 05/05/2025
66
ms.author: glenga
77
---
88

9-
This section describes the configuration settings available for this binding in version 2.x and later. Settings in the host.json file apply to all functions in a function app instance. The following example host.json file contains only the version 2.x+ settings for this binding. For more information about function app configuration settings in version 2.x and later, see [host.json reference for Azure Functions](../articles/azure-functions/functions-host-json.md).
9+
This section describes the configuration settings available for this binding in version 2.x and later. Settings in the host.json file apply to all functions in a function app instance. For more information about function app configuration settings, see [host.json reference for Azure Functions](../articles/azure-functions/functions-host-json.md).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
author: ggailey777
3+
ms.service: azure-functions
4+
ms.topic: include
5+
ms.date: 05/09/2025
6+
ms.author: glenga
7+
---
8+
::: zone pivot="programming-language-powershell"
9+
>[!IMPORTANT]
10+
>The MCP extension doesn't currently support PowerShell apps.
11+
::: zone-end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
author: ggailey777
3+
ms.service: azure-functions
4+
ms.topic: include
5+
ms.date: 05/09/2025
6+
ms.author: glenga
7+
---
8+
>[!IMPORTANT]
9+
>The Azure Functions MCP extension is currently in preview. You can expect changes to the trigger and binding APIs until the extension becomes generally available.
10+
>You should avoid using preview extensions in production apps.

0 commit comments

Comments
 (0)