cthuaung/mcp-server
If you are the rightful owner of mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This repository contains a simple MCP (Model Context Protocol) server built with FastMCP, providing various mathematical operations as tools.
MCP Server Tutorial
This repository contains a simple MCP (Model Context Protocol) server built with FastMCP. The server provides various mathematical operations as tools that can be used through the MCP protocol.
Features
- Basic arithmetic operations (addition, subtraction, multiplication, division)
- Advanced mathematical functions:
- Power
- Square root
- Cube root
- Factorial
- Logarithm
- Trigonometric functions (sin, cos, tan)
- Remainder
- Dynamic greeting resource
Prerequisites
- Python 3.8 or higher
- FastMCP library
Installation
- Clone this repository
- Create and activate a virtual environment:
uv venv source venv/bin/activate # On Windows: venv\Scripts\activate - Install dependencies:
uv install fastmcp
Usage
Running the Server
Run the server using:
python main.py
The server uses SSE (Server-Sent Events) transport by default, which allows you to connect using MCP Inspector.
Connecting with MCP Inspector
- Open MCP Inspector
npx @modelcontextprotocol/inspector
- Choose SSE Transport Type
- Connect to the server URL (typically http://localhost:8000/sse)
- You can now interact with the mathematical tools and resources defined in the server
Available Tools
add(a, b): Adds two numberssubtract(a, b): Subtracts two numbersmultiply(a, b): Multiplies two numbersdivide(a, b): Divides two numberspower(a, b): Calculates a raised to the power of bsqrt(a): Calculates the square root of a numbercbrt(a): Calculates the cube root of a numberfactorial(a): Calculates the factorial of a numberlog(a): Calculates the natural logarithm of a numberremainder(a, b): Calculates the remainder when a is divided by bsin(a): Calculates the sine of a numbercos(a): Calculates the cosine of a numbertan(a): Calculates the tangent of a number
Available Resources
greeting://{name}: Returns a personalized greeting for the given name
Modifying the Server
You can add more tools and resources by following the pattern in main.py:
- To add a new tool, use the
@mcp.tool()decorator - To add a new resource, use the
@mcp.resource()decorator
Transport Options
FastMCP supports two transport protocols:
stdio: Standard input/output (terminal-based)sse: Server-Sent Events (browser-based, compatible with MCP Inspector)
To change the transport protocol, modify the transport parameter in the mcp.run() call.