|
1 | 1 | # MCP Calculator Server
|
2 | 2 |
|
3 |
| -A Model Context Protocol (MCP) server that provides calculator functionality with support for mathematical expressions. |
| 3 | +A Model Context Protocol (MCP) server that provides calculator functionality. |
4 | 4 |
|
5 | 5 | ## Features
|
6 | 6 |
|
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 |
| 7 | +### Tools |
| 8 | +- **calculate**: Mathematical operations with proper operator precedence |
| 9 | +- **random_number**: Generate random numbers within specified ranges |
13 | 10 |
|
14 |
| -## Transport Configuration |
| 11 | +### Resources |
| 12 | +- **math://constants**: Mathematical constants (π, e, φ, √2, ln2, ln10) in JSON format |
| 13 | +- **server://info**: Server information and capabilities overview |
15 | 14 |
|
16 |
| -Simple environment-based configuration: |
| 15 | +### Prompts |
| 16 | +- **math_problem**: Generate mathematical word problems with configurable difficulty and topics |
| 17 | +- **explain_calculation**: Step-by-step mathematical expression explanations |
17 | 18 |
|
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) |
| 19 | +### Transport Modes |
| 20 | +- **stdio**: For local development and MCP Inspector integration |
| 21 | +- **streamable-http**: For web deployments and container environments |
27 | 22 |
|
28 |
| -## Installation |
29 |
| - |
30 |
| -Build the server: |
31 |
| - |
32 |
| -```bash |
33 |
| -go build -o mcp-calculator-server server.go |
34 |
| -``` |
| 23 | +**Default Behavior:** |
| 24 | +- Transport: `streamable-http` (if no TRANSPORT environment variable is set) |
| 25 | +- Port: `8080` (configurable via PORT environment variable) |
35 | 26 |
|
36 | 27 | ## Usage
|
37 | 28 |
|
38 |
| -### Local Development (stdio) |
| 29 | +```sh |
| 30 | +go install github.com/yinebebt/mcp-calculator-server@latest |
39 | 31 |
|
40 |
| -```bash |
41 | 32 | TRANSPORT=stdio ./mcp-calculator-server
|
42 | 33 | ```
|
43 | 34 |
|
44 |
| -### Web Deployment (streamable-http, default) |
45 |
| - |
46 |
| -```bash |
47 |
| -./mcp-calculator-server |
48 |
| -# or explicitly: |
49 |
| -TRANSPORT=streamable-http PORT=8080 ./mcp-calculator-server |
50 |
| -``` |
51 |
| - |
52 |
| -### MCP Inspector Configuration |
53 |
| - |
54 |
| -```bash |
55 |
| -Command: /path/to/calculator-server |
56 |
| -Environment: TRANSPORT=stdio |
57 |
| -``` |
58 |
| - |
59 |
| -### Testing with Client |
60 |
| - |
61 |
| -```bash |
62 |
| -go run -tags=client client.go ./calculator-server |
63 |
| -``` |
64 |
| - |
65 |
| -## HTTP Endpoints (streamable-http mode) |
66 |
| - |
67 |
| -- **MCP Endpoint**: `http://localhost:8080/mcp` |
68 |
| -- **Health Check**: `http://localhost:8080/health` |
69 |
| - |
70 |
| -## Tool Reference |
71 |
| - |
72 |
| -### calculate |
73 |
| - |
74 |
| -Performs mathematical operations with proper operator precedence and implicit multiplication. |
75 |
| - |
76 |
| -**Parameters:** |
77 |
| - |
78 |
| -- `expression` (string, required): Mathematical expression to evaluate |
79 |
| - |
80 |
| -**Supported Operations:** |
81 |
| - |
82 |
| -- Addition: `+` |
83 |
| -- Subtraction: `-` |
84 |
| -- Multiplication: `*` |
85 |
| -- Division: `/` |
86 |
| -- Parentheses: `()` for grouping |
87 |
| -- Negative numbers: `-5`, `(-3 + 2)` |
| 35 | +### MCP Client Configuration |
| 36 | +For testing with MCP Client: |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "command": "/path/to/mcp-calculator-server", |
| 41 | + "env": { |
| 42 | + "TRANSPORT": "stdio" |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
0 commit comments