@@ -267,7 +267,7 @@ def _convert_tools_for_claude(self) -> None:
267267 if selected_computer_tool :
268268 break
269269
270- def to_api_tool (tool : types .Tool ) -> BetaToolUnionParam :
270+ def to_api_tool (tool : types .Tool ) -> BetaToolUnionParam | None :
271271 if tool .name == "str_replace_based_edit_tool" :
272272 return BetaToolTextEditor20250728Param (
273273 type = "text_editor_20250728" ,
@@ -278,14 +278,21 @@ def to_api_tool(tool: types.Tool) -> BetaToolUnionParam:
278278 type = "bash_20250124" ,
279279 name = "bash" ,
280280 )
281- if selected_computer_tool and tool .name == selected_computer_tool .name :
282- return BetaToolComputerUse20250124Param (
283- type = "computer_20250124" ,
284- name = "computer" ,
285- display_number = 1 ,
286- display_width_px = computer_settings .ANTHROPIC_COMPUTER_WIDTH ,
287- display_height_px = computer_settings .ANTHROPIC_COMPUTER_HEIGHT ,
288- )
281+ if selected_computer_tool is not None :
282+ if tool .name == selected_computer_tool .name :
283+ return BetaToolComputerUse20250124Param (
284+ type = "computer_20250124" ,
285+ name = "computer" ,
286+ display_number = 1 ,
287+ display_width_px = computer_settings .ANTHROPIC_COMPUTER_WIDTH ,
288+ display_height_px = computer_settings .ANTHROPIC_COMPUTER_HEIGHT ,
289+ )
290+ elif tool .name == "computer" :
291+ logger .warning (
292+ "Renamed tool %s to 'computer', dropping original 'computer' tool" ,
293+ selected_computer_tool .name ,
294+ )
295+ return None
289296
290297 if tool .description is None or tool .inputSchema is None :
291298 raise ValueError (
@@ -295,7 +302,7 @@ def to_api_tool(tool: types.Tool) -> BetaToolUnionParam:
295302 2. Using pydantic Field() annotations on function parameters for the schema
296303 """ )
297304 )
298- """Convert a tool to the API format"""
305+
299306 return BetaToolParam (
300307 name = tool .name ,
301308 description = tool .description ,
@@ -307,6 +314,8 @@ def to_api_tool(tool: types.Tool) -> BetaToolUnionParam:
307314 self .claude_tools = []
308315 for tool in available_tools :
309316 claude_tool = to_api_tool (tool )
317+ if claude_tool is None :
318+ continue
310319 if claude_tool ["name" ] == "computer" :
311320 self .has_computer_tool = True
312321 self .tool_mapping [claude_tool ["name" ]] = tool .name
0 commit comments