Skip to content

Commit c43e513

Browse files
committed
new MCP bindings articles
1 parent ed82b77 commit c43e513

6 files changed

+318
-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",
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
title: MCP trigger for Azure Functions
3+
description: Learn how you can use a trigger endpoint to expose a functions as a model content protocol (MCP) server tool 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-lang-workers
12+
---
13+
14+
# MCP trigger for Azure Functions
15+
16+
Use the MCP trigger to create endpoints in a [Model Content Protocol (MCP)](https://github.com/modelcontextprotocol) server that are accessed by client LLMs and agents to do specific tasks, such as storing or accessing code snippets. These MCP clients can also subscribe to your MCP server (your function app) to receive notifications about changes to the exposed APIs.
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+
>[!TIP]
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.
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="java" 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="java" 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 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 `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 additional properties of a tool endpoint. In C#, you can define one or more tool properties by applying the `McpToolProperty` attribute to input binding-style parameters in your function.
155+
156+
The `McpToolPropertyAttribute` type supports these properties:
157+
158+
| Property | Description |
159+
| ---- | ----- |
160+
| **PropertyName** | Name of the tool property that gets exposed to clients. |
161+
| **PropertyType** | The data type of the tool property, such as `string`. |
162+
| **Description** | (Optional) Description of what the tool property does. |
163+
164+
::: zone-end
165+
::: zone pivot="programming-language-java,pprogramming-language-python"
166+
Properties of a tool exposed by your 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.
167+
168+
A `ToolProperty` object has this structure:
169+
170+
```json
171+
{
172+
"propertyName": "Name of the property",
173+
"propertyType": "Type of the property",
174+
"description": "Optional property description",
175+
}
176+
```
177+
::: zone-end
178+
::: zone pivot="programming-language-javascript,programming-language-typescript"
179+
Properties of a tool exposed by your 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.
180+
181+
A `ToolProperty` object has this structure:
182+
183+
```json
184+
{
185+
"propertyName": "Name of the property",
186+
"propertyValue": "Type of the property",
187+
"description": "Optional property description",
188+
}
189+
```
190+
::: zone-end
191+
192+
For more information, see [Examples](#example).
193+
194+
## host.json settings
195+
196+
The host.json file contains settings that control MCP trigger behaviors. See the [host.json settings](functions-bindings-mcp.md#host-json) section for details regarding available settings.
197+
198+
## Related articles
199+
200+
[Azure OpenAI extension for Azure Functions](functions-bindings-openai.md)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: MCP bindings for Azure Functions
3+
description: Learn how you can expose your functions as a model content protocol (MCP) server 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-lang-workers
12+
---
13+
14+
15+
# MCP 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 leverage 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 custom MCP servers. When acting as an MCP server, your function app defines a set of function endpoints that are MCP triggers, which LLMs and agents can access to do specific tasks, such as storing or accessing code snippets. These MCP clients can also subscribe to your MCP server app to receive notifications about changes to the exposed APIs.
22+
23+
[!INCLUDE [functions-mcp-extension-powershell-note](../../includes/functions-mcp-extension-powershell-note.md)]
24+
::: zone pivot="programming-language-csharp"
25+
## Prerequisites
26+
27+
+ Requires version 2.0.2 or later of the `Microsoft.Azure.Functions.Worker.Sdk` package.
28+
29+
## Install extension
30+
31+
>[!TIP]
32+
>The Azure Functions MCP extension supports only the [isolated worker model](dotnet-isolated-process-guide.md).
33+
34+
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:
35+
36+
`Microsoft.Azure.Functions.Worker.Extensions.Mcp`
37+
::: zone-end
38+
39+
::: zone pivot="programming-language-javascript,programming-language-python,programming-language-java"
40+
41+
## Install bundle
42+
43+
The MCP extension preview is part of an experimental [extension bundle], which is specified in your host.json project file.
44+
45+
To use this experimental bundle in your app, replace the existing `extensionBundle` object in your project's host.json file with this JSON object:
46+
47+
```json
48+
"extensionBundle": {
49+
"id": "Microsoft.Azure.Functions.ExtensionBundle.Experimental",
50+
"version": "[4.*, 5.0.0)"
51+
}
52+
```
53+
54+
::: zone-end
55+
56+
## host.json settings
57+
58+
[!INCLUDE [functions-host-json-section-intro](../../includes/functions-host-json-section-intro.md)]
59+
60+
```json
61+
{
62+
"version": "2.0",
63+
"extensions": {
64+
"mcp": {
65+
"instructions": "Some test instructions on how to use the server",
66+
"serverName": "TestServer",
67+
"serverVersion": "2.0.0"
68+
}
69+
}
70+
}
71+
```
72+
73+
| Property | Description |
74+
| ----- | ----- |
75+
| **instructions** | Decribes to clients how to access the server. |
76+
| **serverName** | A friendly name for the server. |
77+
| **serverVersion** | Current version of the server. |
78+
79+
80+
## Related articles
81+
82+
[Create a tool endpoint in your MCP server](./functions-bindings-mcp-trigger.md)
83+
84+
85+
[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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
::: zone pivot="programming-language-powershell"
2+
>[!IMPORTANT]
3+
>The MCP extension doesn't currently support PowerShell apps.
4+
::: zone-end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
>[!IMPORTANT]
2+
>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.
3+
>You should avoid using preview extensions in production apps.

0 commit comments

Comments
 (0)