3737
3838class MCPToolKwargs (TypedDict , total = False ):
3939 smart_parsing : bool
40+ exclude_none : bool
4041
4142
4243class MCPTool (Tool [BaseModel , ToolRunOptions , JSONToolOutput ]):
@@ -45,11 +46,13 @@ class MCPTool(Tool[BaseModel, ToolRunOptions, JSONToolOutput]):
4546 def __init__ (self , session : ClientSession , tool : MCPToolInfo , ** options : Unpack [MCPToolKwargs ]) -> None :
4647 """Initialize MCPTool with client and tool configuration."""
4748 smart_parsing = options .pop ("smart_parsing" , True )
49+ exclude_none = options .pop ("exclude_none" , False )
4850
4951 super ().__init__ (dict (options ))
5052 self ._session = session
5153 self ._tool = tool
5254 self ._smart_parsing = smart_parsing
55+ self ._exclude_none = exclude_none
5356
5457 @property
5558 def name (self ) -> str :
@@ -74,7 +77,7 @@ async def _run(self, input_data: Any, options: ToolRunOptions | None, context: R
7477 """Execute the tool with given input."""
7578 logger .debug (f"Executing tool { self ._tool .name } with input: { input_data } " )
7679 result : CallToolResult = await self ._session .call_tool (
77- name = self ._tool .name , arguments = input_data .model_dump (exclude_none = True , exclude_unset = True )
80+ name = self ._tool .name , arguments = input_data .model_dump (exclude_none = self . _exclude_none , exclude_unset = True )
7881 )
7982 logger .debug (f"Tool result: { result } " )
8083
@@ -119,7 +122,7 @@ async def from_session(cls, session: ClientSession, **options: Unpack[MCPToolKwa
119122 return [MCPTool (session , tool , ** options ) for tool in tools_result .tools ]
120123
121124 async def clone (self ) -> Self :
122- options = MCPToolKwargs (smart_parsing = self ._smart_parsing )
125+ options = MCPToolKwargs (smart_parsing = self ._smart_parsing , exclude_none = self . _exclude_none )
123126 options .update (self ._options or {}) # type: ignore
124127
125128 tool = self .__class__ (
0 commit comments