|
42 | 42 | AssistantQueryInput, AssistantPostInput, InputType, EmbeddingsInput, \ |
43 | 43 | semantic_search_system_prompt, \ |
44 | 44 | SemanticSearchInput, EmbeddingsStoreOutput |
| 45 | +from .mcp import MCPToolTrigger |
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/remote-mcp-functions-python |
| 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, |
|
0 commit comments