MCP Server Tutorial
cthuaung
README
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.
Recommended Servers
mixpanel
Connect to your Mixpanel data. Query events, retention, and funnel data from Mixpanel analytics.
Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.
Crypto Price & Market Analysis MCP Server
A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.
MCP PubMed Search
Server to search PubMed (PubMed is a free, online database that allows users to search for biomedical and life sciences literature). I have created on a day MCP came out but was on vacation, I saw someone post similar server in your DB, but figured to post mine.
dbt Semantic Layer MCP Server
A server that enables querying the dbt Semantic Layer through natural language conversations with Claude Desktop and other AI assistants, allowing users to discover metrics, create queries, analyze data, and visualize results.
Vectorize
Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.
Nefino MCP Server
Provides large language models with access to news and information about renewable energy projects in Germany, allowing filtering by location, topic (solar, wind, hydrogen), and date range.
MATLAB MCP Server
Integrates MATLAB with AI to execute code, generate scripts from natural language, and access MATLAB documentation seamlessly.
Macrostrat MCP Server
Enables Claude to query comprehensive geologic data from the Macrostrat API, including geologic units, columns, minerals, and timescales through natural language.
MCP Word Counter
A Model Context Protocol server that provides tools for analyzing text documents, including counting words and characters. This server helps LLMs perform text analysis tasks by exposing simple document statistics functionality.