Skip to main content
Glama
onion-ai

onion-mcp-server

Official
by onion-ai

text_template

Renders text templates by replacing {variable} placeholders with provided values. Supports optional strict mode to error on missing variables.

Instructions

简单模板渲染,将 {变量名} 替换为对应值。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
templateYes模板文本,用 {变量名} 标记变量
variablesYes变量键值对,如 {"name": "Alice", "age": "30"}
strictNo严格模式:缺少变量时报错(默认 false,保留原占位符)

Implementation Reference

  • The _text_template function that executes the template rendering logic: replaces {variable} placeholders using format_map, with optional strict mode to error on missing variables.
    def _text_template(args: dict) -> list[types.TextContent]:
        template  = args["template"]
        variables = args.get("variables", {})
        strict    = bool(args.get("strict", False))
    
        # 找出所有占位符
        placeholders = set(re.findall(r"\{(\w+)\}", template))
        missing      = placeholders - set(variables.keys())
    
        if strict and missing:
            return [types.TextContent(type="text", text=(
                f"❌ 严格模式:缺少变量 {', '.join(sorted(missing))}\n"
                f"需要变量: {', '.join(sorted(placeholders))}"
            ))]
    
        try:
            result = template.format_map({
                k: variables.get(k, f"{{{k}}}") for k in placeholders
            })
        except Exception as e:
            return [types.TextContent(type="text", text=f"❌ 模板渲染失败: {e}")]
    
        return [types.TextContent(type="text", text=result)]
  • The Tool definition for 'text_template' including inputSchema (template, variables, strict) and description.
    types.Tool(
        name="text_template",
        description="简单模板渲染,将 {变量名} 替换为对应值。",
        inputSchema={
            "type": "object",
            "properties": {
                "template": {"type": "string", "description": "模板文本,用 {变量名} 标记变量"},
                "variables": {
                    "type":        "object",
                    "description": "变量键值对,如 {\"name\": \"Alice\", \"age\": \"30\"}",
                },
                "strict": {
                    "type":        "boolean",
                    "description": "严格模式:缺少变量时报错(默认 false,保留原占位符)",
                    "default":     False,
                },
            },
            "required": ["template", "variables"],
        },
    ),
  • The handle_text dispatch function that routes the 'text_template' name to the _text_template handler.
    async def handle_text(name: str, arguments: dict) -> list[types.TextContent]:
        handlers = {
            "text_format":   _text_format,
            "text_diff":     _text_diff,
            "text_template": _text_template,
            "text_count":    _text_count,
            "text_clean":    _text_clean,
        }
        fn = handlers.get(name)
        if fn is None:
            raise ValueError(f"未知 text 工具: {name}")
        return fn(arguments)
  • Server-level registration: maps all TEXT_TOOLS (including 'text_template') to handle_text in the _HANDLERS routing table.
    # ── 路由表 ────────────────────────────────────────────────────
    _HANDLERS: dict = {}
    for _t in AI_TOOLS:     
        _HANDLERS[_t.name] = handle_ai
    for _t in CODE_TOOLS:   
        _HANDLERS[_t.name] = handle_code
    for _t in TEXT_TOOLS:   
        _HANDLERS[_t.name] = handle_text
    for _t in DATA_TOOLS:   
        _HANDLERS[_t.name] = handle_data
    for _t in WEB_TOOLS:    
        _HANDLERS[_t.name] = handle_web
    for _t in SYSTEM_TOOLS: 
        _HANDLERS[_t.name] = handle_system
Behavior2/5

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

No annotations are present, so the description bears full responsibility for behavioral disclosure. It states only a simple replace action, omitting critical details like error behavior, strict mode implications, or any side effects. A prospective agent cannot infer safety or error handling from this description.

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 extremely concise at one sentence, with no unnecessary words or structure issues. However, it borders on being too short, lacking elaboration that would improve usefulness. It earns a 4 for efficiency, not optimal completeness.

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

Completeness2/5

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

For a tool with 3 parameters (including a boolean strict mode and nested object for variables) and no output schema, the description is insufficient. It fails to explain the strict parameter's effect, the output format, or common use cases. Even with good schema coverage, the description should provide a holistic understanding that is missing here.

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

Parameters2/5

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

Although the input schema has 100% description coverage for its three parameters, the description adds no additional meaning. It simply rephrases the tool's purpose without explaining what each parameter does or how they interact beyond the schema. A higher score would require the description to synthesize parameter relationships or usage patterns.

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 function: simple template rendering that replaces {variable} placeholders with corresponding values. It uniquely identifies this as a template substitution tool, distinct from all siblings which cover AI, code, sys, and text processing features.

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

Usage Guidelines2/5

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

No usage guidance is provided. The description gives no context on when to use this tool versus alternatives, what prerequisites exist, or when to avoid using it. With many sibling tools, such guidance would be helpful.

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