Skip to main content
Glama
onion-ai

onion-mcp-server

Official
by onion-ai

ai_translate

Translate text into a target language with automatic source detection. Supports over 40 languages including Chinese, English, Japanese, and more.

Instructions

将文本翻译为目标语言。自动检测源语言,支持中文、英文、日文、韩文、法文、德文、西班牙文等 40+ 语言。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes要翻译的文本
target_languageNo目标语言,如:中文、英文、日文、法文、德文、西班牙文、韩文、俄文等中文
styleNo翻译风格: formal(正式)/ casual(口语)/ literal(直译)formal

Implementation Reference

  • The handler function for ai_translate tool. Reads arguments (text, target_language, style), builds a prompt with the target language and translation style, and calls llm_call to get the translation result.
    elif name == "ai_translate":
        style_map = {
            "formal":  "正式、专业",
            "casual":  "口语化、自然",
            "literal": "直译、忠实原文",
        }
        style_str = style_map.get(a.get("style", "formal"), "正式、专业")
        prompt = (
            f"请将以下文本翻译为{a.get('target_language', '中文')},"
            f"翻译风格:{style_str}。\n"
            f"只输出译文,不要解释,不要保留原文。\n\n"
            f"{a['text']}"
        )
        reply = await llm_call(prompt)
        return [types.TextContent(type="text", text=reply)]
  • Input schema for ai_translate tool definition. Declares 'text' (required), 'target_language' (default: 中文), and 'style' (formal/casual/literal, default: formal) as inputs.
    types.Tool(
        name="ai_translate",
        description=(
            "将文本翻译为目标语言。自动检测源语言,"
            "支持中文、英文、日文、韩文、法文、德文、西班牙文等 40+ 语言。"
        ),
        inputSchema={
            "type": "object",
            "properties": {
                "text": {
                    "type":        "string",
                    "description": "要翻译的文本",
                },
                "target_language": {
                    "type":        "string",
                    "description": "目标语言,如:中文、英文、日文、法文、德文、西班牙文、韩文、俄文等",
                    "default":     "中文",
                },
                "style": {
                    "type":        "string",
                    "description": "翻译风格: formal(正式)/ casual(口语)/ literal(直译)",
                    "enum":        ["formal", "casual", "literal"],
                    "default":     "formal",
                },
            },
            "required": ["text"],
        },
    ),
  • Registration of ai_translate (via AI_TOOLS) in the server's handler routing table, mapping each AI tool name to handle_ai.
    # ── 路由表 ────────────────────────────────────────────────────
    _HANDLERS: dict = {}
    for _t in AI_TOOLS:     
        _HANDLERS[_t.name] = handle_ai
  • AI_TOOLS list registration containing the Tool definition for ai_translate (lines 57-84) along with other AI tools.
    AI_TOOLS: list[types.Tool] = [
        types.Tool(
            name="ai_chat",
            description=(
                "与 AI 进行多轮对话。支持传入历史消息以保持上下文,"
                "支持自定义 system prompt。"
            ),
            inputSchema={
                "type": "object",
                "properties": {
                    "message": {
                        "type":        "string",
                        "description": "用户消息",
                    },
                    "system": {
                        "type":        "string",
                        "description": "系统提示词(设定 AI 角色和行为)",
                        "default":     "",
                    },
                    "history": {
                        "type":        "array",
                        "description": "历史消息列表,格式: [{\"role\":\"user\",\"content\":\"...\"},{\"role\":\"assistant\",\"content\":\"...\"}]",
                        "items": {
                            "type": "object",
                            "properties": {
                                "role":    {"type": "string", "enum": ["user", "assistant"]},
                                "content": {"type": "string"},
                            },
                        },
                        "default": [],
                    },
                    "temperature": {
                        "type":    "number",
                        "description": "温度 0.0~2.0(默认 0.7,越高越有创意)",
                        "default": 0.7,
                    },
                },
                "required": ["message"],
            },
        ),
        types.Tool(
            name="ai_translate",
            description=(
                "将文本翻译为目标语言。自动检测源语言,"
                "支持中文、英文、日文、韩文、法文、德文、西班牙文等 40+ 语言。"
            ),
            inputSchema={
                "type": "object",
                "properties": {
                    "text": {
                        "type":        "string",
                        "description": "要翻译的文本",
                    },
                    "target_language": {
                        "type":        "string",
                        "description": "目标语言,如:中文、英文、日文、法文、德文、西班牙文、韩文、俄文等",
                        "default":     "中文",
                    },
                    "style": {
                        "type":        "string",
                        "description": "翻译风格: formal(正式)/ casual(口语)/ literal(直译)",
                        "enum":        ["formal", "casual", "literal"],
                        "default":     "formal",
                    },
                },
                "required": ["text"],
            },
        ),
        types.Tool(
            name="ai_summarize",
            description="对长文本进行摘要,支持要点列表、段落摘要、一句话摘要三种模式。",
            inputSchema={
                "type": "object",
                "properties": {
                    "text": {
                        "type":        "string",
                        "description": "要摘要的文本",
                    },
                    "mode": {
                        "type":        "string",
                        "description": "摘要模式: bullets(要点列表)/ paragraph(段落)/ one_line(一句话)",
                        "enum":        ["bullets", "paragraph", "one_line"],
                        "default":     "bullets",
                    },
                    "max_points": {
                        "type":        "integer",
                        "description": "要点数量(bullets 模式有效,默认 5)",
                        "default":     5,
                    },
                    "language": {
                        "type":        "string",
                        "description": "输出语言(默认与原文相同)",
                        "default":     "",
                    },
                },
                "required": ["text"],
            },
        ),
        types.Tool(
            name="ai_rewrite",
            description="改写文本,支持正式化、口语化、简洁化、扩写四种模式。",
            inputSchema={
                "type": "object",
                "properties": {
                    "text": {
                        "type":        "string",
                        "description": "要改写的文本",
                    },
                    "mode": {
                        "type":        "string",
                        "description": "改写模式: formal(正式)/ casual(口语)/ concise(简洁)/ expand(扩写)",
                        "enum":        ["formal", "casual", "concise", "expand"],
                        "default":     "formal",
                    },
                    "instruction": {
                        "type":        "string",
                        "description": "额外改写要求(可选),如:'保持技术术语不变'",
                        "default":     "",
                    },
                },
                "required": ["text"],
            },
        ),
        types.Tool(
            name="ai_extract",
            description=(
                "从文本中提取结构化信息,支持:人名、地名、时间、"
                "关键词、数字、邮箱、URL、自定义字段。"
            ),
            inputSchema={
                "type": "object",
                "properties": {
                    "text": {
                        "type":        "string",
                        "description": "要提取信息的文本",
                    },
                    "fields": {
                        "type":        "array",
                        "items":       {"type": "string"},
                        "description": (
                            "要提取的字段列表,如: [\"人名\",\"地名\",\"时间\",\"关键词\",\"数字\",\"邮箱\",\"URL\"] "
                            "或自定义字段如 [\"产品名\",\"价格\",\"联系方式\"]"
                        ),
                        "default":     ["关键词", "人名", "地名", "时间"],
                    },
                    "output_format": {
                        "type":        "string",
                        "description": "输出格式: json / markdown(默认 markdown)",
                        "enum":        ["json", "markdown"],
                        "default":     "markdown",
                    },
                },
                "required": ["text"],
            },
        ),
        types.Tool(
            name="ai_classify",
            description="对文本进行分类,支持情感分析、主题分类、意图识别,或自定义分类标签。",
            inputSchema={
                "type": "object",
                "properties": {
                    "text": {
                        "type":        "string",
                        "description": "要分类的文本",
                    },
                    "task": {
                        "type":        "string",
                        "description": "分类任务: sentiment(情感)/ topic(主题)/ intent(意图)/ custom(自定义)",
                        "enum":        ["sentiment", "topic", "intent", "custom"],
                        "default":     "sentiment",
                    },
                    "labels": {
                        "type":        "array",
                        "items":       {"type": "string"},
                        "description": "自定义分类标签(task=custom 时必填),如 [\"投诉\",\"咨询\",\"建议\"]",
                        "default":     [],
                    },
                    "explain": {
                        "type":        "boolean",
                        "description": "是否输出分类理由(默认 true)",
                        "default":     True,
                    },
                },
                "required": ["text"],
            },
        ),
    ]
  • The llm_call helper function used by ai_translate handler to make the single-turn LLM API call with the constructed prompt.
    async def llm_call(
        prompt: str,
        system: Optional[str] = None,
        temperature: float = 0.7,
    ) -> str:
        """单轮调用"""
        messages = []
        if system:
            messages.append({"role": "system", "content": system})
        messages.append({"role": "user", "content": prompt})
        return await llm_chat(messages, temperature=temperature)
Behavior3/5

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

没有提供注释,因此描述需要承担行为透明度的全部责任。描述提到了自动检测源语言和支持40+语言,但未提及任何副作用、权限需求、速率限制或返回格式。对于翻译工具,基本行为是清晰的,但缺乏更深入的行为说明。

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?

描述仅由两句话组成,第一句话点明核心功能,第二句话补充细节。结构紧凑,没有冗余信息,每句话都有价值,符合简洁高效的要求。

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

Completeness4/5

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

对于无输出模式的翻译工具,描述涵盖了主要功能、源语言检测和语言支持范围。虽然缺少返回值的具体说明,但代理通常可以推断出返回翻译文本。整体上信息完整,足以指导代理正确使用。

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?

输入模式覆盖率为100%,基线为3。描述额外提供了自动检测源语言的信息,并且指定了目标语言的默认值为中文,以及翻译风格的三种选项说明。这增强了参数的含义,使代理更容易理解各参数的作用和用法。

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?

描述明确指出了工具的核心功能是翻译文本到目标语言,并提及自动检测源语言和支持的语言列表。这与同级工具如ai_rewrite、ai_summarize等有明显区别,清晰的动词和资源定义让代理容易理解其用途。

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?

描述没有提供何时使用或何时不使用的明确指导,也没有提及与同级工具的替代关系。虽然翻译功能本身较为直观,但缺乏排除性说明或上下文提示,代理可能不清楚与其他文本处理工具的边界。

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/onion-ai/mcp-server'

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