You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-bindings-mcp-resource-trigger.md
+54-29Lines changed: 54 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -299,8 +299,7 @@ For the complete code example, see [function_app.py](https://github.com/Azure-Sa
299
299
::: zone-end
300
300
301
301
::: zone pivot="programming-language-java"
302
-
303
-
The following example shows a Java function that serves an HTML weather widget as an MCP resource:
302
+
The following code creates an endpoint to expose a resource named `Weather Widget` that serves an interactive weather display as bundled HTML content. The resource uses the `ui://` scheme to indicate it's an MCP App UI resource.
304
303
305
304
```java
306
305
@FunctionName("GetWeatherWidget")
@@ -321,28 +320,67 @@ public String getWeatherWidget(
The `RESOURCE_METADATA` constant is defined as a JSON string that provides additional MCP metadata surfaced via the protocol's `_meta` field:
337
328
338
329
```java
339
330
privatestaticfinalStringRESOURCE_METADATA="""
340
-
{
341
-
"ui": {
342
-
"prefersBorder": true
343
-
}
331
+
{
332
+
"ui": {
333
+
"prefersBorder": true
334
+
}
335
+
}
336
+
""";
337
+
```
338
+
339
+
A tool can reference this resource by declaring a `resourceUri` in its metadata, pointing to `ui://weather/index.html`. When the tool is invoked, the MCP host fetches the resource and renders it:
340
+
341
+
```java
342
+
343
+
privatestaticfinalStringTOOL_METADATA="""
344
+
{
345
+
"ui": {
346
+
"resourceUri": "ui://weather/index.html"
347
+
}
348
+
}
349
+
""";
350
+
351
+
@FunctionName("GetWeather")
352
+
public String getWeather(
353
+
@McpToolTrigger(
354
+
name = "GetWeather",
355
+
description = "Returns current weather for a location via Open-Meteo.")
356
+
@McpMetadata(
357
+
name = "GetWeather",
358
+
json = TOOL_METADATA)
359
+
String context,
360
+
@McpToolProperty(
361
+
name = "location",
362
+
propertyType = "string",
363
+
description = "City name to check weather for (e.g., Seattle, NewYork, Miami)")
364
+
String location,
365
+
final ExecutionContext executionContext) {
366
+
Object result = weatherService.getCurrentWeather(location);
367
+
return MAPPER.writeValueAsString(result);
344
368
}
345
-
""";
369
+
```
370
+
371
+
372
+
For the complete code example, see [McpWeatherApp](https://github.com/Azure-Samples/remote-mcp-functions-java/tree/main/samples/McpWeatherApp/src/main/java/com/function/weather).
373
+
374
+
### Dependency
375
+
376
+
Add the following dependency to your project's `pom.xml` file. The MCP annotations are included in the Azure Functions Java library starting from version **3.2.4**:
Add the following dependency to your project's `pom.xml` file. The MCP annotations are included in the Azure Functions Java library starting from version **3.2.4**:
0 commit comments