|
42 | 42 | AssistantQueryInput, AssistantPostInput, InputType, EmbeddingsInput, \
|
43 | 43 | semantic_search_system_prompt, \
|
44 | 44 | SemanticSearchInput, EmbeddingsStoreOutput
|
| 45 | +from .mcp import MCPToolTrigger, MCPToolInput, MCPToolOutput |
45 | 46 | from .retry_policy import RetryPolicy
|
46 | 47 | from .function_name import FunctionName
|
47 | 48 | from .warmup import WarmUpTrigger
|
@@ -1511,6 +1512,57 @@ def decorator():
|
1511 | 1512 |
|
1512 | 1513 | return wrap
|
1513 | 1514 |
|
| 1515 | + def mcp_tool_trigger(self, |
| 1516 | + arg_name: str, |
| 1517 | + tool_name: str, |
| 1518 | + description: Optional[str] = None, |
| 1519 | + tool_properties: Optional[str] = None, |
| 1520 | + data_type: Optional[Union[DataType, str]] = None, |
| 1521 | + **kwargs) -> Callable[..., Any]: |
| 1522 | + """ |
| 1523 | + The `mcp_tool_trigger` decorator adds :class:`MCPToolTrigger` to the |
| 1524 | + :class:`FunctionBuilder` object for building a :class:`Function` object |
| 1525 | + used in the worker function indexing model. |
| 1526 | +
|
| 1527 | + This is equivalent to defining `MCPToolTrigger` in the `function.json`, |
| 1528 | + which enables the function to be triggered when MCP tool requests are |
| 1529 | + received by the host. |
| 1530 | +
|
| 1531 | + All optional fields will be given default values by the function host when |
| 1532 | + they are parsed. |
| 1533 | +
|
| 1534 | + Ref: https://aka.ms/azure-function-binding-custom |
| 1535 | +
|
| 1536 | + :param arg_name: The name of the trigger parameter in the function code. |
| 1537 | + :param tool_name: The logical tool name exposed to the host. |
| 1538 | + :param description: Optional human-readable description of the tool. |
| 1539 | + :param tool_properties: JSON-serialized tool properties/parameters list. |
| 1540 | + :param data_type: Defines how the Functions runtime should treat the |
| 1541 | + parameter value. |
| 1542 | + :param kwargs: Keyword arguments for specifying additional binding |
| 1543 | + fields to include in the binding JSON. |
| 1544 | +
|
| 1545 | + :return: Decorator function. |
| 1546 | + """ |
| 1547 | + |
| 1548 | + @self._configure_function_builder |
| 1549 | + def wrap(fb): |
| 1550 | + def decorator(): |
| 1551 | + fb.add_trigger( |
| 1552 | + trigger=MCPToolTrigger( |
| 1553 | + name=arg_name, |
| 1554 | + tool_name=tool_name, |
| 1555 | + description=description, |
| 1556 | + tool_properties=tool_properties, |
| 1557 | + data_type=parse_singular_param_to_enum(data_type, |
| 1558 | + DataType), |
| 1559 | + **kwargs)) |
| 1560 | + return fb |
| 1561 | + |
| 1562 | + return decorator() |
| 1563 | + |
| 1564 | + return wrap |
| 1565 | + |
1514 | 1566 | def dapr_service_invocation_trigger(self,
|
1515 | 1567 | arg_name: str,
|
1516 | 1568 | method_name: str,
|
@@ -3720,6 +3772,57 @@ def decorator():
|
3720 | 3772 |
|
3721 | 3773 | return wrap
|
3722 | 3774 |
|
| 3775 | + def mcp_tool_input(self, |
| 3776 | + arg_name: str, |
| 3777 | + tool_name: str, |
| 3778 | + description: Optional[str] = None, |
| 3779 | + tool_properties: Optional[str] = None, |
| 3780 | + data_type: Optional[Union[DataType, str]] = None, |
| 3781 | + **kwargs) -> Callable[..., Any]: |
| 3782 | + """ |
| 3783 | + The `mcp_tool_input` decorator adds :class:`MCPToolInput` to the |
| 3784 | + :class:`FunctionBuilder` object for building a :class:`Function` object |
| 3785 | + used in the worker function indexing model. |
| 3786 | +
|
| 3787 | + This is equivalent to defining `MCPToolInput` in the `function.json`, |
| 3788 | + which enables the function to read data from MCP tool sources. |
| 3789 | +
|
| 3790 | + All optional fields will be assigned default values by the function host |
| 3791 | + when they are parsed. |
| 3792 | +
|
| 3793 | + Ref: https://aka.ms/azure-function-binding-custom |
| 3794 | +
|
| 3795 | + :param arg_name: The name of the variable that represents the MCP tool input |
| 3796 | + object in the function code. |
| 3797 | + :param tool_name: The logical tool name for the MCP binding. |
| 3798 | + :param description: Optional human-readable description of the tool. |
| 3799 | + :param tool_properties: JSON-serialized tool properties/parameters list. |
| 3800 | + :param data_type: Defines how the Functions runtime should treat the |
| 3801 | + parameter value. |
| 3802 | + :param kwargs: Keyword arguments for specifying additional binding |
| 3803 | + fields to include in the binding JSON. |
| 3804 | +
|
| 3805 | + :return: Decorator function. |
| 3806 | + """ |
| 3807 | + |
| 3808 | + @self._configure_function_builder |
| 3809 | + def wrap(fb): |
| 3810 | + def decorator(): |
| 3811 | + fb.add_binding( |
| 3812 | + binding=MCPToolInput( |
| 3813 | + name=arg_name, |
| 3814 | + tool_name=tool_name, |
| 3815 | + description=description, |
| 3816 | + tool_properties=tool_properties, |
| 3817 | + data_type=parse_singular_param_to_enum(data_type, |
| 3818 | + DataType), |
| 3819 | + **kwargs)) |
| 3820 | + return fb |
| 3821 | + |
| 3822 | + return decorator() |
| 3823 | + |
| 3824 | + return wrap |
| 3825 | + |
3723 | 3826 | def mysql_output(self,
|
3724 | 3827 | arg_name: str,
|
3725 | 3828 | command_text: str,
|
@@ -3771,6 +3874,57 @@ def decorator():
|
3771 | 3874 |
|
3772 | 3875 | return wrap
|
3773 | 3876 |
|
| 3877 | + def mcp_tool_output(self, |
| 3878 | + arg_name: str, |
| 3879 | + tool_name: str, |
| 3880 | + description: Optional[str] = None, |
| 3881 | + tool_properties: Optional[str] = None, |
| 3882 | + data_type: Optional[Union[DataType, str]] = None, |
| 3883 | + **kwargs) -> Callable[..., Any]: |
| 3884 | + """ |
| 3885 | + The `mcp_tool_output` decorator adds :class:`MCPToolOutput` to the |
| 3886 | + :class:`FunctionBuilder` object for building a :class:`Function` object |
| 3887 | + used in the worker function indexing model. |
| 3888 | +
|
| 3889 | + This is equivalent to defining `MCPToolOutput` in the `function.json`, |
| 3890 | + which enables the function to write data to MCP tool destinations. |
| 3891 | +
|
| 3892 | + All optional fields will be assigned default values by the function host |
| 3893 | + when they are parsed. |
| 3894 | +
|
| 3895 | + Ref: https://aka.ms/azure-function-binding-custom |
| 3896 | +
|
| 3897 | + :param arg_name: The name of the variable that represents the MCP tool output |
| 3898 | + object in the function code. |
| 3899 | + :param tool_name: The logical tool name for the MCP binding. |
| 3900 | + :param description: Optional human-readable description of the tool. |
| 3901 | + :param tool_properties: JSON-serialized tool properties/parameters list. |
| 3902 | + :param data_type: Defines how the Functions runtime should treat the |
| 3903 | + parameter value. |
| 3904 | + :param kwargs: Keyword arguments for specifying additional binding |
| 3905 | + fields to include in the binding JSON. |
| 3906 | +
|
| 3907 | + :return: Decorator function. |
| 3908 | + """ |
| 3909 | + |
| 3910 | + @self._configure_function_builder |
| 3911 | + def wrap(fb): |
| 3912 | + def decorator(): |
| 3913 | + fb.add_binding( |
| 3914 | + binding=MCPToolOutput( |
| 3915 | + name=arg_name, |
| 3916 | + tool_name=tool_name, |
| 3917 | + description=description, |
| 3918 | + tool_properties=tool_properties, |
| 3919 | + data_type=parse_singular_param_to_enum(data_type, |
| 3920 | + DataType), |
| 3921 | + **kwargs)) |
| 3922 | + return fb |
| 3923 | + |
| 3924 | + return decorator() |
| 3925 | + |
| 3926 | + return wrap |
| 3927 | + |
3774 | 3928 |
|
3775 | 3929 | class SettingsApi(DecoratorApi, ABC):
|
3776 | 3930 | """Interface to extend for using an existing settings decorator in functions."""
|
|
0 commit comments