Skip to content

Commit a8f9627

Browse files
committed
feat: add prompt and resource methods
1 parent 2e327f3 commit a8f9627

File tree

5 files changed

+315
-312
lines changed

5 files changed

+315
-312
lines changed

Dockerfile

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1-
FROM golang:1.23-alpine AS builder
2-
1+
FROM golang:1.24-alpine AS builder
32
RUN apk add --no-cache git ca-certificates
4-
53
WORKDIR /app
6-
74
COPY go.mod go.sum ./
85
RUN go mod download
9-
106
COPY . .
117
RUN GOOS=linux go build -o mcp-calculator-server ./server.go
128

139
FROM alpine:3.21
14-
1510
RUN apk --no-cache add ca-certificates wget
16-
17-
RUN addgroup -g 1001 -S mcp && \
18-
adduser -S -D -H -u 1001 -s /sbin/nologin -G mcp mcp
19-
2011
WORKDIR /app
21-
2212
COPY --from=builder /app/mcp-calculator-server .
23-
24-
RUN chown mcp:mcp mcp-calculator-server
25-
26-
USER mcp
27-
2813
EXPOSE 8080
29-
30-
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
31-
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
32-
3314
CMD ["./mcp-calculator-server"]

README.md

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,45 @@
11
# MCP Calculator Server
22

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.
44

55
## Features
66

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
1310

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
1514

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
1718

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
2722

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)
3526

3627
## Usage
3728

38-
### Local Development (stdio)
29+
```sh
30+
go install github.com/yinebebt/mcp-calculator-server@latest
3931

40-
```bash
4132
TRANSPORT=stdio ./mcp-calculator-server
4233
```
4334

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+
```

go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
module github.com/yinebebt/mcp-calculator-server
22

3-
go 1.23
3+
go 1.24
44

5-
require github.com/mark3labs/mcp-go v0.30.1
5+
require github.com/mark3labs/mcp-go v0.37.0
66

77
require (
8+
github.com/bahlo/generic-list-go v0.2.0 // indirect
9+
github.com/buger/jsonparser v1.1.1 // indirect
810
github.com/google/uuid v1.6.0 // indirect
9-
github.com/spf13/cast v1.7.1 // indirect
11+
github.com/invopop/jsonschema v0.13.0 // indirect
12+
github.com/mailru/easyjson v0.7.7 // indirect
13+
github.com/spf13/cast v1.9.2 // indirect
14+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
1015
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
16+
gopkg.in/yaml.v3 v3.0.1 // indirect
1117
)

go.sum

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
2+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
3+
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
4+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
15
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
26
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
37
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
@@ -6,21 +10,30 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
610
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
711
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
812
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
13+
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
14+
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
15+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
916
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1017
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1118
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1219
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
13-
github.com/mark3labs/mcp-go v0.30.1 h1:3R1BPvNT/rC1iPpLx+EMXFy+gvux/Mz/Nio3c6XEU9E=
14-
github.com/mark3labs/mcp-go v0.30.1/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
20+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
21+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
22+
github.com/mark3labs/mcp-go v0.37.0 h1:BywvZLPRT6Zx6mMG/MJfxLSZQkTGIcJSEGKsvr4DsoQ=
23+
github.com/mark3labs/mcp-go v0.37.0/go.mod h1:T7tUa2jO6MavG+3P25Oy/jR7iCeJPHImCZHRymCn39g=
1524
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1625
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1726
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
1827
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
19-
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
20-
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
28+
github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE=
29+
github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
2130
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
2231
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
32+
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
33+
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
2334
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
2435
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
36+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
37+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2538
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2639
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)