Math MCP Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Math MCP Serveradd these numbers: 15, 27, 8.5, and 3"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Math MCP Server
A Model Context Protocol (MCP) server implementation that provides mathematical operations through a standardized interface. This server exposes add and multiply tools for performing arithmetic operations on lists of numbers.
π Features
Addition Tool: Sum any list of numbers
Multiplication Tool: Multiply any list of numbers
Comprehensive Error Handling: Validates inputs for type safety and edge cases
FastMCP Framework: Built on the efficient FastMCP server framework
Stdio Transport: Uses standard input/output for client-server communication
π Requirements
Python 3.8+
Required packages:
mcp- Model Context Protocol libraryfastmcp- Fast MCP server implementation
π§ Installation
Clone the repository:
git clone https://github.com/y-nihat/mcp.git
cd mcpInstall dependencies:
pip install -r requirements.txtπ Usage
Running the Server
The server runs as a subprocess and communicates via stdio:
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(
command="python",
args=["mcp_math_server.py"],
env=None
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# Call the add tool
result = await session.call_tool("add", {"numbers": [10, 20, 30]})
print(result.content[0].text) # Output: 60.0
# Call the multiply tool
result = await session.call_tool("multiply", {"numbers": [7, 8]})
print(result.content[0].text) # Output: 56.0Available Tools
add(numbers: List[float]) -> float
Sums all numbers in the provided list.
Parameters:
numbers: List of numeric values (int or float)
Returns:
Sum of all numbers as float
Example:
result = await session.call_tool("add", {"numbers": [1, 2, 3, 4, 5]})
# Returns: 15.0multiply(numbers: List[float]) -> float
Multiplies all numbers in the provided list.
Parameters:
numbers: List of numeric values (int or float)
Returns:
Product of all numbers as float
Example:
result = await session.call_tool("multiply", {"numbers": [2, 3, 4]})
# Returns: 24.0π‘οΈ Error Handling
The server includes comprehensive validation for all inputs:
Validation Checks
β Type Validation: Ensures input is a list
β Non-Empty List: Rejects empty lists
β Numeric Values: Validates all elements are int or float
β NaN Detection: Catches Not-a-Number values
β Infinity Detection: Catches infinite values (Β±inf)
Error Types
ValueError - Raised for:
Empty lists
NaN values
Infinite values
TypeError - Raised for:
Non-list inputs
Non-numeric elements in the list
Error Examples
# Empty list
await session.call_tool("add", {"numbers": []})
# Returns error: "Cannot add an empty list of numbers"
# Non-numeric value
await session.call_tool("add", {"numbers": [1, "two", 3]})
# Returns error: "Element at index 1 must be a number, got str: two"
# NaN value
await session.call_tool("add", {"numbers": [1, float('nan'), 3]})
# Returns error: "Element at index 1 is NaN (Not a Number)"
# Infinite value
await session.call_tool("multiply", {"numbers": [5, float('inf')]})
# Returns error: "Element at index 1 is infinite"π§ͺ Testing
The project includes comprehensive test coverage with 20 tests:
12 Functional Tests: Verify correct mathematical operations
8 Error Handling Tests: Validate error detection and reporting
Running Tests
python test_math_mcp_server.pyTest Coverage
Functional Tests:
Basic addition and multiplication
Decimal number operations
Negative number handling
Single number operations
Zero operations
Large number calculations
Sequential operations (chaining)
Error Handling Tests:
Empty list validation
Non-numeric element detection
NaN value detection
Infinity detection (positive and negative)
Mixed invalid values
Type error reporting with index information
π Project Structure
mcp/
βββ mcp_math_server.py # Main MCP server implementation
βββ test_math_mcp_server.py # Comprehensive test suite
βββ README.md # This file
βββ CHANGELOG.md # Version history and changes
βββ .gitignore # Git ignore rulesπ Architecture
The server uses a client-server architecture with stdio transport:
βββββββββββββββ ββββββββββββββββββββ
β Client β β Math MCP Server β
β β β β
β - Session β ββββ stdio ββββββββΊβ - add() β
β - call_toolβ ββββ stdio ββββββββ - multiply() β
β β β β
βββββββββββββββ ββββββββββββββββββββClient spawns server as subprocess
Communication via standard input/output
Client sends tool call requests
Server validates inputs and executes operations
Server returns results or errors
Client processes responses
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Guidelines
Follow PEP 8 style guidelines
Add tests for new features
Update documentation for API changes
Ensure all tests pass before submitting PR
π License
This project is open source and available under the MIT License.
π€ Author
Nihat
Email: nihat@yinovasyon.com
GitHub: @y-nihat
π Acknowledgments
Built with FastMCP framework
Uses Model Context Protocol specification
π Additional Resources
Version: 1.0.0
Last Updated: November 7, 2025
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/y-nihat/mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server