Skip to main content
Glama

add_video_animation

Apply animations to video segments in JianYing (CapCut) projects, including intros, outros, and group animations, to enhance visual storytelling.

Instructions

为视频片段添加动画效果

Args: video_segment_id: 视频片段ID,通过add_video_segment获得 animation_type: 动画类型,支持 "IntroType", "OutroType", "GroupAnimationType" animation_name: 动画名称,如 "上下抖动", "向上滑动" 等,可以使用find_effects_by_type工具,资源类型选择IntroType、OutroType、GroupAnimationType,从而获取动画类型有哪些 duration: 动画持续时间,格式如 "1s"(可选)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_segment_idYes
animation_typeYes
animation_nameYes
durationNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
messageYes
successYes

Implementation Reference

  • Main handler for the 'add_video_animation' tool. Decorated with @mcp.tool() for registration. Performs input validation for animation_type, checks if animation exists using JianYingResourceManager, retrieves draft_id and track_name from index_manager, and calls the service layer.
    @mcp.tool()
    def add_video_animation(
            video_segment_id: str,
            animation_type: str,
            animation_name: str,
            duration: Optional[str] = ''
    ) -> ToolResponse:
        """
        为视频片段添加动画效果
    
        Args:
            video_segment_id: 视频片段ID,通过add_video_segment获得
            animation_type: 动画类型,支持 "IntroType", "OutroType", "GroupAnimationType"
            animation_name: 动画名称,如 "上下抖动", "向上滑动" 等,可以使用find_effects_by_type工具,资源类型选择IntroType、OutroType、GroupAnimationType,从而获取动画类型有哪些
            duration: 动画持续时间,格式如 "1s"(可选)
        """
        # 动画类型验证
        valid_animation_types = ["IntroType", "OutroType", "GroupAnimationType"]
        if animation_type not in valid_animation_types:
            return ToolResponse(
                success=False,
                message=f"无效的动画类型 '{animation_type}',支持的类型: {', '.join(valid_animation_types)}"
            )
    
        # 动画存在性验证
        effects = manager.find_by_type(
            effect_type=animation_type,
            keyword=animation_name,
            limit=1
        )
    
        # 检查是否找到完全匹配的动画
        exact_match = False
        if effects:
            for effect in effects:
                if effect.get('title') == animation_name:
                    exact_match = True
                    break
    
        if not effects or not exact_match:
            # 获取建议动画
            animation_suggestions = manager.find_by_type(animation_type, keyword=animation_name)
    
            all_suggestions = []
            for effect in animation_suggestions:
                if effect.get('title'):
                    all_suggestions.append(effect.get('title'))
    
            return ToolResponse(
                success=False,
                message=f"在 {animation_type} 中未找到动画 '{animation_name}'",
                data={
                    "error_type": "animation_not_found",
                    "animation_type": animation_type,
                    "animation_name": animation_name,
                    "suggestions": all_suggestions
                }
            )
    
        # 通过video_segment_id获取相关信息
        draft_id = index_manager.get_draft_id_by_video_segment_id(video_segment_id)
        track_info = index_manager.get_track_info_by_video_segment_id(video_segment_id)
        print(duration, type(duration))
        if not draft_id:
            return ToolResponse(
                success=False,
                message=f"未找到视频片段ID对应的草稿: {video_segment_id}"
            )
    
        if not track_info:
            return ToolResponse(
                success=False,
                message=f"未找到视频片段ID对应的轨道信息: {video_segment_id}"
            )
    
        track_name = track_info.get("track_name")
    
        # 调用服务层处理业务逻辑
        result = add_video_animation_service(
            draft_id=draft_id,
            video_segment_id=video_segment_id,
            animation_type=animation_type,
            animation_name=animation_name,
            duration=duration,
            track_name=track_name
        )
    
        return result
  • Helper service function that creates a VideoSegment instance and calls its add_animation method to apply the animation to the video segment. Handles exceptions and formats the ToolResponse.
    def add_video_animation_service(
        draft_id: str,
        video_segment_id: str,
        animation_type: str,
        animation_name: str,
        duration: Optional[str] = None,
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        视频动画添加服务 - 为视频片段添加动画效果
    
        Args:
            draft_id: 草稿ID
            video_segment_id: 视频片段ID
            animation_type: 动画类型,支持 "IntroType", "OutroType", "GroupAnimationType"
            animation_name: 动画名称,如 "上下抖动", "向上滑动" 等
            duration: 动画持续时间,格式如 "1s"(可选)
            track_name: 轨道名称(可选)
    
        Returns:
            ToolResponse: 包含操作结果的响应对象
        """
        try:
            # 创建VideoSegment实例,传入video_segment_id
            video_segment = VideoSegment(draft_id, video_segment_id=video_segment_id, track_name=track_name)
    
            # 调用视频动画添加方法
            result_data = video_segment.add_animation(
                animation_type=animation_type,
                animation_name=animation_name,
                duration=duration
            )
    
            # 构建返回数据
            response_data = {
                "video_segment_id": video_segment_id,
                "draft_id": draft_id,
                "animation_type": animation_type,
                "animation_name": animation_name,
                "duration": duration,
                "add_animation": result_data
            }
    
            # 如果有轨道名称,添加到返回数据中
            if track_name:
                response_data["track_name"] = track_name
    
            return ToolResponse(
                success=True,
                message=f"视频动画添加成功: {animation_type}.{animation_name}",
                data=response_data
            )
    
        except ValueError as e:
            # 处理参数错误
            return ToolResponse(
                success=False,
                message=f"参数错误: {str(e)}"
            )
    
        except NameError as e:
            # 处理轨道不存在错误
            return ToolResponse(
                success=False,
                message=f"轨道错误: {str(e)}"
            )
    
        except Exception as e:
            # 处理其他未预期的错误
            return ToolResponse(
                success=False,
                message=f"视频动画添加失败: {str(e)}"
            )
  • The @mcp.tool() decorator registers the add_video_animation function as an MCP tool.
    @mcp.tool()
    def add_video_animation(
            video_segment_id: str,
            animation_type: str,
            animation_name: str,
            duration: Optional[str] = ''
    ) -> ToolResponse:
        """
        为视频片段添加动画效果
    
        Args:
            video_segment_id: 视频片段ID,通过add_video_segment获得
            animation_type: 动画类型,支持 "IntroType", "OutroType", "GroupAnimationType"
            animation_name: 动画名称,如 "上下抖动", "向上滑动" 等,可以使用find_effects_by_type工具,资源类型选择IntroType、OutroType、GroupAnimationType,从而获取动画类型有哪些
            duration: 动画持续时间,格式如 "1s"(可选)
        """
        # 动画类型验证
        valid_animation_types = ["IntroType", "OutroType", "GroupAnimationType"]
        if animation_type not in valid_animation_types:
            return ToolResponse(
                success=False,
                message=f"无效的动画类型 '{animation_type}',支持的类型: {', '.join(valid_animation_types)}"
            )
    
        # 动画存在性验证
        effects = manager.find_by_type(
            effect_type=animation_type,
            keyword=animation_name,
            limit=1
        )
    
        # 检查是否找到完全匹配的动画
        exact_match = False
        if effects:
            for effect in effects:
                if effect.get('title') == animation_name:
                    exact_match = True
                    break
    
        if not effects or not exact_match:
            # 获取建议动画
            animation_suggestions = manager.find_by_type(animation_type, keyword=animation_name)
    
            all_suggestions = []
            for effect in animation_suggestions:
                if effect.get('title'):
                    all_suggestions.append(effect.get('title'))
    
            return ToolResponse(
                success=False,
                message=f"在 {animation_type} 中未找到动画 '{animation_name}'",
                data={
                    "error_type": "animation_not_found",
                    "animation_type": animation_type,
                    "animation_name": animation_name,
                    "suggestions": all_suggestions
                }
            )
    
        # 通过video_segment_id获取相关信息
        draft_id = index_manager.get_draft_id_by_video_segment_id(video_segment_id)
        track_info = index_manager.get_track_info_by_video_segment_id(video_segment_id)
        print(duration, type(duration))
        if not draft_id:
            return ToolResponse(
                success=False,
                message=f"未找到视频片段ID对应的草稿: {video_segment_id}"
            )
    
        if not track_info:
            return ToolResponse(
                success=False,
                message=f"未找到视频片段ID对应的轨道信息: {video_segment_id}"
            )
    
        track_name = track_info.get("track_name")
    
        # 调用服务层处理业务逻辑
        result = add_video_animation_service(
            draft_id=draft_id,
            video_segment_id=video_segment_id,
            animation_type=animation_type,
            animation_name=animation_name,
            duration=duration,
            track_name=track_name
        )
    
        return result
  • Function signature and docstring define the input schema and usage for the tool.
    def add_video_animation(
            video_segment_id: str,
            animation_type: str,
            animation_name: str,
            duration: Optional[str] = ''
    ) -> ToolResponse:
        """
        为视频片段添加动画效果
    
        Args:
            video_segment_id: 视频片段ID,通过add_video_segment获得
            animation_type: 动画类型,支持 "IntroType", "OutroType", "GroupAnimationType"
            animation_name: 动画名称,如 "上下抖动", "向上滑动" 等,可以使用find_effects_by_type工具,资源类型选择IntroType、OutroType、GroupAnimationType,从而获取动画类型有哪些
            duration: 动画持续时间,格式如 "1s"(可选)
        """
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions that duration is optional and provides format examples ('1s'), but doesn't describe what happens when the tool executes (e.g., whether it modifies the video segment in place, creates a new version, requires specific permissions, has side effects, or returns specific output). For a mutation tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and structured with a clear purpose statement followed by parameter explanations. Each sentence adds value: the first states the purpose, and the subsequent lines provide necessary parameter context. However, the English translation of the Chinese text is slightly awkward in structure.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there's an output schema (which means return values are documented elsewhere), the description covers the basic purpose and parameters adequately. However, for a mutation tool with no annotations, it should provide more behavioral context about what the tool actually does beyond parameter descriptions. The parameter explanations are good, but the overall context for using this tool is incomplete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description compensates well by explaining all 4 parameters: video_segment_id (obtained from add_video_segment), animation_type (lists supported types), animation_name (gives examples and references find_effects_by_type for discovery), and duration (optional, with format example). This adds significant meaning beyond the bare schema, though it doesn't fully explain constraints or relationships between parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '为视频片段添加动画效果' (add animation effects to video segments). It specifies the verb '添加' (add) and the resource '动画效果' (animation effects) to video segments. However, it doesn't explicitly differentiate from sibling tools like add_video_effect or add_text_animation, which might have overlapping functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides some usage context by mentioning that video_segment_id should be obtained from add_video_segment and that animation_name can be discovered using find_effects_by_type. However, it doesn't explicitly state when to use this tool versus alternatives like add_video_effect or add_text_animation, nor does it provide exclusion criteria or prerequisites beyond parameter sourcing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hey-jian-wei/jianying-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server