Skip to main content
Glama
istabraqruhaili

MCP Calculator Demo

README.md
Day 2
MCP Calculator Demo (FastMCP)
This demo contains a simple MCP server built using FastMCP. It demonstrates how to expose tools to MCP clients such as GitHub Copilot Agent mode using a modern Python setup based on uv.

Prerequisites
Python 3.10 or newer
VS Code
No prior virtual environment setup is required.

Step 1: Install uv
macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

Restart your terminal after installation.

Windows (PowerShell)
irm https://astral.sh/uv/install.ps1 | iex

Verify installation:

uv --version

Step 2: Set Up the Python Environment
Initialize the project environment (only needed once):

uv init

This creates: - pyproject.toml - .python-version - A managed virtual environment

Step 3: Install Dependencies
Install FastMCP and required dependencies:

uv add fastmcp starlette

This will: - Create a virtual environment automatically - Resolve and lock dependencies - Generate uv.lock

Step 4: Activate the Environment (Optional)
You do not need to activate the environment manually when using uv run.

If you want to activate it explicitly:

macOS / Linux
source .venv/bin/activate

Windows (PowerShell)
.venv\\Scripts\\activate

Step 5: Run the MCP Server
Run the demo MCP server:

uv run python servers\01_calculator_stdio.py.py

You should see output indicating that the MCP server is running.

Available Tools
add(a: int, b: int) -> int
subtract(a: int, b: int) -> int
multiply(a: int, b: int) -> int
divide(a: int, b: int) -> Optional[float]
Key Files
01_calculator_stdio.py – MCP server implementation
pyproject.toml – Project configuration and dependencies
uv.lock – Locked dependency versions
.python-version – Python runtime version
Workshop Notes
Do not use pip install
Do not create virtual environments manually
Always use uv add and uv run
This ensures consistent behavior across machines, CI pipelines, and cloud deployments.

MCP Inspector
The MCP Inspector is a local web-based tool used to inspect MCP servers, discover tools, send test requests, and view responses.

Install MCP Inspector
The MCP Inspector is distributed as an npm package.

Prerequisites:

Node.js 18 or newer
npm
Run MCP Inspector
Start the MCP Inspector UI:

npx @modelcontextprotocol/inspector
By default, the Inspector runs at:

http://localhost:6274

Connect to the MCP Server (STDIO)
In MCP Inspector:

Transport: stdio
Command: uv
Arguments: run python <full path to your mcp server>.py
Click Connect.

What You Can Do with MCP Inspector
Discover available tools
Inspect tool schemas
Send tool invocation requests
View raw MCP messages
Inspect errors and responses
Workshop Notes
MCP Inspector is intended for local development and debugging
It is not used in production deployments
It helps visualize MCP message flow and tool schemas