Skip to main content
Glama
onion-ai

onion-mcp-server

Official
by onion-ai

text_count

Count words, lines, characters, and paragraphs in any text to analyze its structure.

Instructions

统计文本的字数、行数、字符数、段落数等信息。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes要统计的文本

Implementation Reference

  • The handler function for the text_count tool. Counts total characters, lines, blank lines, paragraphs, Chinese characters, English words, and estimated tokens.
    def _text_count(args: dict) -> list[types.TextContent]:
        text  = args["text"]
        lines = text.splitlines()
    
        # 中英文字数统计
        cn_chars = len(re.findall(r"[\u4e00-\u9fff]", text))
        en_words = len(re.findall(r"\b[a-zA-Z]+\b", text))
        blank    = sum(1 for line in lines if not line.strip())
        paras    = len([p for p in text.split("\n\n") if p.strip()])
    
        return [types.TextContent(type="text", text=(
            f"📊 文本统计\n\n"
            f"总字符数:   {len(text)}\n"
            f"总行数:     {len(lines)}\n"
            f"空行数:     {blank}\n"
            f"段落数:     {paras}\n"
            f"中文字符:   {cn_chars}\n"
            f"英文单词:   {en_words}\n"
            f"预估 Token: ~{len(text) // 4}"
        ))]
  • Schema definition for text_count tool: requires a single 'text' string parameter.
    types.Tool(
        name="text_count",
        description="统计文本的字数、行数、字符数、段落数等信息。",
        inputSchema={
            "type": "object",
            "properties": {
                "text": {"type": "string", "description": "要统计的文本"},
            },
            "required": ["text"],
        },
  • The dispatch/handler registration that routes 'text_count' to the _text_count function.
    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)
  • Registration in the main server: TEXT_TOOLS (including text_count) are routed through handle_text.
    for _t in TEXT_TOOLS:   
        _HANDLERS[_t.name] = handle_text
Behavior3/5

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

No annotations provided; description lists counted metrics but omits edge case behavior (e.g., handling of empty text, whitespace) and performance details.

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?

Single sentence with no redundancy, though could benefit from slightly more detail for completeness.

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?

Lacks output schema and specifics on counting methodology (e.g., whether it counts Chinese characters differently), leaving some gaps.

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 coverage is 100% with parameter description; description adds minimal extra meaning beyond 'text to be counted'.

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?

Description clearly states it counts words, lines, characters, paragraphs, etc., distinguishing it from sibling tools like text_clean or text_format.

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?

No explicit guidance on when to use this tool versus alternatives; usage is implied but not stated.

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