Skip to content

Commit 98f3d8a

Browse files
authored
Improve MCP Extension Support (#224)
* add mcptooltrigger annotation * build * update with java docs * update version name to 3.1.1-alpha * register McpToolTrigger in build tool so custom binding is not needed * Add McpToolProperty annotation * update mcp annotations * update docs * update library version * revert mvnBuild.bat changes * remove propertyName attribute since it will be filled by build tool * add missing dataType method for McpToolTrigger * fix some styling bugs
1 parent 8c6648e commit 98f3d8a

File tree

3 files changed

+157
-1
lines changed

3 files changed

+157
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.microsoft.azure.functions</groupId>
66
<artifactId>azure-functions-java-library</artifactId>
7-
<version>3.1.0</version>
7+
<version>3.2.0</version>
88
<packaging>jar</packaging>
99
<parent>
1010
<groupId>com.microsoft.maven</groupId>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
7+
package com.microsoft.azure.functions.annotation;
8+
9+
import java.lang.annotation.ElementType;
10+
import java.lang.annotation.Retention;
11+
import java.lang.annotation.RetentionPolicy;
12+
import java.lang.annotation.Target;
13+
14+
/**
15+
* Defines a strongly-typed input property for an MCP tool function parameter.
16+
* <p>
17+
* Alternative to using JSON format in {@link McpToolTrigger#toolProperties()}.
18+
* Each annotated parameter receives a specific value from the tool invocation arguments.
19+
* </p>
20+
*
21+
* <p>Example:</p>
22+
* <pre>
23+
* {@literal @}FunctionName("searchFiles")
24+
* public HttpResponseMessage search(
25+
* {@literal @}McpToolTrigger(name = "context", description = "Search files") String context,
26+
* {@literal @}McpToolProperty(
27+
* name = "query",
28+
* propertyName = "searchTerm",
29+
* propertyType = "string",
30+
* description = "Search term",
31+
* required = true
32+
* ) String searchTerm
33+
* ) {
34+
* // Use searchTerm directly
35+
* }
36+
* </pre>
37+
*
38+
* @see McpToolTrigger
39+
* @since 3.2.0
40+
*/
41+
@Target({ElementType.PARAMETER})
42+
@Retention(RetentionPolicy.RUNTIME)
43+
public @interface McpToolProperty {
44+
45+
/**
46+
* The parameter binding name for the Azure Functions runtime.
47+
*
48+
* @return The parameter binding name
49+
*/
50+
String name();
51+
52+
/**
53+
* The expected data type (e.g., "string", "number", "boolean", "array", "object").
54+
*
55+
* @return The property type identifier
56+
*/
57+
String propertyType();
58+
59+
/**
60+
* Description of the property's purpose and usage.
61+
*
62+
* @return Description of the property
63+
*/
64+
String description();
65+
66+
/**
67+
* Whether this property is required for tool execution.
68+
*
69+
* @return true if required, false if optional
70+
*/
71+
boolean required() default false;
72+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
7+
package com.microsoft.azure.functions.annotation;
8+
9+
import java.lang.annotation.ElementType;
10+
import java.lang.annotation.Retention;
11+
import java.lang.annotation.RetentionPolicy;
12+
import java.lang.annotation.Target;
13+
14+
/**
15+
* Triggers an Azure Function when invoked by the Model Context Protocol (MCP) tool system.
16+
* <p>
17+
* This annotation enables Azure Functions to be called as tools from MCP-compatible clients
18+
* like AI assistants. The annotated parameter receives tool invocation arguments and context.
19+
* </p>
20+
*
21+
* <p>Example:</p>
22+
* <pre>
23+
* {@literal @}FunctionName("getFileContent")
24+
* public HttpResponseMessage getFile(
25+
* {@literal @}McpToolTrigger(
26+
* name = "request",
27+
* description = "Reads file content",
28+
* toolProperties = "[{\"propertyName\":\"filePath\",\"propertyType\":\"string\"," +
29+
* "\"description\":\"File path to read\"}]"
30+
* ) String toolRequest
31+
* ) {
32+
* // Parse and handle tool request
33+
* }
34+
* </pre>
35+
*
36+
* @see McpToolProperty
37+
* @since 3.2.0
38+
*/
39+
@Target({ElementType.PARAMETER})
40+
@Retention(RetentionPolicy.RUNTIME)
41+
public @interface McpToolTrigger {
42+
43+
/**
44+
* The binding name for the tool invocation context parameter.
45+
*
46+
* @return The parameter binding name
47+
*/
48+
String name();
49+
50+
/**
51+
* Defines how Functions runtime should treat the parameter value. Possible values are:
52+
* <ul>
53+
* <li>"": get the value as a string, and try to deserialize to actual parameter type like POJO</li>
54+
* <li>string: always get the value as a string</li>
55+
* <li>binary: get the value as a binary data, and try to deserialize to actual parameter type byte[]</li>
56+
* </ul>
57+
*
58+
* @return The dataType which will be used by the Functions runtime.
59+
*/
60+
String dataType() default "";
61+
62+
/**
63+
* Human-readable description of what this tool does.
64+
*
65+
* @return Description of the tool's functionality
66+
*/
67+
String description();
68+
69+
/**
70+
* JSON array defining expected tool properties.
71+
* <p>
72+
* Each property should be a JSON object with: propertyName, propertyType, description.
73+
* Alternative: use {@link McpToolProperty} annotations on parameters.
74+
* </p>
75+
*
76+
* <p>Example:</p>
77+
* <pre>
78+
* [{"propertyName":"fileName","propertyType":"string","description":"File to read"}]
79+
* </pre>
80+
*
81+
* @return JSON array of property definitions, or empty string
82+
*/
83+
String toolProperties() default "";
84+
}

0 commit comments

Comments
 (0)