Skip to main content
Glama
allvoicelab

All Voice Lab MCP Server

Official
by allvoicelab

text_translation

Translate text files between languages. Supports TXT and SRT formats up to 10MB. Specify target language and optional source language for accurate translation results.

Instructions

[AllVoiceLab Tool] Translate text from a file to another language.

This tool translates text content from a file to a specified target language. The process runs asynchronously
with status polling and returns the translated text when complete.

Args:
    file_path: Path to the text file to translate. Only TXT and SRT formats are supported. Maximum file size: 10MB.
    target_lang: Target language code for translation (e.g., 'zh', 'en', 'ja', 'fr', 'de', 'ko'). Required.
    source_lang: Source language code of the original content. Set to 'auto' for automatic language detection. Default is 'auto'.
    output_dir: Output directory for the downloaded result file. Default is user's desktop.

Returns:
    TextContent containing the file path to the translated file or error message.
    If the process takes longer than expected, returns the project ID for later status checking. 

Limitations:
    - Only TXT and SRT formats are supported
    - Maximum file size: 10MB
    - File must exist and be accessible
    - Currently supports a limited set of languages for translation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
target_langYes
source_langNoauto
output_dirNo

Implementation Reference

  • The main handler function for the 'text_translation' tool. Validates input file (TXT/SRT, <=10MB), submits translation task to AllVoiceLab API, polls status up to 10 minutes, downloads result if successful, saves to output_dir, and returns formatted TextContent with translation details and file path.
    def text_translation_tool(
        file_path: str,
        target_lang: str,
        source_lang: str = "auto",
        output_dir: str = None
    ) -> TextContent:
        all_voice_lab = get_client()
        output_dir = all_voice_lab.get_output_path(output_dir)
        max_polling_time = 600
        polling_interval = 10
        logging.info(
            f"Tool called: text_translation, file_path: {file_path}, target_lang: {target_lang}, source_lang: {source_lang}")
        logging.info(f"Max polling time: {max_polling_time}s, Polling interval: {polling_interval}s")
    
        
        if not file_path:
            logging.warning("File path parameter is empty")
            return TextContent(
                type="text",
                text="file_path parameter cannot be empty"
            )
    
        
        if not os.path.exists(file_path):
            logging.warning(f"File does not exist: {file_path}")
            return TextContent(
                type="text",
                text=f"File does not exist: {file_path}"
            )
    
        
        _, file_extension = os.path.splitext(file_path)
        file_extension = file_extension.lower()
        if file_extension not in [".txt", ".srt"]:
            logging.warning(f"Unsupported file format: {file_extension}")
            return TextContent(
                type="text",
                text=f"Unsupported file format. Only TXT and SRT formats are supported."
            )
    
        
        max_size_bytes = 10 * 1024 * 1024  # 10MB in bytes
        file_size = os.path.getsize(file_path)
        if file_size > max_size_bytes:
            logging.warning(f"File size exceeds limit: {file_size} bytes, max allowed: {max_size_bytes} bytes")
            return TextContent(
                type="text",
                text=f"File size exceeds the maximum limit of 10MB. Please use a smaller file."
            )
    
        try:
            if all_voice_lab is None:
                logging.error("all_voice_lab client is not initialized.")
                return TextContent(type="text",
                                   text="Error: AllVoiceLab client not initialized. Please check server setup.")
    
            
            logging.info("Starting text translation process")
            project_id = all_voice_lab.text_translation(
                file_path=file_path,
                target_lang=target_lang,
                source_lang=source_lang
            )
            logging.info(f"Text translation task submitted. Project ID: {project_id}")
    
            
            logging.info(f"Starting to poll translation status for Project ID: {project_id}")
            start_time = time.time()
            completed = False
    
            
            while time.time() - start_time < max_polling_time:
                try:
                    
                    translation_result = all_voice_lab.get_text_translation_result(project_id)
                    if translation_result is None:
                        logging.warning(f"Failed to get translation result for Project ID: {project_id}")
                        time.sleep(polling_interval)
                        continue
    
                    logging.info(f"Translation status: {translation_result.status} for Project ID: {project_id}")
    
                    
                    if translation_result.status.lower() == "success":
                        logging.info(f"Text translation completed for Project ID: {project_id}")
                        completed = True
    
                        
                        if translation_result.result and translation_result.result.startswith("http"):
                            try:
                                
                                os.makedirs(output_dir, exist_ok=True)
    
                                
                                # Get original filename without extension
                                original_filename = os.path.splitext(os.path.basename(file_path))[0]
                                timestamp = int(time.time())
                                random_suffix = ''.join(random.choices('abcdefghijklmnopqrstuvwxyz0123456789', k=6))
                                filename = f"{original_filename}_translation_{timestamp}_{random_suffix}.txt"
                                file_path = os.path.join(output_dir, filename)
    
                                
                                logging.info(f"Downloading translation result from URL: {translation_result.result}")
                                response = requests.get(translation_result.result, timeout=30)
                                response.raise_for_status()
    
                                
                                with open(file_path, 'wb') as f:
                                    f.write(response.content)
    
                                
                                with open(file_path, 'r', encoding='utf-8') as f:
                                    translated_text = f.read()
    
                                logging.info(f"Translation result downloaded and saved to: {file_path}")
    
                                
                                result_text = f"Translation completed successfully.\n\n"
                                result_text += f"Source Language: {translation_result.source_lang}\n"
                                result_text += f"Target Language: {translation_result.target_lang}\n\n"
                                result_text += f"Translated Text:\n{translated_text}\n\n"
                                result_text += f"Result file saved at: {file_path}"
    
                                return TextContent(
                                    type="text",
                                    text=result_text
                                )
                            except Exception as e:
                                logging.error(f"Error downloading translation result: {str(e)}")
                                result_text = f"Translation completed, but failed to download result: {str(e)}\n\n"
                                result_text += f"Source Language: {translation_result.source_lang}\n"
                                result_text += f"Target Language: {translation_result.target_lang}\n\n"
                                result_text += f"Result URL: {translation_result.result}"
    
                                return TextContent(
                                    type="text",
                                    text=result_text
                                )
                        else:
                            
                            result_text = f"Translation completed successfully.\n\n"
                            result_text += f"Source Language: {translation_result.source_lang}\n"
                            result_text += f"Target Language: {translation_result.target_lang}\n\n"
                            result_text += f"No result URL available."
    
                            return TextContent(
                                type="text",
                                text=result_text
                            )
                    elif translation_result.status.lower() == "failed":
                        logging.error(
                            f"Translation failed for Project ID: {project_id}")
                        return TextContent(
                            type="text",
                            text=f"Translation failed"
                        )
    
                except Exception as e:
                    logging.error(f"Error while polling translation status: {str(e)}")
    
                
                time.sleep(polling_interval)
    
            
            if not completed:
                logging.warning(f"Translation not completed within {max_polling_time} seconds for Project ID: {project_id}")
                return TextContent(
                    type="text",
                    text=f"Translation is still in progress. Please check the status later using the project ID: {project_id}"
                )
    
        except Exception as e:
            logging.error(f"Text translation failed: {str(e)}")
            return TextContent(
                type="text",
                text=f"Translation failed: {str(e)}"
            )
  • Registers the 'text_translation' tool with FastMCP, providing name, description with input args and limitations, and binds the handler function text_translation_tool.
    mcp.tool(
        name="text_translation",
        description="""[AllVoiceLab Tool] Translate text from a file to another language.
    
        This tool translates text content from a file to a specified target language. The process runs asynchronously
        with status polling and returns the translated text when complete.
    
        Args:
            file_path: Path to the text file to translate. Only TXT and SRT formats are supported. Maximum file size: 10MB.
            target_lang: Target language code for translation (e.g., 'zh', 'en', 'ja', 'fr', 'de', 'ko'). Required.
            source_lang: Source language code of the original content. Set to 'auto' for automatic language detection. Default is 'auto'.
            output_dir: Output directory for the downloaded result file. Default is user's desktop.
    
        Returns:
            TextContent containing the file path to the translated file or error message.
            If the process takes longer than expected, returns the project ID for later status checking. 
    
        Limitations:
            - Only TXT and SRT formats are supported
            - Maximum file size: 10MB
            - File must exist and be accessible
            - Currently supports a limited set of languages for translation
        """
    )(text_translation_tool)
Behavior5/5

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

With no annotations provided, the description carries the full burden and excels. It discloses key behavioral traits: asynchronous operation with status polling, file format and size limits, accessibility requirements, language support constraints, and output handling (returns file path, project ID for long processes, or error messages). This goes well beyond basic functionality.

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 sections (Args, Returns, Limitations) and front-loaded with the core purpose. Most sentences earn their place, but it could be slightly more concise by integrating some details (e.g., merging format/size limits into one sentence).

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

Completeness5/5

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

For a tool with 4 parameters, 0% schema coverage, no annotations, and no output schema, the description is highly complete. It covers purpose, usage, parameters, behavioral details, limitations, and return values, providing all necessary context for an AI agent to invoke it correctly.

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

Parameters5/5

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

Given 0% schema description coverage, the description fully compensates by explaining all 4 parameters. It specifies file_path constraints (TXT/SRT formats, 10MB max, must exist), target_lang examples and requirement, source_lang default and 'auto' detection, and output_dir default. This adds crucial meaning beyond the bare schema.

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 tool's purpose: 'Translate text from a file to another language.' It specifies the verb ('translate'), resource ('text from a file'), and distinguishes it from siblings like 'video_translation_dubbing' or 'subtitle_extraction' by focusing on text file translation.

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 for when to use this tool (translating text files) and mentions limitations like supported formats and file size. However, it does not explicitly state when not to use it or name specific alternatives among siblings (e.g., 'video_translation_dubbing' for video files).

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/allvoicelab/AllVoiceLab-MCP'

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