math-mcp-learning-server 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Hugues Clouâtre
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,224 @@
1
+ Metadata-Version: 2.4
2
+ Name: math-mcp-learning-server
3
+ Version: 0.1.0
4
+ Summary: Educational MCP server demonstrating FastMCP best practices - Complete learning guide with contributing guidelines and roadmap for Model Context Protocol development
5
+ Author-email: Hugues Clouâtre <hugues+mcp@linux.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/huguesclouatre/math-mcp-server
8
+ Project-URL: Repository, https://github.com/huguesclouatre/math-mcp-server
9
+ Project-URL: Issues, https://github.com/huguesclouatre/math-mcp-server/issues
10
+ Project-URL: Documentation, https://github.com/huguesclouatre/math-mcp-server#readme
11
+ Project-URL: Contributing, https://github.com/huguesclouatre/math-mcp-server/blob/main/CONTRIBUTING.md
12
+ Project-URL: Future Improvements, https://github.com/huguesclouatre/math-mcp-server/blob/main/FUTURE_IMPROVEMENTS.md
13
+ Keywords: mcp,math,calculator,learning,fastmcp,tutorial,education
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Education
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Education
19
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
20
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
21
+ Classifier: Topic :: Documentation
22
+ Classifier: Environment :: Console
23
+ Requires-Python: >=3.12
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: mcp>=1.14.1
27
+ Requires-Dist: pydantic>=2.11.9
28
+ Dynamic: license-file
29
+
30
+ # Math MCP Server
31
+
32
+ A simple Model Context Protocol (MCP) server for mathematical operations. This project serves as a learning example demonstrating MCP fundamentals and best practices.
33
+
34
+ ## Features
35
+
36
+ - **Safe Expression Evaluation**: Securely evaluate mathematical expressions with enhanced error handling
37
+ - **Educational Annotations**: Responses include difficulty levels and learning metadata
38
+ - **Statistical Analysis**: Calculate mean, median, mode, standard deviation, and variance
39
+ - **Financial Calculations**: Compound interest calculations with formatted output
40
+ - **Unit Conversions**: Length, weight, and temperature conversions
41
+ - **Security Logging**: Monitor and log potentially dangerous expression attempts
42
+ - **Type Safety**: Full Pydantic validation for inputs and structured content responses
43
+ - **Comprehensive Testing**: 100% test pass rate with security and edge case coverage
44
+
45
+ ## Available Tools
46
+
47
+ ### 1. `calculate`
48
+ Safely evaluate mathematical expressions with support for basic operations and math functions.
49
+
50
+ **Examples:**
51
+ ```
52
+ 2 + 3 * 4 → 14
53
+ sqrt(16) → 4.0
54
+ sin(3.14159/2) → 1.0
55
+ abs(-5) → 5.0
56
+ ```
57
+
58
+ ### 2. `statistics`
59
+ Perform statistical calculations on lists of numbers.
60
+
61
+ **Operations:** `mean`, `median`, `mode`, `std_dev`, `variance`
62
+
63
+ **Example:**
64
+ ```json
65
+ {
66
+ "numbers": [1, 2, 3, 4, 5],
67
+ "operation": "mean"
68
+ }
69
+ ```
70
+
71
+ ### 3. `compound_interest`
72
+ Calculate compound interest for investments.
73
+
74
+ **Example:**
75
+ ```json
76
+ {
77
+ "principal": 1000,
78
+ "rate": 0.05,
79
+ "time": 5,
80
+ "compounds_per_year": 12
81
+ }
82
+ ```
83
+
84
+ ### 4. `convert_units`
85
+ Convert between different units of measurement.
86
+
87
+ **Supported unit types:**
88
+ - **Length**: mm, cm, m, km, in, ft, yd, mi
89
+ - **Weight**: g, kg, oz, lb
90
+ - **Temperature**: c, f, k (Celsius, Fahrenheit, Kelvin)
91
+
92
+ ## Installation
93
+
94
+ ### Prerequisites
95
+ - Python 3.12+
96
+ - [uv](https://docs.astral.sh/uv/) package manager
97
+
98
+ ### Setup
99
+ ```bash
100
+ # Clone the repository
101
+ git clone https://github.com/huguesclouatre/math-mcp-server.git
102
+ cd math-mcp-server
103
+
104
+ # Install dependencies
105
+ uv sync
106
+
107
+ # Run tests
108
+ uv run pytest tests/ -v
109
+
110
+ # Start the MCP server
111
+ uv run math-mcp-server
112
+ ```
113
+
114
+ ## Development
115
+
116
+ ### Project Structure
117
+ ```
118
+ math-mcp-server/
119
+ ├── src/math_mcp/
120
+ │ ├── __init__.py
121
+ │ └── server.py # Main MCP server implementation
122
+ ├── tests/
123
+ │ └── test_math_operations.py
124
+ ├── pyproject.toml # Project configuration
125
+ └── README.md
126
+ ```
127
+
128
+ ### Adding New Tools
129
+
130
+ 1. Define input/output models with Pydantic
131
+ 2. Add `@mcp.tool()` decorated function
132
+ 3. Implement tool logic with proper validation
133
+ 4. Add corresponding tests
134
+
135
+ ### Security Considerations
136
+
137
+ The `calculate` tool uses restricted `eval()` with:
138
+ - Whitelist of allowed characters and functions
139
+ - Restricted global scope (only `math` module and `abs`)
140
+ - No access to dangerous built-ins or imports
141
+
142
+ ## Usage with Claude Desktop
143
+
144
+ Add to your Claude Desktop configuration:
145
+
146
+ ```json
147
+ {
148
+ "mcpServers": {
149
+ "math": {
150
+ "command": "uv",
151
+ "args": ["run", "math-mcp-server"],
152
+ "cwd": "/path/to/math-mcp-server"
153
+ }
154
+ }
155
+ }
156
+ ```
157
+
158
+ ## Example Interactions
159
+
160
+ ### Basic Calculation
161
+ ```
162
+ User: Calculate 15% tip on $84.50
163
+ Assistant: [uses calculate tool with "84.50 * 0.15"]
164
+ Result: 12.675
165
+ ```
166
+
167
+ ### Statistical Analysis
168
+ ```
169
+ User: What's the average of these test scores: 85, 92, 78, 96, 88?
170
+ Assistant: [uses statistics tool with numbers=[85,92,78,96,88], operation="mean"]
171
+ Mean: 87.8
172
+ ```
173
+
174
+ ### Investment Planning
175
+ ```
176
+ User: If I invest $5000 at 4.5% annually, compounded monthly, what will it be worth in 10 years?
177
+ Assistant: [uses compound_interest tool]
178
+ Principal: $5000.00
179
+ Final Amount: $7814.17
180
+ Total Interest: $2814.17
181
+ ```
182
+
183
+ ## Learning Objectives
184
+
185
+ This project demonstrates:
186
+ - MCP protocol implementation with Python
187
+ - Safe code execution patterns
188
+ - Input validation with Pydantic
189
+ - Comprehensive error handling
190
+ - Testing strategies for MCP servers
191
+ - Professional Python project structure
192
+
193
+ ## Contributing
194
+
195
+ We welcome contributions! This project follows a **fast & minimal** philosophy while maintaining educational value and professional standards.
196
+
197
+ **Quick Start for Contributors:**
198
+ 1. Fork the repository
199
+ 2. Set up development environment: `uv sync`
200
+ 3. Create feature branch: `git checkout -b feature/your-feature`
201
+ 4. Make changes and add tests
202
+ 5. Run quality checks: `uv run pytest && uv run mypy src/ && uv run ruff check`
203
+ 6. Submit a pull request
204
+
205
+ **📋 For detailed guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md)**
206
+
207
+ Includes:
208
+ - Development workflow and Git practices
209
+ - Code standards and security requirements
210
+ - Testing procedures and quality assurance
211
+ - Architecture guidelines and best practices
212
+
213
+ ## License
214
+
215
+ MIT License - see LICENSE file for details
216
+
217
+ ## Next Steps
218
+
219
+ This basic math MCP can be extended with:
220
+ - Matrix operations
221
+ - Graphing capabilities
222
+ - Advanced statistical functions
223
+ - Financial modeling tools
224
+ - Integration with external APIs
@@ -0,0 +1,195 @@
1
+ # Math MCP Server
2
+
3
+ A simple Model Context Protocol (MCP) server for mathematical operations. This project serves as a learning example demonstrating MCP fundamentals and best practices.
4
+
5
+ ## Features
6
+
7
+ - **Safe Expression Evaluation**: Securely evaluate mathematical expressions with enhanced error handling
8
+ - **Educational Annotations**: Responses include difficulty levels and learning metadata
9
+ - **Statistical Analysis**: Calculate mean, median, mode, standard deviation, and variance
10
+ - **Financial Calculations**: Compound interest calculations with formatted output
11
+ - **Unit Conversions**: Length, weight, and temperature conversions
12
+ - **Security Logging**: Monitor and log potentially dangerous expression attempts
13
+ - **Type Safety**: Full Pydantic validation for inputs and structured content responses
14
+ - **Comprehensive Testing**: 100% test pass rate with security and edge case coverage
15
+
16
+ ## Available Tools
17
+
18
+ ### 1. `calculate`
19
+ Safely evaluate mathematical expressions with support for basic operations and math functions.
20
+
21
+ **Examples:**
22
+ ```
23
+ 2 + 3 * 4 → 14
24
+ sqrt(16) → 4.0
25
+ sin(3.14159/2) → 1.0
26
+ abs(-5) → 5.0
27
+ ```
28
+
29
+ ### 2. `statistics`
30
+ Perform statistical calculations on lists of numbers.
31
+
32
+ **Operations:** `mean`, `median`, `mode`, `std_dev`, `variance`
33
+
34
+ **Example:**
35
+ ```json
36
+ {
37
+ "numbers": [1, 2, 3, 4, 5],
38
+ "operation": "mean"
39
+ }
40
+ ```
41
+
42
+ ### 3. `compound_interest`
43
+ Calculate compound interest for investments.
44
+
45
+ **Example:**
46
+ ```json
47
+ {
48
+ "principal": 1000,
49
+ "rate": 0.05,
50
+ "time": 5,
51
+ "compounds_per_year": 12
52
+ }
53
+ ```
54
+
55
+ ### 4. `convert_units`
56
+ Convert between different units of measurement.
57
+
58
+ **Supported unit types:**
59
+ - **Length**: mm, cm, m, km, in, ft, yd, mi
60
+ - **Weight**: g, kg, oz, lb
61
+ - **Temperature**: c, f, k (Celsius, Fahrenheit, Kelvin)
62
+
63
+ ## Installation
64
+
65
+ ### Prerequisites
66
+ - Python 3.12+
67
+ - [uv](https://docs.astral.sh/uv/) package manager
68
+
69
+ ### Setup
70
+ ```bash
71
+ # Clone the repository
72
+ git clone https://github.com/huguesclouatre/math-mcp-server.git
73
+ cd math-mcp-server
74
+
75
+ # Install dependencies
76
+ uv sync
77
+
78
+ # Run tests
79
+ uv run pytest tests/ -v
80
+
81
+ # Start the MCP server
82
+ uv run math-mcp-server
83
+ ```
84
+
85
+ ## Development
86
+
87
+ ### Project Structure
88
+ ```
89
+ math-mcp-server/
90
+ ├── src/math_mcp/
91
+ │ ├── __init__.py
92
+ │ └── server.py # Main MCP server implementation
93
+ ├── tests/
94
+ │ └── test_math_operations.py
95
+ ├── pyproject.toml # Project configuration
96
+ └── README.md
97
+ ```
98
+
99
+ ### Adding New Tools
100
+
101
+ 1. Define input/output models with Pydantic
102
+ 2. Add `@mcp.tool()` decorated function
103
+ 3. Implement tool logic with proper validation
104
+ 4. Add corresponding tests
105
+
106
+ ### Security Considerations
107
+
108
+ The `calculate` tool uses restricted `eval()` with:
109
+ - Whitelist of allowed characters and functions
110
+ - Restricted global scope (only `math` module and `abs`)
111
+ - No access to dangerous built-ins or imports
112
+
113
+ ## Usage with Claude Desktop
114
+
115
+ Add to your Claude Desktop configuration:
116
+
117
+ ```json
118
+ {
119
+ "mcpServers": {
120
+ "math": {
121
+ "command": "uv",
122
+ "args": ["run", "math-mcp-server"],
123
+ "cwd": "/path/to/math-mcp-server"
124
+ }
125
+ }
126
+ }
127
+ ```
128
+
129
+ ## Example Interactions
130
+
131
+ ### Basic Calculation
132
+ ```
133
+ User: Calculate 15% tip on $84.50
134
+ Assistant: [uses calculate tool with "84.50 * 0.15"]
135
+ Result: 12.675
136
+ ```
137
+
138
+ ### Statistical Analysis
139
+ ```
140
+ User: What's the average of these test scores: 85, 92, 78, 96, 88?
141
+ Assistant: [uses statistics tool with numbers=[85,92,78,96,88], operation="mean"]
142
+ Mean: 87.8
143
+ ```
144
+
145
+ ### Investment Planning
146
+ ```
147
+ User: If I invest $5000 at 4.5% annually, compounded monthly, what will it be worth in 10 years?
148
+ Assistant: [uses compound_interest tool]
149
+ Principal: $5000.00
150
+ Final Amount: $7814.17
151
+ Total Interest: $2814.17
152
+ ```
153
+
154
+ ## Learning Objectives
155
+
156
+ This project demonstrates:
157
+ - MCP protocol implementation with Python
158
+ - Safe code execution patterns
159
+ - Input validation with Pydantic
160
+ - Comprehensive error handling
161
+ - Testing strategies for MCP servers
162
+ - Professional Python project structure
163
+
164
+ ## Contributing
165
+
166
+ We welcome contributions! This project follows a **fast & minimal** philosophy while maintaining educational value and professional standards.
167
+
168
+ **Quick Start for Contributors:**
169
+ 1. Fork the repository
170
+ 2. Set up development environment: `uv sync`
171
+ 3. Create feature branch: `git checkout -b feature/your-feature`
172
+ 4. Make changes and add tests
173
+ 5. Run quality checks: `uv run pytest && uv run mypy src/ && uv run ruff check`
174
+ 6. Submit a pull request
175
+
176
+ **📋 For detailed guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md)**
177
+
178
+ Includes:
179
+ - Development workflow and Git practices
180
+ - Code standards and security requirements
181
+ - Testing procedures and quality assurance
182
+ - Architecture guidelines and best practices
183
+
184
+ ## License
185
+
186
+ MIT License - see LICENSE file for details
187
+
188
+ ## Next Steps
189
+
190
+ This basic math MCP can be extended with:
191
+ - Matrix operations
192
+ - Graphing capabilities
193
+ - Advanced statistical functions
194
+ - Financial modeling tools
195
+ - Integration with external APIs
@@ -0,0 +1,56 @@
1
+ [project]
2
+ name = "math-mcp-learning-server"
3
+ version = "0.1.0"
4
+ description = "Educational MCP server demonstrating FastMCP best practices - Complete learning guide with contributing guidelines and roadmap for Model Context Protocol development"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ license = "MIT"
8
+ authors = [
9
+ {name = "Hugues Clouâtre", email = "hugues+mcp@linux.com"}
10
+ ]
11
+ keywords = ["mcp", "math", "calculator", "learning", "fastmcp", "tutorial", "education"]
12
+ classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ "Intended Audience :: Developers",
15
+ "Intended Audience :: Education",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Topic :: Education",
18
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
19
+ "Topic :: Scientific/Engineering :: Mathematics",
20
+ "Topic :: Documentation",
21
+ "Environment :: Console",
22
+ ]
23
+ dependencies = [
24
+ "mcp>=1.14.1",
25
+ "pydantic>=2.11.9",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/huguesclouatre/math-mcp-server"
30
+ Repository = "https://github.com/huguesclouatre/math-mcp-server"
31
+ Issues = "https://github.com/huguesclouatre/math-mcp-server/issues"
32
+ Documentation = "https://github.com/huguesclouatre/math-mcp-server#readme"
33
+ Contributing = "https://github.com/huguesclouatre/math-mcp-server/blob/main/CONTRIBUTING.md"
34
+ "Future Improvements" = "https://github.com/huguesclouatre/math-mcp-server/blob/main/FUTURE_IMPROVEMENTS.md"
35
+
36
+ [project.scripts]
37
+ math-mcp-learning-server = "math_mcp.server:main"
38
+
39
+ [build-system]
40
+ requires = ["setuptools>=61"]
41
+ build-backend = "setuptools.build_meta"
42
+
43
+ [tool.setuptools.packages.find]
44
+ where = ["src"]
45
+
46
+ [tool.pytest.ini_options]
47
+ pythonpath = ["src"]
48
+
49
+ [dependency-groups]
50
+ dev = [
51
+ "black>=25.9.0",
52
+ "mypy>=1.18.2",
53
+ "pytest>=8.4.2",
54
+ "pytest-asyncio>=1.2.0",
55
+ "ruff>=0.13.1",
56
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ # Math MCP Server - Learning Project