66import inspect
77import json
88import logging
9+ import textwrap
10+
911from abc import ABC
1012from datetime import time
1113from typing import Any , Callable , Dict , List , Optional , Union , \
4547 AssistantQueryInput , AssistantPostInput , InputType , EmbeddingsInput , \
4648 semantic_search_system_prompt , \
4749 SemanticSearchInput , EmbeddingsStoreOutput
48- from .mcp import MCPToolTrigger , check_property_type , check_is_array , check_is_required
50+ from .mcp import MCPToolTrigger , build_property_metadata
4951from .retry_policy import RetryPolicy
5052from .function_name import FunctionName
5153from .warmup import WarmUpTrigger
@@ -1595,43 +1597,17 @@ def decorator(fb: FunctionBuilder) -> FunctionBuilder:
15951597
15961598 # Parse tool name and description from function signature
15971599 tool_name = target_func .__name__
1598- description = (target_func .__doc__ or "" ).strip ().split ("\n " )[0 ]
1600+ raw_doc = target_func .__doc__ or ""
1601+ description = textwrap .dedent (raw_doc ).strip ()
15991602
16001603 # Identify arguments that are already bound (bindings)
16011604 bound_param_names = {b .name for b in getattr (fb ._function , "_bindings" , [])}
16021605 skip_param_names = bound_param_names
16031606
16041607 # Build tool properties
1605- tool_properties = []
1606- for param_name , param in sig .parameters .items ():
1607- if param_name in skip_param_names :
1608- continue
1609- param_type_hint = param .annotation if param .annotation != inspect .Parameter .empty else str # noqa
1610-
1611- if param_type_hint is MCPToolContext :
1612- continue
1613-
1614- # Inferred defaults
1615- is_required = check_is_required (param , param_type_hint )
1616- is_array = check_is_array (param_type_hint )
1617- property_type = check_property_type (param_type_hint , is_array )
1618-
1619- property_data = {
1620- "propertyName" : param_name ,
1621- "propertyType" : property_type ,
1622- "description" : "" ,
1623- "isArray" : is_array ,
1624- "isRequired" : is_required
1625- }
1626-
1627- # Merge in any explicit overrides
1628- if param_name in explicit_properties :
1629- overrides = explicit_properties [param_name ]
1630- for key , value in overrides .items ():
1631- if value is not None :
1632- property_data [key ] = value
1633-
1634- tool_properties .append (property_data )
1608+ tool_properties = build_property_metadata (sig = sig ,
1609+ skip_param_names = skip_param_names ,
1610+ explicit_properties = explicit_properties )
16351611
16361612 tool_properties_json = json .dumps (tool_properties )
16371613
@@ -1684,15 +1660,15 @@ def mcp_tool_property(self, arg_name: str,
16841660 description : Optional [str ] = None ,
16851661 property_type : Optional [McpPropertyType ] = None ,
16861662 is_required : Optional [bool ] = True ,
1687- is_array : Optional [bool ] = False ):
1663+ as_array : Optional [bool ] = False ):
16881664 """
16891665 Decorator for defining explicit MCP tool property metadata for a specific argument.
16901666
16911667 :param arg_name: The name of the argument.
16921668 :param description: The description of the argument.
16931669 :param property_type: The type of the argument.
16941670 :param is_required: If the argument is required or not.
1695- :param is_array : If the argument is array or not.
1671+ :param as_array : If the argument should be passed as an array or not.
16961672
16971673 :return: Decorator function.
16981674
@@ -1702,7 +1678,7 @@ def mcp_tool_property(self, arg_name: str,
17021678 description="The name of the snippet.",
17031679 property_type=func.McpPropertyType.STRING,
17041680 is_required=True,
1705- is_array =False
1681+ as_array =False
17061682 )
17071683 """
17081684 def decorator (func ):
@@ -1715,7 +1691,7 @@ def decorator(func):
17151691 "description" : description ,
17161692 "propertyType" : property_type .value if property_type else None , # Get enum value
17171693 "isRequired" : is_required ,
1718- "isArray" : is_array ,
1694+ "isArray" : as_array ,
17191695 }
17201696 setattr (target_func , "__mcp_tool_properties__" , existing )
17211697 return func
0 commit comments