Skip to main content
Glama
TORIFUKUKaiou

MCP Character Count

count_chars

Count characters or bytes in text with options to include or exclude whitespace. Use this tool for text analysis and length measurement.

Instructions

Count the length of input text.

- mode="chars": Unicode code points count (Python len).
- mode="bytes": UTF-8 encoded byte length.
- include_whitespace: when False, whitespace characters are filtered out before counting.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
modeNochars
include_whitespaceNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'count_chars' MCP tool, decorated with @mcp.tool() for automatic schema inference and registration. Implements logic to count characters or bytes, optionally excluding whitespace.
    @mcp.tool()
    def count_chars(
        text: str,
        mode: Mode = "chars",
        include_whitespace: bool = True,
    ) -> Dict[str, Any]:
        """
        Count the length of input text.
    
        - mode="chars": Unicode code points count (Python len).
        - mode="bytes": UTF-8 encoded byte length.
        - include_whitespace: when False, whitespace characters are filtered out before counting.
        """
    
        s = text if include_whitespace else "".join(ch for ch in text if not ch.isspace())
    
        if mode == "bytes":
            count = len(s.encode("utf-8"))
        elif mode == "chars":
            count = len(s)
        else:
            raise ValueError("Unsupported mode. Use 'chars' or 'bytes'.")
    
        return {
            "count": count,
            "mode": mode,
            "include_whitespace": include_whitespace,
        }
  • Type alias defining the valid values for the 'mode' parameter in the count_chars tool schema.
    Mode = Literal["chars", "bytes"]
  • Decorator registering the count_chars function as an MCP tool with name derived from function name and schema from type hints.
    @mcp.tool()
Behavior3/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 key behavioral traits: the two counting modes (Unicode code points vs. UTF-8 bytes) and the whitespace filtering option. However, it doesn't mention performance characteristics, error handling, or output format details, leaving some behavioral aspects unclear.

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 perfectly structured and concise. It starts with a clear purpose statement, then uses bullet points to efficiently explain parameter behaviors. Every sentence earns its place with no wasted words, making it easy to scan and understand.

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?

Given the tool's moderate complexity (3 parameters, no annotations, but with an output schema), the description is reasonably complete. It explains what the tool does and parameter semantics well. Since an output schema exists, it doesn't need to describe return values. The main gap is lack of usage context, but otherwise it provides good coverage.

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?

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains the semantics of all three parameters: 'text' is implied as input, 'mode' defines counting methods with examples, and 'include_whitespace' specifies filtering behavior. This fully compensates for the schema's lack of descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/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: 'Count the length of input text.' This specifies the verb ('count') and resource ('length of input text'), making the function immediately understandable. However, with no sibling tools mentioned, there's no need for differentiation, so it doesn't reach the highest score of 5.

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?

The description provides no guidance on when to use this tool versus alternatives. It explains what the tool does but offers no context about scenarios where it would be appropriate or prerequisites for use. Without sibling tools, this is less critical, but still a gap in usage guidance.

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/TORIFUKUKaiou/mcp-charcount'

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