tushargandhi77/Model-Contex-Protocol
If you are the rightful owner of Model-Contex-Protocol and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This is a minimal Example 'Calculator' MCP (Model Context Protocol) server implemented with `fastmcp`.
Model Context Protocol (MCP) Learning Repository
This repository is a hands-on MCP learning workspace built for education and revision.
It contains one working MCP server (Calculator MCP Server) and one starter project (Test Remote Server) that can be expanded into a remote MCP service.
Learning Goals
- Understand how an MCP server is structured in Python.
- Learn how tools are exposed to an MCP client (for example, Codex/Desktop clients).
- Practice extending tool sets from simple math operations to real workflows.
- Use this repo as quick revision material before interviews, demos, or project work.
Repository Structure
Model-Contex-Protocol/
|-- README.md # This file (full repo guide)
|-- image.png
|-- Image_main.jpg
|-- Calculator MCP Server/
| |-- main.py # FastMCP server and tool definitions
| |-- pyproject.toml # Project metadata + dependencies
| |-- uv.lock # Resolved dependency lock file
| `-- README.md # Local project README
`-- Test Remote Server/
|-- main.py # Starter script (currently non-MCP)
|-- pyproject.toml # Minimal Python project config
`-- README.md # Remote server notes and expansion plan
What Is MCP (Quick Revision)
Model Context Protocol (MCP) is a standard for connecting AI applications to external capabilities in a structured and safe way.
In practical terms:
- MCP Client: The AI app that wants to use external tools.
- MCP Server: Your application that exposes tools/resources/prompts.
- Transport Layer: How client and server communicate (local stdio or network/remote transport).
- Tool Invocation: The client requests a named tool with arguments; server executes and returns structured results.
Architecture in This Repository
+---------------------------+
| MCP Client (LLM App) |
| e.g., Codex/Desktop |
+-------------+-------------+
|
| MCP request: tool name + arguments
v
+-------------+-------------+
| FastMCP Server |
| Calculator MCP Server |
| (main.py) |
+-------------+-------------+
|
| Python function execution
v
+-------------+-------------+
| Tools |
| - roll_dice |
| - add_numbers |
| - subtract_numbers |
| - multiply_numbers |
| - divide_numbers |
| - modulus_numbers |
+---------------------------+
Current Implementation Summary
1) Calculator MCP Server (Calculator MCP Server/main.py)
This is the main MCP implementation.
- Creates a
FastMCPserver instance namedDEMO Server. - Registers tools using
@mcp.tool. - Exposes arithmetic operations and a random dice tool.
- Starts server with
mcp.run()in the main entrypoint.
Available tools:
roll_dice(n_dice: int = 1) -> list[int]add_numbers(a: float, b: float) -> floatsubtract_numbers(a: float, b: float) -> floatmultiply_numbers(a: float, b: float) -> floatdivide_numbers(a: float, b: float) -> float(raisesValueErrorfor divide-by-zero)modulus_numbers(a: int, b: int) -> int
2) Test Remote Server (Test Remote Server/main.py)
This is currently a starter script and prints:
Hello from test-remote-server!
It is a good place to build your remote MCP experiments without affecting the calculator example.
Setup and Run
Python requirement for both projects: >=3.11
Option A: Run Calculator MCP Server
cd "Calculator MCP Server"
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install fastmcp
python main.py
Option B: Run Starter Remote Server
cd "Test Remote Server"
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python main.py
MCP Use Cases (Relevant to This Repo)
Use this calculator server pattern as a template for:
- Data preprocessing tools for ML workflows.
- Statistical utility tools (mean/std/normalization checks).
- Feature engineering helpers exposed as MCP tools.
- Internal operations assistant (validated business calculations).
- Educational sandboxes to teach AI tool-calling.
Concepts to Revise from This Codebase
- Tool registration via decorators (
@mcp.tool). - Typed signatures and automatic schema generation.
- Deterministic tools (
add_numbers) vs non-deterministic tools (roll_dice). - Error handling and tool safety (
divide_numbers). - Separation of concern: MCP wiring vs business logic.
- Local-first development before remote deployment.
Suggested Next Improvements
- Add input validation for all math tools (ranges, type guards).
- Add unit tests for each tool function.
- Add logging and structured error responses.
- Convert
Test Remote Serverinto a real remote MCP server. - Add resources/prompts support (not only tools) for broader MCP learning.
Example Extension Path (Remote MCP)
To convert Test Remote Server into a remote MCP service:
- Initialize a
FastMCPinstance. - Define at least one
@mcp.toolfunction. - Configure run mode for remote transport.
- Add auth, request limits, and logging.
- Test using an MCP-capable client.
Troubleshooting Notes
ModuleNotFoundError: fastmcp: install dependency in active virtual environment.- Wrong Python version: confirm
python --versionis 3.11+. - Tool errors: check function signatures and edge cases (for example divide by zero).
Revision Checklist
Use this before interviews or practical sessions:
- Explain MCP client-server flow in 30 seconds.
- Describe how
@mcp.toolexposes Python functions. - Discuss one safety concern and one mitigation.
- Extend one tool and test it locally.
- Explain how local MCP differs from remote MCP deployment.
If you want, the next step can be adding a production-style remote MCP server in Test Remote Server with authentication, logging, and a few ML-oriented tools.