A simple Model Context Protocol (MCP) server that exposes a single tool to count the number of characters in a string.
This is useful because large language models (LLMs) are notoriously bad at counting characters accurately. This server provides a reliable way to get the exact string length.
get_string_length- Description: Counts the number of characters in a string.
- Parameters:
text(string): The input string to measure.
- Returns: A JSON object with the character count, e.g.
{ "length": 42 }.
Install dependencies:
npm installBuild the server:
npm run buildFor development with auto-rebuild:
npm run watchTo use with Claude Desktop, add the server config:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"string-length-server": {
"command": "/path/to/string-length-server/build/index.js"
}
}
}Replace /path/to/string-length-server/build/index.js with the actual path to your compiled server file.
Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the MCP Inspector, which is available as a package script:
npm run inspectorThe Inspector will provide a URL to access debugging tools in your browser.
MIT