Skip to main content
Glama

add_video_transition

Add transition effects between video segments in JianYing (CapCut) projects. Specify transition type and duration to create professional video edits.

Instructions

为视频片段添加转场效果,注意两视频间添加转场应该在前一个添加转场,即video_segment_id使用前一个视频

Args: video_segment_id: 视频片段ID,通过add_video_segment获得 transition_type: 转场类型名称,可以使用find_effects_by_type工具,资源类型选择TransitionType,从而获取转场类型有哪些 duration: 转场持续时间,格式如 "1s"(可选)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_segment_idYes
transition_typeYes
durationNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
messageYes
successYes

Implementation Reference

  • The MCP tool handler for 'add_video_transition'. Validates the transition_type using JianYingResourceManager, resolves draft_id and track_name using index_manager, and delegates to add_video_transition_service.
    @mcp.tool()
    def add_video_transition(
            video_segment_id: str,
            transition_type: str,
            duration: Optional[str] = None
    ) -> ToolResponse:
        """
        为视频片段添加转场效果,注意两视频间添加转场应该在前一个添加转场,即video_segment_id使用前一个视频
    
        Args:
            video_segment_id: 视频片段ID,通过add_video_segment获得
            transition_type: 转场类型名称,可以使用find_effects_by_type工具,资源类型选择TransitionType,从而获取转场类型有哪些
            duration: 转场持续时间,格式如 "1s"(可选)
        """
        # 转场存在性验证
        effects = manager.find_by_type(
            effect_type="TransitionType",
            keyword=transition_type,
            limit=1
        )
    
        # 检查是否找到完全匹配的转场
        exact_match = False
        if effects:
            for effect in effects:
                if effect.get('name') == transition_type:
                    exact_match = True
                    break
    
        if not effects or not exact_match:
            # 获取建议转场
            transition_suggestions = manager.find_by_type("TransitionType", keyword=transition_type)
    
            all_suggestions = []
            for effect in transition_suggestions:
                if effect.get('name'):
                    all_suggestions.append(effect.get('name'))
    
            return ToolResponse(
                success=False,
                message=f"未找到转场 '{transition_type}',请确认转场名称是否正确,或尝试使用以下建议: {', '.join(all_suggestions)}",
                data={
                    "error_type": "transition_not_found",
                    "transition_name": transition_type,
                    "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)
    
        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_transition_service(
            draft_id=draft_id,
            video_segment_id=video_segment_id,
            transition_type=transition_type,
            duration=duration,
            track_name=track_name
        )
    
        return result
  • The call to video_tools(mcp) in the main server file, which registers the video tools including 'add_video_transition'.
    video_tools(mcp)
  • Helper service function that instantiates VideoSegment and invokes its add_transition method to apply the transition, handling errors and formatting response.
    def add_video_transition_service(
        draft_id: str,
        video_segment_id: str,
        transition_type: str,
        duration: Optional[str] = None,
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        视频转场添加服务 - 为视频片段添加转场效果
    
        Args:
            draft_id: 草稿ID
            video_segment_id: 视频片段ID
            transition_type: 转场类型名称,如 "信号故障", "淡入淡出" 等
            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_transition(
                transition_type=transition_type,
                duration=duration
            )
    
            # 构建返回数据
            response_data = {
                "video_segment_id": video_segment_id,
                "draft_id": draft_id,
                "transition_type": transition_type,
                "duration": duration,
                "add_transition": result_data
            }
    
            # 如果有轨道名称,添加到返回数据中
            if track_name:
                response_data["track_name"] = track_name
    
            return ToolResponse(
                success=True,
                message=f"视频转场添加成功: {transition_type}",
                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)}"
            )
  • Core implementation in VideoSegment class: constructs the JSON operation data for 'add_transition' and appends it to the draft's video.json file.
    def add_transition(self, transition_type: str, duration: Optional[str] = None,
                       video_segment_id: Optional[str] = None) -> bool:
        """
        添加转场特效
    
        Args:
            transition_type: 转场类型名称,如 "信号故障", "淡入淡出" 等
            duration: 转场持续时间,如 "1s"
    
        Returns:
            bool: 添加是否成功
        """
        if self.video_segment_id is None and video_segment_id is None:
            print("错误: video_segment_id不能为空")
            return False
        video_segment_id = video_segment_id or self.video_segment_id
        # 构建add_transition参数(只保存用户传入的参数)
        add_transition_params = {
            "transition_type": transition_type
        }
    
        # 只添加用户明确传入的可选参数
        if duration is not None:
            add_transition_params["duration"] = duration
    
        # 构建完整的转场数据
        transition_data = {
            "video_segment_id": video_segment_id,
            "operation": "add_transition",
            "add_transition": add_transition_params
        }
    
        # 保存参数
        self.add_json_to_file(transition_data)
        return True
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions the action ('添加转场效果' - add transition effects) and provides some implementation guidance, it doesn't disclose critical behavioral traits: whether this is a mutating operation, what permissions are required, whether changes are reversible, error conditions, or what the output contains. For a tool that modifies video content with zero annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is efficiently structured: a clear purpose statement, important usage note, then parameter explanations in a labeled 'Args:' section. Every sentence earns its place by providing essential information without redundancy. The Chinese text is direct and front-loads the core functionality.

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 reduces the need to describe return values) but zero annotation coverage and 0% schema description coverage, the description does reasonably well. It covers the tool's purpose, important usage nuance, and parameter semantics. However, for a video editing tool that likely performs mutations, it should disclose more about behavioral aspects like side effects, error handling, or prerequisites. The presence of an output schema helps, but doesn't fully compensate for the lack of behavioral transparency.

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?

Schema description coverage is 0%, so the description must compensate. It provides meaningful semantic context for all three parameters: 'video_segment_id' is explained as coming from 'add_video_segment' and should reference the previous video segment; 'transition_type' is linked to 'find_effects_by_type' with resource type 'TransitionType'; 'duration' is described as optional with format example '1s'. This adds substantial value beyond the bare schema, though it doesn't cover all possible parameter constraints or validation rules.

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 transition effects to video segments). It specifies the verb ('添加' - add) and resource ('转场效果' - transition effects), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'add_video_effect' or 'add_video_animation' beyond the specific transition focus.

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

Usage Guidelines4/5

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

The description provides important contextual guidance: '注意两视频间添加转场应该在前一个添加转场,即video_segment_id使用前一个视频' (note that when adding transitions between two videos, it should be added to the previous one, i.e., video_segment_id uses the previous video). This clarifies a non-obvious implementation detail. It also references 'find_effects_by_type' as a way to discover available transition types, though it doesn't explicitly state when NOT to use this tool versus alternatives.

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