Skip to content

Commit 02bed81

Browse files
authored
Merge pull request #313022 from ggailey777/mcp-java-updates
[Functions] Update MCP server docs with Java examples and correct paths
2 parents 99b82f5 + 256e4b0 commit 02bed81

2 files changed

Lines changed: 102 additions & 31 deletions

File tree

articles/azure-functions/scenario-custom-remote-mcp-server.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ In a terminal window, go to the `FunctionsMcpTool` project folder:
128128
cd src/FunctionsMcpTool
129129
```
130130
::: zone-end
131+
::: zone pivot="programming-language-java"
132+
In a terminal window, go to the `FunctionsMcpTool` project folder:
133+
134+
```console
135+
cd samples/FunctionsMcpTool
136+
```
137+
::: zone-end
131138
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
132139

133140
[!INCLUDE [run-locally](../../includes/functions-mcp-run-locally.md)]
@@ -180,11 +187,11 @@ The function code for the MCP server tools is defined in the `src` folder. The `
180187
You can view the complete project template in the [Azure Functions .NET MCP Server](https://github.com/Azure-Samples/remote-mcp-functions-dotnet) GitHub repository.
181188
::: zone-end
182189
::: zone pivot="programming-language-java"
183-
The function code for the MCP server tools is defined in the `src/main/java/com/function/` folder. The `@McpToolTrigger` annotation exposes the functions as MCP Server tools:
190+
The function code for the MCP server tools is defined in the `samples/FunctionsMcpTool/src/main/java/com/function/` folder. The `@McpToolTrigger` annotation exposes the functions as MCP Server tools:
184191
185-
<!- :::code language="java" source="~/functions-scenarios-custom-mcp-java/src/main/java/com/function/HelloWorld.java" range="35-51" ::: >
192+
:::code language="java" source="~/functions-scenarios-custom-mcp-java/samples/FunctionsMcpTool/src/main/java/com/function/HelloWorld.java" range="26-40" :::
186193
187-
<!- :::code language="java" source="~/functions-scenarios-custom-mcp-java/src/main/java/com/function/Snippets.java" range="80-118" ::: >
194+
:::code language="java" source="~/functions-scenarios-custom-mcp-java/samples/FunctionsMcpTool/src/main/java/com/function/Snippets.java" range="50-83" :::
188195
189196
You can view the complete project template in the [Azure Functions Java MCP Server](https://github.com/Azure-Samples/remote-mcp-functions-java) GitHub repository.
190197
::: zone-end

articles/azure-functions/scenario-mcp-apps.md

Lines changed: 92 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ After running the project locally and verifying your code by using GitHub Copilo
2121

2222
Because the new app runs on the Flex Consumption plan, which follows a _pay-for-what-you-use_ billing model, completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
2323

24-
::: zone pivot="programming-language-javascript,programming-language-java"
24+
::: zone pivot="programming-language-javascript"
2525
> [!IMPORTANT]
26-
> While [creating MCP Apps](./functions-bindings-mcp.md) is supported for Java and JavaScript, this quickstart currently only has examples for C#, Python, and TypeScript. To complete this quickstart, select one of these supported languages at the top of the article.
26+
> While [creating MCP Apps](./functions-bindings-mcp.md) is supported for JavaScript, this quickstart currently only has examples for C#, Java, Python, and TypeScript. To complete this quickstart, select one of these supported languages at the top of the article.
2727
::: zone-end
2828

2929
[!INCLUDE [functions-mcp-extension-powershell-note](../../includes/functions-mcp-extension-powershell-note.md)]
@@ -34,12 +34,18 @@ This article supports version 4 of the Node.js programming model for Azure Funct
3434
::: zone pivot="programming-language-python"
3535
This article supports version 2 of the Python programming model for Azure Functions.
3636
::: zone-end
37-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript"
37+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
3838
## Prerequisites
3939
::: zone-end
4040
::: zone pivot="programming-language-csharp"
4141
+ [.NET 10 SDK](https://dotnet.microsoft.com/download)
4242
::: zone-end
43+
::: zone pivot="programming-language-java"
44+
+ [Java 17 Developer Kit](/azure/developer/java/fundamentals/java-support-on-azure)
45+
+ If you use another [supported version of Java](supported-languages.md?pivots=programming-language-java#languages-by-runtime-version), update the project's `pom.xml` file.
46+
+ Set the `JAVA_HOME` environment variable to the install location of the correct version of the Java Development Kit (JDK).
47+
+ [Apache Maven 3.8.x](https://maven.apache.org)
48+
::: zone-end
4349
<!-- replace when supported
4450
::: zone pivot="programming-language-javascript,programming-language-typescript" -->
4551
::: zone pivot="programming-language-typescript"
@@ -57,7 +63,7 @@ This article supports version 2 of the Python programming model for Azure Functi
5763

5864
+ [Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) version 1.23.x or a later version
5965
::: zone-end
60-
::: zone pivot="programming-language-python,programming-language-typescript"
66+
::: zone pivot="programming-language-java,programming-language-python,programming-language-typescript"
6167
+ [Node.js](https://nodejs.org/) (required to build the MCP Apps UI)
6268

6369
+ [Visual Studio Code](https://code.visualstudio.com/) with these extensions:
@@ -66,7 +72,7 @@ This article supports version 2 of the Python programming model for Azure Functi
6672

6773
+ [Azure Developer CLI extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.azure-dev).
6874
::: zone-end
69-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript"
75+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
7076
+ [Azurite storage emulator](../storage/common/storage-install-azurite.md#install-azurite)
7177

7278
+ [Azure CLI](/cli/azure/install-azure-cli). You can also run Azure CLI commands in [Azure Cloud Shell](../cloud-shell/overview.md).
@@ -78,12 +84,6 @@ This article supports version 2 of the Python programming model for Azure Functi
7884
Use the Azure Developer CLI to create an Azure Functions code project from a template.
7985

8086
1. In Visual Studio Code, open a folder or workspace where you want to create your project.
81-
::: zone-end
82-
::: zone pivot="programming-language-python,programming-language-typescript"
83-
1. Press <kbd>F1</kbd> to open the command palette. Search for and run `Azure Developer CLI (azd): init`.
84-
85-
1. When prompted, select **Select a template**.
86-
8787
::: zone-end
8888
::: zone pivot="programming-language-csharp"
8989
2. Run the following command in the Terminal:
@@ -92,7 +92,12 @@ Use the Azure Developer CLI to create an Azure Functions code project from a tem
9292
azd init --template remote-mcp-functions-dotnet -e mcpweather-dotnet
9393
```
9494

95-
This command pulls the project files from the [template repository](https://github.com/Azure-Samples/remote-mcp-functions-dotnet) and initializes the project in the current folder. The -e flag sets a name for the current environment. In `azd`, the environment maintains a unique deployment context for your app, and you can define more than one. It's also used in names of the resources you create in Azure.
95+
This command pulls the project files from the [template repository](https://github.com/Azure-Samples/remote-mcp-functions-dotnet) and initializes the project in the current folder. The -e flag sets a name for the current environment. In `azd`, the environment maintains a unique deployment context for your app, and you can define more than one. It's also used in names of the resources you create in Azure.
96+
::: zone-end
97+
::: zone pivot="programming-language-java,programming-language-python,programming-language-typescript"
98+
2. Press <kbd>F1</kbd> to open the command palette. Search for and run `Azure Developer CLI (azd): init`.
99+
100+
3. When prompted, select **Select a template**.
96101
::: zone-end
97102
::: zone pivot="programming-language-typescript"
98103
4. Search for and select **Remote MCP Functions with TypeScript**.
@@ -108,7 +113,14 @@ Use the Azure Developer CLI to create an Azure Functions code project from a tem
108113

109114
The command pulls the project files from the [template repository](https://github.com/Azure-Samples/remote-mcp-functions-python) and initializes the project in the current folder. In `azd`, the environment maintains a unique deployment context for your app, and you can define more than one. It's also used in the names of the resources you create in Azure.
110115
::: zone-end
111-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript"
116+
::: zone pivot="programming-language-java"
117+
4. Search for and select **Remote MCP Functions with Java**.
118+
119+
5. When prompted, enter `mcpweather-java` as the environment name.
120+
121+
The command pulls the project files from the [template repository](https://github.com/Azure-Samples/remote-mcp-functions-java) and initializes the project in the current folder. In `azd`, the environment maintains a unique deployment context for your app, and you can define more than one. It's also used in names of the resources you create in Azure.
122+
::: zone-end
123+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
112124
## Start the storage emulator
113125

114126
[!INCLUDE [start-storage-emulator](../../includes/functions-mcp-start-storage-emulator.md)]
@@ -128,6 +140,18 @@ The MCP Apps weather tool includes a frontend application that you must build be
128140
cd ../
129141
```
130142

143+
::: zone-end
144+
::: zone pivot="programming-language-java"
145+
146+
1. In the terminal, go to the UI app folder and build the application:
147+
148+
```console
149+
cd samples/McpWeatherApp/app
150+
npm install
151+
npm run build
152+
cd ..
153+
```
154+
131155
::: zone-end
132156
::: zone pivot="programming-language-python"
133157

@@ -169,13 +193,16 @@ The MCP Apps weather tool includes a frontend application that you must build be
169193
```
170194

171195
::: zone-end
172-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript"
196+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
173197
## Run your MCP server locally
174198
::: zone-end
175199
::: zone pivot="programming-language-csharp"
176200
When prompted, select **src/McpWeatherApp**. You see this prompt because there are two projects in the solution, and the other project isn't used by this article.
177201
::: zone-end
178-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript"
202+
::: zone pivot="programming-language-java"
203+
In a terminal window, make sure you're in the `samples/McpWeatherApp` project folder.
204+
::: zone-end
205+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
179206
[!INCLUDE [run-locally](../../includes/functions-mcp-run-locally.md)]
180207

181208
## Verify by using GitHub Copilot
@@ -204,50 +231,85 @@ You can review the code that defines the MCP Apps tools. An MCP Apps tool requir
204231
+ A **resource** that serves the bundled HTML/JavaScript at the matching `ui://` URI.
205232
::: zone-end
206233
::: zone pivot="programming-language-csharp"
207-
The function code for the MCP Apps weather tool is defined in the `src/McpWeatherApp` folder. The `[McpMetadata]` attribute adds UI metadata to the tool, and the `[McpResourceTrigger]` attribute serves the HTML widget:
234+
The function code for the MCP Apps weather tool is defined in the `src/McpWeatherApp` folder. In this function, the `[McpMetadata]` attribute adds UI metadata to the `GetWeather` tool.
208235

209236
:::code language="csharp" source="~/functions-scenarios-custom-mcp-dotnet/src/McpWeatherApp/WeatherFunction.cs" range="48-76" :::
210237

238+
The `[McpResourceTrigger]` attribute is applied to the `GetWeatherWidget` function, which serves the HTML widget.
239+
211240
:::code language="csharp" source="~/functions-scenarios-custom-mcp-dotnet/src/McpWeatherApp/WeatherFunction.cs" range="34-46" :::
212241

213-
The `ToolMetadata` constant declares a `ui.resourceUri` that tells the MCP host to fetch the interactive UI from `ui://weather/index.html` after the tool runs. The `GetWeatherWidget` function serves the bundled HTML file at that URI using `[McpResourceTrigger]`.
242+
The `ToolMetadata` constant declares a `ui.resourceUri` that tells the MCP host to fetch the interactive UI from `ui://weather/index.html` after the tool runs.
243+
244+
:::code language="csharp" source="~/functions-scenarios-custom-mcp-dotnet/src/McpWeatherApp/WeatherFunction.cs" range="12-18" :::
245+
246+
The `GetWeatherWidget` function serves the bundled HTML file at that URI using `[McpResourceTrigger]`.
214247

215248
You can view the complete project template in the [Azure Functions .NET MCP Server](https://github.com/Azure-Samples/remote-mcp-functions-dotnet) GitHub repository.
216249
::: zone-end
217250
::: zone pivot="programming-language-python"
218-
The function code for the MCP Apps weather tool is defined in the `src/function_app.py` file. The `metadata` parameter on `@app.mcp_tool()` adds UI metadata to the tool:
251+
The function code for the MCP Apps weather tool is defined in the `src/function_app.py` file. In this function, the `metadata` parameter on `@app.mcp_tool()` adds UI metadata to the `get_weather` tool.
219252

220253
:::code language="python" source="~/functions-scenarios-custom-mcp-python/src/function_app.py" range="109-130" :::
221254

222-
The `TOOL_METADATA` constant declares a `ui.resourceUri` that tells the MCP host to fetch the interactive UI from `ui://weather/index.html` after the tool runs. The `@app.mcp_resource_trigger()` method serves the HTML widget. The `get_weather_widget` function serves the bundled HTML file at that URI using `@app.mcp_resource_trigger()`:
255+
The `@app.mcp_resource_trigger()` decorator is applied to the `get_weather_widget` function, which serves the HTML widget.
223256

224257
:::code language="python" source="~/functions-scenarios-custom-mcp-python/src/function_app.py" range="64-105" :::
225258

259+
The `TOOL_METADATA` constant declares a `ui.resourceUri` that tells the MCP host to fetch the interactive UI from `ui://weather/index.html` after the tool runs.
260+
261+
:::code language="python" source="~/functions-scenarios-custom-mcp-python/src/function_app.py" range="20-21" :::
262+
263+
The `get_weather_widget` function serves the bundled HTML file at that URI using `@app.mcp_resource_trigger()`.
264+
226265
You can view the complete project template in the [Azure Functions Python MCP Server](https://github.com/Azure-Samples/remote-mcp-functions-python) GitHub repository.
227266
::: zone-end
228267
::: zone pivot="programming-language-typescript"
229-
The function code for the MCP Apps weather tool is defined in the `src/functions/weatherMcpApp.ts` file. The `metadata` property on `app.mcpTool()` adds UI metadata to the tool, and `app.mcpResource()` serves the HTML widget:
268+
The function code for the MCP Apps weather tool is defined in the `src/functions/weatherMcpApp.ts` file. In this function, the `metadata` property on `app.mcpTool()` adds UI metadata to the `getWeather` tool when it's registered.
230269

231-
:::code language="typescript" source="~/functions-scenarios-custom-mcp-typescript/src/functions/weatherMcpApp.ts" range="13-17" :::
270+
:::code language="typescript" source="~/functions-scenarios-custom-mcp-typescript/src/functions/weatherMcpApp.ts" range="102-110" :::
271+
272+
The `getWeather` handler fetches weather data for a location and returns it as JSON.
232273

233274
:::code language="typescript" source="~/functions-scenarios-custom-mcp-typescript/src/functions/weatherMcpApp.ts" range="54-87" :::
234275

235-
:::code language="typescript" source="~/functions-scenarios-custom-mcp-typescript/src/functions/weatherMcpApp.ts" range="102-110" :::
276+
The `app.mcpResource()` function registers the `getWeatherWidget` handler, which serves the HTML widget.
277+
278+
:::code language="typescript" source="~/functions-scenarios-custom-mcp-typescript/src/functions/weatherMcpApp.ts" range="89-97" :::
279+
280+
The `getWeatherWidget` handler reads and returns the bundled HTML file.
236281

237282
:::code language="typescript" source="~/functions-scenarios-custom-mcp-typescript/src/functions/weatherMcpApp.ts" range="29-52" :::
238283

239-
:::code language="typescript" source="~/functions-scenarios-custom-mcp-typescript/src/functions/weatherMcpApp.ts" range="89-97" :::
284+
The `TOOL_METADATA` constant declares a `ui.resourceUri` that tells the MCP host to fetch the interactive UI from `ui://weather/index.html` after the tool runs.
240285

241-
The `TOOL_METADATA` constant declares a `ui.resourceUri` that tells the MCP host to fetch the interactive UI from `ui://weather/index.html` after the tool runs. The `getWeatherWidget` handler serves the bundled HTML file at that URI when registered with `app.mcpResource()`.
286+
:::code language="typescript" source="~/functions-scenarios-custom-mcp-typescript/src/functions/weatherMcpApp.ts" range="13-17" :::
242287

243288
You can view the complete project template in the [Azure Functions TypeScript MCP Server](https://github.com/Azure-Samples/remote-mcp-functions-typescript) GitHub repository.
244289
::: zone-end
245-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript"
290+
::: zone pivot="programming-language-java"
291+
The function code for the MCP Apps weather tool is defined in the `samples/McpWeatherApp` folder. In this function, the `@McpMetadata` annotation adds UI metadata to the `GetWeather` tool.
292+
293+
:::code language="java" source="~/functions-scenarios-custom-mcp-java/samples/McpWeatherApp/src/main/java/com/function/weather/WeatherFunction.java" range="98-132" :::
294+
295+
The `@McpResourceTrigger` annotation is applied to the `GetWeatherWidget` function, which serves the HTML widget.
296+
297+
:::code language="java" source="~/functions-scenarios-custom-mcp-java/samples/McpWeatherApp/src/main/java/com/function/weather/WeatherFunction.java" range="53-66" :::
298+
299+
The `TOOL_METADATA` constant declares a `ui.resourceUri` that tells the MCP host to fetch the interactive UI from `ui://weather/index.html` after the tool runs.
300+
301+
:::code language="java" source="~/functions-scenarios-custom-mcp-java/samples/McpWeatherApp/src/main/java/com/function/weather/WeatherFunction.java" range="29-35" :::
302+
303+
The `GetWeatherWidget` function serves the bundled HTML file at that URI using `@McpResourceTrigger`.
304+
305+
You can view the complete project template in the [Azure Functions Java MCP Server](https://github.com/Azure-Samples/remote-mcp-functions-java) GitHub repository.
306+
::: zone-end
307+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
246308
After verifying the MCP Apps tools locally, you can publish the project to Azure.
247309

248310
## Deploy to Azure
249311
::: zone-end
250-
::: zone pivot="programming-language-python,programming-language-typescript"
312+
::: zone pivot="programming-language-java,programming-language-python,programming-language-typescript"
251313
[!INCLUDE [deploy-azure](../../includes/functions-mcp-deploy-azure.md)]
252314
::: zone-end
253315

@@ -274,15 +336,17 @@ This project is configured to use `azd` to deploy this project to a new function
274336
| _Azure subscription_ | Subscription in which your resources are created. |
275337
| _Azure location_ | Azure region in which to create the resource group that contains the new Azure resources. Only regions that currently support the Flex Consumption plan are shown. |
276338
| _vnetEnabled_ | `False` to skip creating virtual network resources, which simplifies the deployment. |
277-
When prompted, pick your subscription, an Azure region for the resources, and choose `false` to skip creating virtual network resources to simplify the deployment.
339+
340+
When prompted, pick your subscription, an Azure region for the resources, and choose `false` to skip creating virtual network resources to simplify the deployment.
278341

279342
1. Run the `azd deploy` command to deploy the `weather` app to Azure:
280343

281344
```console
282345
azd deploy --service weather
283346
```
284-
::: zone-end
285347

348+
::: zone-end
349+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
286350
## Connect to your remote MCP server
287351

288352
[!INCLUDE [connect-remote](../../includes/functions-mcp-connect-remote.md)]

0 commit comments

Comments
 (0)