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
+72Lines changed: 72 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -280,6 +280,78 @@ For the complete code example, see [function_app.py](https://github.com/Azure-Sa
280
280
281
281
::: zone-end
282
282
283
+
::: zone pivot="programming-language-java"
284
+
The following code registers 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.
285
+
286
+
```java
287
+
privatestaticfinalStringRESOURCE_METADATA="""
288
+
{
289
+
"ui": {
290
+
"prefersBorder": true
291
+
}
292
+
}
293
+
""";
294
+
295
+
@FunctionName("GetWeatherWidget")
296
+
publicString getWeatherWidget(
297
+
@McpResourceTrigger(
298
+
name="context",
299
+
uri="ui://weather/index.html",
300
+
resourceName="Weather Widget",
301
+
title="Weather Widget",
302
+
description="Interactive weather display for MCP Apps",
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:
317
+
318
+
```java
319
+
privatestaticfinalStringTOOL_METADATA="""
320
+
{
321
+
"ui": {
322
+
"resourceUri": "ui://weather/index.html"
323
+
}
324
+
}
325
+
""";
326
+
327
+
@FunctionName("GetWeather")
328
+
public String getWeather(
329
+
@McpToolTrigger(
330
+
name = "GetWeather",
331
+
description = "Returns current weather for a location via Open-Meteo.")
332
+
@McpMetadata(
333
+
name = "GetWeather",
334
+
json = TOOL_METADATA)
335
+
String context,
336
+
@McpToolProperty(
337
+
name = "location",
338
+
propertyType = "string",
339
+
description = "City name to check weather for (e.g., Seattle, NewYork, Miami)")
340
+
String location,
341
+
final ExecutionContext executionContext) {
342
+
343
+
executionContext.getLogger().info("GetWeather: looking up weather for'" + location + "'");
344
+
345
+
Object result = weatherService.getCurrentWeather(location);
346
+
347
+
return MAPPER.writeValueAsString(result);
348
+
}
349
+
```
350
+
351
+
For the complete code example, see [WeatherFunction.java](https://github.com/Azure-Samples/remote-mcp-functions-java/blob/main/samples/McpWeatherApp/src/main/java/com/function/weather/WeatherFunction.java).
0 commit comments