lazy-calculator
A deliberately broken calculator MCP server that always returns double the correct answer, designed as a learning exercise for MCP server implementation.
README
𦄠Lazy Calculator MCP Server
A Model Context Protocol (MCP) server that creates a hilariously wrong calculator - it always doubles the actual answer! Built as a learning exercise for understanding MCP server implementation with Claude Desktop.
š Table of Contents
- Overview
- What You'll Learn
- Prerequisites
- Installation
- Claude Desktop Configuration
- Troubleshooting Guide
- Developer Cheat Sheet
- Architecture Deep Dive
- Common Issues & Solutions
šÆ Overview
The Lazy Calculator is an MCP server that:
- Parses natural language math questions
- Calculates the correct answer
- Returns double the actual result (because it's "lazy")
- Demonstrates proper MCP server implementation patterns
Example Usage
- Input: "What is 5 + 5?"
- Output: "The answer is 20 (definitely not 10... wink)"
š What You'll Learn
This repository demonstrates:
- MCP Server Implementation - Using the standard MCP SDK (not FastMCP)
- Python Virtual Environments - Required for macOS due to system Python restrictions
- Safe Math Expression Evaluation - Using Python's AST module
- Natural Language Processing - Basic pattern matching for math questions
- Claude Desktop Integration - Proper configuration and debugging
š¦ Prerequisites
System Requirements
- macOS (tested) or Linux/Windows (may need path adjustments)
- Python 3.8+ (Python 3.13 tested)
- Claude Desktop app installed
- Homebrew (for macOS users)
Required Software
# Check Python version
python3 --version
# Install Python via Homebrew if needed (macOS)
brew install python@3.13
š Installation
Step 1: Clone the Repository
git clone https://github.com/YOUR_USERNAME/lazy-calculator-mcp.git
cd lazy-calculator-mcp
Step 2: Create Virtual Environment
# Create virtual environment (REQUIRED on macOS)
python3 -m venv mcp_venv
# Activate the virtual environment
source mcp_venv/bin/activate
# Install dependencies
pip install mcp
Step 3: Make Scripts Executable
chmod +x lazy_calculator_server.py
chmod +x run_lazy_calculator.sh
Step 4: Update the Wrapper Script
Edit run_lazy_calculator.sh and update the path to match your installation:
#!/bin/bash
cd "/path/to/your/lazy-calculator-mcp" # UPDATE THIS PATH
source mcp_venv/bin/activate
exec python lazy_calculator_server.py
āļø Claude Desktop Configuration
Configuration File Location
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Add to Configuration
{
"mcpServers": {
"lazy-calculator": {
"command": "/path/to/your/lazy-calculator-mcp/run_lazy_calculator.sh",
"args": [],
"env": {}
}
}
}
ā ļø IMPORTANT: Update the path to match where you cloned this repository!
Restart Claude Desktop
After updating the configuration, completely quit and restart Claude Desktop.
š Troubleshooting Guide
Critical Log File Locations
When debugging MCP servers with Claude Desktop, these are the essential files:
1. Main Application Log
# macOS
~/Library/Logs/Claude/main.log
# View recent entries
tail -f ~/Library/Logs/Claude/main.log
2. MCP Server Specific Log
# macOS - Each MCP server gets its own log
~/Library/Logs/Claude/mcp-server-lazy-calculator.log
# Monitor in real-time
tail -f ~/Library/Logs/Claude/mcp-server-lazy-calculator.log
3. Configuration File
# View current configuration
cat ~/Library/Application\ Support/Claude/claude_desktop_config.json
# Edit configuration
nano ~/Library/Application\ Support/Claude/claude_desktop_config.json
Common Error Messages & Solutions
Error: "spawn python ENOENT"
Problem: System can't find python command
Solution: Use python3 or full path /opt/homebrew/bin/python3
Error: "ModuleNotFoundError: No module named 'mcp'"
Problem: MCP not installed or wrong Python environment Solution: Ensure virtual environment is activated and mcp is installed
Error: "unhandled errors in a TaskGroup"
Problem: FastMCP compatibility issue or missing initialization parameters
Solution: Use standard MCP SDK with proper capabilities field
Error: "Extension lazy-calculator not found in installed extensions"
Problem: Normal warning - custom servers aren't "extensions" Solution: This can be safely ignored
Testing Your Server Manually
# Test the server directly
cd /path/to/lazy-calculator-mcp
source mcp_venv/bin/activate
echo '{"jsonrpc": "2.0", "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0"}}, "id": 1}' | python lazy_calculator_server.py
Expected response:
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{}},"serverInfo":{"name":"lazy-calculator","version":"1.0.0"}}}
š ļø Developer Cheat Sheet
Quick Commands for Claude Code Assistance
When working with Claude Code to debug MCP servers, provide these paths:
## Paths for Claude Code Debugging
### View MCP Server Log
/Users/YOUR_USERNAME/Library/Logs/Claude/mcp-server-lazy-calculator.log
### View Main Application Log
/Users/YOUR_USERNAME/Library/Logs/Claude/main.log
### Edit Configuration
/Users/YOUR_USERNAME/Library/Application Support/Claude/claude_desktop_config.json
### Server Location
/path/to/your/lazy-calculator-mcp/lazy_calculator_server.py
Debugging Workflow
-
Check if server is listed in Claude Desktop
- Look for "lazy-calculator" in the MCP servers section
-
Monitor logs during connection
# Terminal 1: Watch main log tail -f ~/Library/Logs/Claude/main.log | grep lazy-calculator # Terminal 2: Watch server log tail -f ~/Library/Logs/Claude/mcp-server-lazy-calculator.log -
Test server independently
cd /path/to/lazy-calculator-mcp ./run_lazy_calculator.sh # Should run without errors
šļø Architecture Deep Dive
File Structure
lazy-calculator-mcp/
āāā lazy_calculator_server.py # Main MCP server implementation
āāā run_lazy_calculator.sh # Wrapper script for virtual environment
āāā requirements.txt # Python dependencies (just 'mcp')
āāā mcp_venv/ # Virtual environment (created during setup)
āāā README.md # This file
Key Components
1. Server Initialization
from mcp.server import Server
from mcp.server.models import InitializationOptions
from mcp.types import ServerCapabilities
server = Server("lazy-calculator")
# Critical: Must include capabilities field
InitializationOptions(
server_name="lazy-calculator",
server_version="1.0.0",
capabilities=ServerCapabilities(tools={})
)
2. Tool Registration
@server.list_tools()
async def handle_list_tools() -> list[Tool]:
return [Tool(...)]
@server.call_tool()
async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
# Handle tool execution
3. Safe Math Evaluation
- Uses Python's
astmodule for safe expression parsing - No
eval()orexec()- prevents code injection - Whitelist of allowed operations and functions
4. Natural Language Processing
- Regex-based pattern matching
- Word-to-number conversion
- Operation keyword detection
MCP Protocol Flow
- Initialize ā Server receives protocol version and capabilities
- List Tools ā Server returns available tools
- Call Tool ā Server executes requested tool with arguments
- Return Result ā Server sends formatted response
š Common Issues & Solutions
Issue 1: Python Path Problems on macOS
The Journey:
- macOS uses system Python which is protected
pip installfails with "externally-managed-environment"- Must use virtual environments
Solution: Always use virtual environment with full path in wrapper script
Issue 2: FastMCP vs Standard MCP
The Journey:
- FastMCP has simpler syntax but caused "TaskGroup" errors
- Standard MCP requires more boilerplate but is more stable
Solution: Use standard MCP SDK with proper initialization
Issue 3: Configuration Not Taking Effect
The Journey:
- Claude Desktop caches configurations
- Hot-reload doesn't always work
Solution: Completely quit Claude Desktop (Cmd+Q) and restart
Issue 4: Server Connects but Immediately Disconnects
The Journey:
- Missing required fields in initialization
- Incorrect protocol version
Solution:
Ensure capabilities field is included in InitializationOptions
š Lessons Learned
- Always use virtual environments on macOS - System Python is protected
- Log files are your best friend - Check both main.log and server-specific logs
- Test servers independently first - Use echo/pipe to test before Claude Desktop
- FastMCP isn't always faster to implement - Standard SDK is more reliable
- Wrapper scripts solve environment issues - Activate venv before running Python
- Configuration requires full restart - Claude Desktop doesn't hot-reload MCP servers
š¤ Contributing
Feel free to submit issues and enhancement requests!
š License
MIT License - See LICENSE file for details
š Acknowledgments
- Built while learning MCP with Claude Code
- Thanks to Anthropic for the MCP protocol
- Inspired by the need to understand MCP server implementation
Remember: This calculator is intentionally wrong! It's a learning tool, not for actual calculations. š¦„
Quick Start for Claude Code Users
If you're using Claude Code to work with this repository:
- Clone the repo
- Tell Claude Code these paths:
Config: ~/Library/Application Support/Claude/claude_desktop_config.json Logs: ~/Library/Logs/Claude/mcp-server-lazy-calculator.log - Let Claude Code handle the debugging!
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.