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
@@ -22,7 +22,7 @@ For information on setup and configuration details, see the [overview](functions
22
22
> For C#, the Azure Functions MCP extension supports only the [isolated worker model](dotnet-isolated-process-guide.md).
23
23
::: zone-end
24
24
25
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript,programming-language-javascript"
25
+
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript,programming-language-javascript, programming-language-java"
26
26
27
27
This first example shows how to use resource to implement the UI element of MCP Apps.
28
28
::: zone-end
@@ -127,12 +127,6 @@ For the complete code example, see the [Azure Functions MCP Extension repo](http
127
127
128
128
::: zone-end
129
129
130
-
::: zone pivot="programming-language-java"
131
-
132
-
> [!IMPORTANT]
133
-
> The MCP extension in Java supports resource today. Documentation coming soon.
134
-
135
-
::: zone-end
136
130
137
131
::: zone pivot="programming-language-javascript"
138
132
Example code for JavaScript isn't currently available. See the TypeScript example for general guidance.
@@ -286,6 +280,78 @@ For the complete code example, see [function_app.py](https://github.com/Azure-Sa
286
280
287
281
::: zone-end
288
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).
@@ -355,7 +421,52 @@ Define the trigger's binding options in your code. The trigger supports the foll
355
421
356
422
::: zone-end
357
423
358
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript"
424
+
::: zone pivot="programming-language-java"
425
+
426
+
## Attributes
427
+
428
+
Apply the `@McpResourceTrigger` annotation to a function parameter to define an MCP resource trigger.
429
+
430
+
The `@McpResourceTrigger` annotation supports the following properties:
431
+
432
+
| Property | Description |
433
+
|---|---|
434
+
| **`name`** | Required. The binding name for the resource invocation context parameter. |
435
+
| **`uri`** | Required. The URI of the MCP resource (for example, `"file://readme.md"` or `"ui://weather/index.html"`). |
436
+
|**`resourceName`**|Required. The display name of the MCP resource. |
437
+
|**`title`**|Optional. A human-readable title for display purposes. Unlike `resourceName`, which is a programmatic identifier, this is a friendly label forUI presentation. |
438
+
|**`description`**|Optional. A human-readable description of this resource. |
439
+
|**`mimeType`**|Optional. TheMIME type of the resource content (for example, `"text/plain"`, `"text/html"`, `"image/png"`, `"text/html;profile=mcp-app"`).|
440
+
|**`size`**|Optional. The size of the resource in bytes. Defaults to `-1` (not specified).|
441
+
|**`dataType`**|Optional. Defines how the Functions runtime should treat the parameter value. Possible values: `""` (default, deserialize to parameter type), `"string"`, `"binary"`.|
442
+
443
+
## Metadata annotation
444
+
445
+
You can optionally apply `@McpMetadata` on the same parameter as `@McpResourceTrigger` to attach arbitrary JSON metadata to the resource. This metadata is surfaced in the MCP protocol's `_meta` field when clients call `resources/list`.
446
+
447
+
The `@McpMetadata` annotation supports the following properties:
448
+
449
+
| Property | Description |
450
+
|---|---|
451
+
| **`name`** | Required. The binding parameter name. Should match the `name` value of the trigger annotation on the same parameter. |
452
+
| **`json`** | Required. The metadata as a valid JSON string. Can include any arbitrary key-value pairs such as author information, version numbers, UI hints, or tags. |
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
359
470
360
471
See the [Example section](#example) for complete examples.
361
472
@@ -400,7 +511,13 @@ The resource handler function has two parameters:
400
511
401
512
::: zone-end
402
513
403
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-javascript,programming-language-typescript"
514
+
::: zone pivot="programming-language-java"
515
+
516
+
The MCP resource trigger binds the resource invocation context to a function parameter. The trigger can bind to the following types: `String`, or `byte[]` for binary content.
517
+
518
+
::: zone-end
519
+
520
+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-javascript,programming-language-typescript"
404
521
405
522
### Resource URIs
406
523
@@ -428,7 +545,13 @@ Use the `metadata` option to provide extra metadata for resources. This metadata
428
545
429
546
::: zone-end
430
547
431
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-javascript,programming-language-typescript"
548
+
::: zone pivot="programming-language-java"
549
+
550
+
Use the `@McpMetadata` annotation to provide extra metadata for resources. This metadata is a JSON-serialized string included in the `meta` field of each resource when clients call `resources/list`. It can affect how the resource content is displayed or processed.
551
+
552
+
::: zone-end
553
+
554
+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-javascript,programming-language-typescript"
432
555
433
556
### Return types
434
557
@@ -462,7 +585,18 @@ The function should return a `string` containing the resource content (for examp
462
585
463
586
::: zone-end
464
587
465
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-javascript,programming-language-typescript"
588
+
::: zone pivot="programming-language-java"
589
+
590
+
The MCP resource trigger supports the following return types:
591
+
592
+
| Type | Description |
593
+
| --- | --- |
594
+
| `String` | Returned as text content in the MCP `ReadResourceResult`. |
595
+
| `byte[]` | Returned as base64-encoded binary content in the MCP `ReadResourceResult`. Set `dataType = "binary"` on the annotation when returning binary content. |
596
+
597
+
::: zone-end
598
+
599
+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-javascript,programming-language-typescript"
0 commit comments