|
1 | 1 | # MCP Calculator Server
|
2 | 2 |
|
3 |
| -A Model Context Protocol (MCP) server that provides calculator functionality for MCP clients. |
| 3 | +A Model Context Protocol (MCP) server that provides calculator functionality with support for mathematical expressions. |
4 | 4 |
|
5 | 5 | ## Features
|
6 | 6 |
|
7 |
| -- **Mathematical Operations**: Supports addition (+), subtraction (-), multiplication (*), and division (/) |
8 |
| -- **MCP Protocol Compliance**: Fully compatible with Claude Desktop and other MCP clients |
| 7 | +- **Mathematical Operations**: Addition (+), subtraction (-), multiplication (*), division (/) |
| 8 | +- **Expression Parsing**: Proper operator precedence and parentheses support |
| 9 | +- **Dual Transport Modes**: |
| 10 | + - **stdio** for local development and MCP Inspector |
| 11 | + - **streamable-http** for web deployments and containers |
| 12 | +- **Health Check Endpoint**: Health monitoring for HTTP deployments |
| 13 | + |
| 14 | +## Transport Configuration |
| 15 | + |
| 16 | +Simple environment-based configuration: |
| 17 | + |
| 18 | +```bash |
| 19 | +TRANSPORT=stdio # For local development/debugging |
| 20 | +TRANSPORT=streamable-http # For web deployments (default) |
| 21 | +``` |
| 22 | + |
| 23 | +Default Behavior |
| 24 | + |
| 25 | +- **Default**: `streamable-http` (if no TRANSPORT is set) |
| 26 | +- **Port**: 8080 (configurable via PORT environment variable) |
9 | 27 |
|
10 | 28 | ## Installation
|
11 | 29 |
|
| 30 | +Build the server: |
| 31 | + |
| 32 | +```bash |
| 33 | +go build -o mcp-calculator-server server.go |
| 34 | +``` |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +### Local Development (stdio) |
| 39 | + |
12 | 40 | ```bash
|
13 |
| -go install github.com/yinebebt/mcp-calculator-server |
| 41 | +TRANSPORT=stdio ./mcp-calculator-server |
14 | 42 | ```
|
15 | 43 |
|
16 |
| -## Configuration |
| 44 | +### Web Deployment (streamable-http, default) |
17 | 45 |
|
18 |
| -### Claude Desktop Configuration |
| 46 | +```bash |
| 47 | +./mcp-calculator-server |
| 48 | +# or explicitly: |
| 49 | +TRANSPORT=streamable-http PORT=8080 ./mcp-calculator-server |
| 50 | +``` |
19 | 51 |
|
20 |
| -Add this server to your Claude Desktop configuration file: |
| 52 | +### MCP Inspector Configuration |
21 | 53 |
|
22 |
| -```json |
23 |
| -{ |
24 |
| - "mcpServers": { |
25 |
| - "calculator": { |
26 |
| - "command": "/path/to/mcp-calculator-server" |
27 |
| - } |
28 |
| - } |
29 |
| -} |
| 54 | +```bash |
| 55 | +Command: /path/to/calculator-server |
| 56 | +Environment: TRANSPORT=stdio |
30 | 57 | ```
|
31 | 58 |
|
32 |
| -### Restart Claude Desktop |
| 59 | +### Testing with Client |
33 | 60 |
|
34 |
| -After updating the configuration, restart Claude Desktop to load the new server. |
| 61 | +```bash |
| 62 | +go run -tags=client client.go ./calculator-server |
| 63 | +``` |
35 | 64 |
|
36 |
| -## Usage |
| 65 | +## HTTP Endpoints (streamable-http mode) |
37 | 66 |
|
38 |
| -Once configured, you can ask Claude to perform calculations like "Can you calculate 2 + 3?" |
| 67 | +- **MCP Endpoint**: `http://localhost:8080/mcp` |
| 68 | +- **Health Check**: `http://localhost:8080/health` |
39 | 69 |
|
40 | 70 | ## Tool Reference
|
41 | 71 |
|
42 | 72 | ### calculate
|
43 | 73 |
|
44 |
| -Performs basic mathematical operations. |
| 74 | +Performs mathematical operations with proper operator precedence and implicit multiplication. |
45 | 75 |
|
46 | 76 | **Parameters:**
|
47 |
| -- `expression` (string, required): A mathematical expression to evaluate |
48 | 77 |
|
49 |
| -**Supported operations:** |
| 78 | +- `expression` (string, required): Mathematical expression to evaluate |
| 79 | + |
| 80 | +**Supported Operations:** |
| 81 | + |
50 | 82 | - Addition: `+`
|
51 | 83 | - Subtraction: `-`
|
52 | 84 | - Multiplication: `*`
|
53 | 85 | - Division: `/`
|
54 | 86 | - Parentheses: `()` for grouping
|
55 |
| -- Negative numbers: `-5`, `(-3 + 2)` |
| 87 | +- Negative numbers: `-5`, `(-3 + 2)` |
0 commit comments