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 doesn't_ support resource today.
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.
@@ -304,6 +298,54 @@ For the complete code example, see [function_app.py](https://github.com/Azure-Sa
304
298
305
299
::: zone-end
306
300
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:
304
+
305
+
```java
306
+
@FunctionName("GetWeatherWidget")
307
+
public String getWeatherWidget(
308
+
@McpResourceTrigger(
309
+
name = "context",
310
+
uri = "ui://weather/index.html",
311
+
resourceName = "Weather Widget",
312
+
title = "Weather Widget",
313
+
description = "Interactive weather display for MCP Apps",
@@ -373,7 +415,65 @@ Define the trigger's binding options in your code. The trigger supports the foll
373
415
374
416
::: zone-end
375
417
376
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript"
418
+
::: zone pivot="programming-language-java"
419
+
420
+
## Attributes
421
+
422
+
Apply the `@McpResourceTrigger` annotation to a function parameter to define an MCP resource trigger.
423
+
424
+
The `@McpResourceTrigger` annotation supports the following properties:
425
+
426
+
| Property | Description |
427
+
|---|---|
428
+
|**`name`**| Required. The binding name for the resource invocation context parameter. |
429
+
|**`uri`**| Required. The URI of the MCP resource (for example, `"file://readme.md"` or `"ui://weather/index.html"`). |
430
+
|**`resourceName`**| Required. The display name of the MCP resource. |
431
+
|**`title`**| Optional. A human-readable title for display purposes. Unlike `resourceName`, which is a programmatic identifier, this is a friendly label for UI presentation. |
432
+
|**`description`**| Optional. A human-readable description of this resource. |
433
+
|**`mimeType`**| Optional. The MIME type of the resource content (for example, `"text/plain"`, `"text/html"`, `"image/png"`, `"text/html;profile=mcp-app"`). |
434
+
|**`size`**| Optional. The size of the resource in bytes. Defaults to `-1` (not specified). |
435
+
|**`dataType`**| Optional. Defines how the Functions runtime should treat the parameter value. Possible values: `""` (default, deserialize to parameter type), `"string"`, `"binary"`. |
436
+
437
+
## Metadata annotation
438
+
439
+
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`.
440
+
441
+
The `@McpMetadata` annotation supports the following properties:
442
+
443
+
| Property | Description |
444
+
|---|---|
445
+
|**`name`**| Required. The binding parameter name. Should match the `name` value of the trigger annotation on the same parameter. |
446
+
|**`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. |
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**:
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-typescript"
377
477
378
478
See the [Example section](#example) for complete examples.
379
479
@@ -418,7 +518,13 @@ The resource handler function has two parameters:
418
518
419
519
::: zone-end
420
520
421
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-javascript,programming-language-typescript"
521
+
::: zone pivot="programming-language-java"
522
+
523
+
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.
524
+
525
+
::: zone-end
526
+
527
+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-javascript,programming-language-typescript"
422
528
423
529
### Resource URIs
424
530
@@ -446,7 +552,13 @@ Use the `metadata` option to provide extra metadata for resources. This metadata
446
552
447
553
::: zone-end
448
554
449
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-javascript,programming-language-typescript"
555
+
::: zone pivot="programming-language-java"
556
+
557
+
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.
558
+
559
+
::: zone-end
560
+
561
+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-javascript,programming-language-typescript"
450
562
451
563
### Return types
452
564
@@ -480,7 +592,18 @@ The function should return a `string` containing the resource content (for examp
480
592
481
593
::: zone-end
482
594
483
-
::: zone pivot="programming-language-csharp,programming-language-python,programming-language-javascript,programming-language-typescript"
595
+
::: zone pivot="programming-language-java"
596
+
597
+
The MCP resource trigger supports the following return types:
598
+
599
+
| Type | Description |
600
+
| --- | --- |
601
+
|`String`| Returned as text content in the MCP `ReadResourceResult`. |
602
+
|`byte[]`| Returned as base64-encoded binary content in the MCP `ReadResourceResult`. Set `dataType = "binary"` on the annotation when returning binary content. |
603
+
604
+
::: zone-end
605
+
606
+
::: zone pivot="programming-language-csharp,programming-language-java,programming-language-python,programming-language-javascript,programming-language-typescript"
0 commit comments