MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / copy

Method copy

src/tool/context.py:659–773  ·  view source on GitHub ↗

Copy an existing tool configuration Args: tool_name: Name of the tool to copy new_name: New name for the copied tool. If None, uses original name. new_version: New version for the copied tool. If None, increments version. new_config: N

(self, 
                  tool_name: str,
                  new_name: Optional[str] = None, 
                  new_version: Optional[str] = None, 
                  new_config: Optional[Dict[str, Any]] = None)

Source from the content-addressed store, hash-verified

657 raise
658
659 async def copy(self,
660 tool_name: str,
661 new_name: Optional[str] = None,
662 new_version: Optional[str] = None,
663 new_config: Optional[Dict[str, Any]] = None) -> ToolConfig:
664 """Copy an existing tool configuration
665
666 Args:
667 tool_name: Name of the tool to copy
668 new_name: New name for the copied tool. If None, uses original name.
669 new_version: New version for the copied tool. If None, increments version.
670 new_config: New configuration dict for the copied tool. If None, uses original config.
671
672 Returns:
673 ToolConfig: New tool configuration
674 """
675 try:
676 original_config = self._tool_configs.get(tool_name)
677 if original_config is None:
678 raise ValueError(f"Tool {tool_name} not found")
679
680 if original_config.cls is None:
681 raise ValueError(f"Cannot copy tool {tool_name}: no class provided")
682
683 # Determine new name
684 if new_name is None:
685 new_name = tool_name
686
687 # Prepare config dict (merge original config with new config)
688 tool_config_dict = original_config.config.copy() if original_config.config else {}
689 if new_config:
690 # Merge new config into original config
691 tool_config_dict.update(new_config)
692
693 # Instantiate tool instance (copy is a runtime operation)
694 try:
695 tool_instance = original_config.cls(**tool_config_dict)
696 except Exception as e:
697 logger.error(f"| ❌ Failed to create tool instance for {original_config.cls.__name__}: {e}")
698 raise ValueError(f"Failed to instantiate tool {original_config.cls.__name__} with provided config: {e}")
699
700 # Apply name override if provided (after instantiation)
701 if new_name != tool_name:
702 tool_instance.name = new_name
703
704 tool_description = tool_instance.description
705 tool_metadata = tool_instance.metadata
706 tool_require_grad = tool_config_dict.get("require_grad", tool_instance.require_grad) if tool_config_dict and "require_grad" in tool_config_dict else tool_instance.require_grad
707
708 # Determine new version from version_manager
709 if new_version is None:
710 if new_name == tool_name:
711 # If copying with same name, get next version from version_manager
712 new_version = await version_manager.generate_next_version("tool", new_name, "patch")
713 else:
714 # If copying with different name, get or generate version for new name
715 new_version = await version_manager.get_version("tool", new_name)
716

Callers

nothing calls this directly

Calls 15

_storeMethod · 0.95
save_to_jsonMethod · 0.95
save_contractMethod · 0.95
ToolConfigClass · 0.90
generate_next_versionMethod · 0.80
get_source_codeMethod · 0.80
warningMethod · 0.80
get_parametersMethod · 0.80
build_args_schemaMethod · 0.80
register_versionMethod · 0.80

Tested by

no test coverage detected