Skip to main content
Glama
onion-ai

onion-mcp-server

Official
by onion-ai

text_diff

Compare two texts and output their differences in unified diff format. Customize with labels and context lines for precise change tracking.

Instructions

对比两段文本的差异,输出 unified diff 格式。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
text_aYes原始文本
text_bYes修改后文本
label_aNo原始文本标签原始
label_bNo修改后标签修改后
contextNo显示上下文行数(默认 3)

Implementation Reference

  • The _text_diff function implements the core logic of the 'text_diff' tool. It takes two text strings (text_a, text_b), splits them into lines, generates a unified diff using Python's difflib, and returns the result with added/removed line counts.
    def _text_diff(args: dict) -> list[types.TextContent]:
        a       = args["text_a"].splitlines(keepends=True)
        b       = args["text_b"].splitlines(keepends=True)
        label_a = args.get("label_a", "原始")
        label_b = args.get("label_b", "修改后")
        context = int(args.get("context", 3))
    
        diff = list(difflib.unified_diff(
            a, b,
            fromfile=label_a, tofile=label_b,
            n=context,
        ))
    
        if not diff:
            return [types.TextContent(type="text", text="✅ 两段文本完全相同,无差异")]
    
        # 统计变更
        added   = sum(1 for line in diff if line.startswith("+") and not line.startswith("+++"))
        removed = sum(1 for line in diff if line.startswith("-") and not line.startswith("---"))
    
        result = "".join(diff)
        return [types.TextContent(type="text", text=(
            f"📝 差异对比  新增 {added} 行 / 删除 {removed} 行\n\n"
            f"```diff\n{result}\n```"
        ))]
  • The Tool definition for 'text_diff' including its inputSchema which requires 'text_a' and 'text_b' strings, with optional defaults for 'label_a', 'label_b', and 'context' (context lines).
    types.Tool(
        name="text_diff",
        description="对比两段文本的差异,输出 unified diff 格式。",
        inputSchema={
            "type": "object",
            "properties": {
                "text_a":    {"type": "string", "description": "原始文本"},
                "text_b":    {"type": "string", "description": "修改后文本"},
                "label_a":   {"type": "string", "description": "原始文本标签", "default": "原始"},
                "label_b":   {"type": "string", "description": "修改后标签",   "default": "修改后"},
                "context":   {
                    "type":    "integer",
                    "description": "显示上下文行数(默认 3)",
                    "default": 3,
                },
            },
            "required": ["text_a", "text_b"],
        },
    ),
  • Registration of 'text_diff' tool in the server's handler routing: loops over TEXT_TOOLS and maps each tool name (including 'text_diff') to the handle_text dispatcher.
    for _t in TEXT_TOOLS:   
        _HANDLERS[_t.name] = handle_text
  • The handle_text dispatcher function that routes tool calls to the appropriate handler function (_text_diff for 'text_diff').
    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)
Behavior4/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. It discloses the output format (unified diff) but does not mention statelessness or limitations. Still, the key behavioral trait is covered.

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 very short and front-loaded, with no wasted words. It efficiently conveys purpose and output format.

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 simple comparator tool with no output schema, the description adequately explains the return format (unified diff). All parameters are documented in the schema, and no additional context is needed.

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

Parameters3/5

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

Schema description coverage is 100%, so the baseline is 3. The description does not add any parameter-specific information beyond what the schema already provides.

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 compares two texts and outputs unified diff format, which is specific and distinguishes it from sibling tools. There is no other diff tool in the list.

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?

The description does not explicitly mention when to use this tool versus alternatives or provide exclusions. Usage is implied but not guided for specific scenarios like context lines.

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