Skip to main content
Glama

add_text_animation

Apply entrance, exit, or looping animations to text segments in video editing projects. Choose from effects like typewriter, spring, glitch, fade-in, or fade-out to enhance visual storytelling.

Instructions

为文本片段添加动画效果

Args: text_segment_id: 文本片段ID,通过add_text_segment获得 animation_type: 动画类型,支持以下类型: - "TextIntro": 入场动画 - "TextOutro": 出场动画 - "TextLoopAnim": 循环动画 animation_name: 动画名称,如 "复古打字机", "弹簧", "色差故障", "淡入", "淡出" 等,可以使用find_effects_by_type工具,资源类型选择TextIntro、TextOutro、TextLoopAnim,从而获取动画类型有哪些 duration: 动画持续时间(可选),格式如 "1s", "500ms"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
text_segment_idYes
animation_typeYes
animation_nameYes
durationNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
messageYes
successYes

Implementation Reference

  • The primary handler for the 'add_text_animation' MCP tool. It performs input validation (animation type and existence check using JianYingResourceManager), resolves draft/track info via index_manager, and delegates to the service layer for execution.
    @mcp.tool()
    def add_text_animation(
            text_segment_id: str,
            animation_type: str,
            animation_name: str,
            duration: Optional[str] = None
    ) -> ToolResponse:
        """
        为文本片段添加动画效果
    
        Args:
            text_segment_id: 文本片段ID,通过add_text_segment获得
            animation_type: 动画类型,支持以下类型:
                - "TextIntro": 入场动画
                - "TextOutro": 出场动画
                - "TextLoopAnim": 循环动画
            animation_name: 动画名称,如 "复古打字机", "弹簧", "色差故障", "淡入", "淡出" 等,可以使用find_effects_by_type工具,资源类型选择TextIntro、TextOutro、TextLoopAnim,从而获取动画类型有哪些
            duration: 动画持续时间(可选),格式如 "1s", "500ms"
        """
        # 参数验证
        valid_types = ["TextIntro", "TextOutro", "TextLoopAnim"]
        if animation_type not in valid_types:
            return ToolResponse(
                success=False,
                message=f"无效的动画类型 '{animation_type}',支持的类型: {', '.join(valid_types)}"
            )
    
        # 动画存在性验证(文本动画使用 title 字段)
        from jianyingdraft.utils.effect_manager import JianYingResourceManager
        manager = JianYingResourceManager()
    
        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
                }
            )
    
        # 通过text_segment_id获取相关信息
        draft_id = index_manager.get_draft_id_by_text_segment_id(text_segment_id)
        track_info = index_manager.get_track_info_by_text_segment_id(text_segment_id)
    
        if not draft_id:
            return ToolResponse(
                success=False,
                message=f"未找到文本片段ID对应的草稿: {text_segment_id}"
            )
    
        if not track_info:
            return ToolResponse(
                success=False,
                message=f"未找到文本片段ID对应的轨道信息: {text_segment_id}"
            )
    
        track_name = track_info.get("track_name")
    
        # 调用服务层处理业务逻辑
        result = add_text_animation_service(
            draft_id=draft_id,
            text_segment_id=text_segment_id,
            animation_type=animation_type,
            animation_name=animation_name,
            duration=duration,
            track_name=track_name
        )
    
        return result
  • Registration of the text tools module, including 'add_text_animation', by calling text_tools(mcp) on the FastMCP server instance.
    from jianyingdraft.tool.text_tool import text_tools
    from jianyingdraft.tool.audio_tool import audio_tools
    from jianyingdraft.tool.utility_tool import utility_tools
    
    
    def main():
        # 注册所有工具
        draft_tools(mcp)
        track_tools(mcp)
        video_tools(mcp)
        text_tools(mcp)
  • Helper service function called by the handler. Instantiates TextSegment and invokes add_animation method to apply the text animation effect, handling errors and formatting responses.
    def add_text_animation_service(
        draft_id: str,
        text_segment_id: str,
        animation_type: str,
        animation_name: str,
        duration: Optional[str] = None,
        track_name: Optional[str] = None
    ) -> ToolResponse:
        """
        文本动画添加服务 - 为文本片段添加动画效果
    
        Args:
            draft_id: 草稿ID
            text_segment_id: 文本片段ID
            animation_type: 动画类型,"TextIntro"、"TextOutro"、"TextLoopAnim"
            animation_name: 动画名称,如 "复古打字机"、"弹簧"、"色差故障" 等
            duration: 动画持续时间(可选),格式如 "1s"、"500ms"
            track_name: 轨道名称(可选)
    
        Returns:
            ToolResponse: 包含操作结果的响应对象
        """
        try:
            # 创建TextSegment实例,传入text_segment_id
            text_segment = TextSegment(draft_id, text_segment_id=text_segment_id, track_name=track_name)
    
            # 调用文本动画添加方法
            result_data = text_segment.add_animation(
                animation_type=animation_type,
                animation_name=animation_name,
                duration=duration
            )
    
            # 构建返回数据
            response_data = {
                "text_segment_id": text_segment_id,
                "draft_id": draft_id,
                "animation_type": animation_type,
                "animation_name": animation_name,
                "add_animation": result_data
            }
    
            # 添加可选参数到返回数据
            if duration:
                response_data["duration"] = duration
            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)}"
            )
  • Input schema defined by function parameters and comprehensive docstring describing args, types, and examples.
    def add_text_animation(
            text_segment_id: str,
            animation_type: str,
            animation_name: str,
            duration: Optional[str] = None
    ) -> ToolResponse:
        """
        为文本片段添加动画效果
    
        Args:
            text_segment_id: 文本片段ID,通过add_text_segment获得
            animation_type: 动画类型,支持以下类型:
                - "TextIntro": 入场动画
                - "TextOutro": 出场动画
                - "TextLoopAnim": 循环动画
            animation_name: 动画名称,如 "复古打字机", "弹簧", "色差故障", "淡入", "淡出" 等,可以使用find_effects_by_type工具,资源类型选择TextIntro、TextOutro、TextLoopAnim,从而获取动画类型有哪些
            duration: 动画持续时间(可选),格式如 "1s", "500ms"
        """
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While it mentions the tool's purpose and parameters, it doesn't describe important behavioral aspects: whether this is a read-only or mutation operation, what permissions are required, whether animations can be removed or modified, what happens if invalid parameters are provided, or what the output contains. For a tool that presumably modifies content, this is insufficient behavioral context.

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 well-structured with a clear purpose statement followed by organized parameter explanations. Each parameter gets its own line with helpful details. While slightly verbose in the animation_name explanation, every sentence adds value. The structure makes it easy to scan and understand.

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 (though not shown), the description doesn't need to explain return values. However, for a tool with 4 parameters, 0% schema coverage, and no annotations, the description does a good job explaining parameters but lacks behavioral context about what the tool actually does beyond adding effects. It doesn't explain the mutation nature, error conditions, or integration with the broader workflow involving create_draft, create_track, and export_draft siblings.

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 provides substantial value by explaining all parameters. It clarifies that text_segment_id comes from add_text_segment, lists the three animation_type options with Chinese translations, provides examples of animation_name values, explains how to discover more names using find_effects_by_type, and specifies the duration format. The only gap is not explaining what happens when duration is omitted (though it's marked optional).

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

Purpose5/5

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

The description clearly states the specific action ('为文本片段添加动画效果' - add animation effects to text segments) and identifies the resource (text segments). It distinguishes itself from sibling tools like add_video_animation, add_audio_effect, and add_text_segment by focusing specifically on text animation rather than video/audio effects or text segment creation.

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 clear context about when to use this tool: after obtaining a text segment ID from add_text_segment. It also references find_effects_by_type as an alternative for discovering available animation names. However, it doesn't explicitly state when NOT to use this tool or compare it directly to similar sibling tools like add_video_animation.

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