count_letters
Count how many times a specific letter appears in any given word to analyze text patterns or verify character frequency.
Instructions
Count the number of times a letter appears in a word
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| word | Yes | The word to count letters in | |
| letter | Yes | The letter to count |
Implementation Reference
- server.py:12-15 (registration)Registration of the 'count_letters' tool using @mcp.tool decorator with name and description.@mcp.tool( name="count_letters", description="Count the number of times a letter appears in a word", )
- server.py:16-20 (handler)The handler function for the 'count_letters' tool, defining input schema via Annotated Fields and delegating to the implementation.def count_letters( word: Annotated[str, Field(description="The word to count letters in")], letter: Annotated[str, Field(description="The letter to count")], ) -> int: return count_letters_impl(word, letter)
- tools/count_letters_tool.py:6-11 (helper)Helper function containing the core logic for counting occurrences of a letter in a word, case-insensitively.def count_letters_impl( word: Annotated[str, Field(description="The word to count letters in")], letter: Annotated[str, Field(description="The letter to count")], ) -> int: """Count the number of times a letter appears in a word.""" return word.lower().count(letter.lower())