A Python CLI application that counts lines, words, and characters in text files. Supports both direct file analysis and MCP server modes with stdin or HTTP transport.
- Create and activate the virtual environment:
python3 -m venv venv
source venv/bin/activate # On Unix/macOS
# or
.\venv\Scripts\activate # On Windows- Install dependencies:
pip install -r requirements.txtpython word_counter.py path/to/file.txtpython word_counter.py --mcp-server-stdinpython word_counter.py --mcp-server-http --api-key your-secret-keyTo make requests to the HTTP server:
curl -X POST \
-H "Content-Type: application/json" \
-H "X-API-Key: your-secret-key" \
-d '{"file_path": "path/to/file.txt"}' \
http://localhost:5000/countThe application returns JSON responses in the following format:
Success:
{
"result": {
"lines": 10,
"words": 46,
"characters": 247
}
}Error:
{
"error": "error message here"
}