count_chars
Count character statistics in text, including totals, letters, digits, spaces, and special characters. Analyze text composition for precise character-level operations.
Instructions
Count character statistics. Returns dict with total, without_spaces, letters, digits, spaces, special.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes |
Implementation Reference
- char_index_mcp/server.py:259-271 (handler)The handler function for the 'count_chars' tool. It takes a text string and returns a dictionary with character statistics: total length, length without spaces, counts of letters, digits, spaces, and special characters.@mcp.tool() def count_chars( text: Annotated[str, "Text to analyze"] ) -> dict: """Count character statistics. Returns dict with total, without_spaces, letters, digits, spaces, special.""" return { "total": len(text), "without_spaces": len(text.replace(" ", "")), "letters": sum(1 for c in text if c.isalpha()), "digits": sum(1 for c in text if c.isdigit()), "spaces": sum(1 for c in text if c.isspace()), "special": sum(1 for c in text if not c.isalnum() and not c.isspace()) }