loading…
Search for a command to run...
loading…
A demonstration MCP server providing basic tools for returning greetings and performing mathematical addition. It serves as a practical workshop guide for setti
A demonstration MCP server providing basic tools for returning greetings and performing mathematical addition. It serves as a practical workshop guide for setting up and configuring Model Context Protocol servers from scratch using Python.
This guide provides a complete walkthrough to create and run a simple Model Context Protocol (MCP) server from scratch.
Before we begin, ensure you have the following installed:
pyenv allows you to manage multiple Python versions easily.
macOS:
brew install pyenv
Linux:
curl https://pyenv.run | bash
Windows:
# Install pyenv-win using PowerShell
Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
Add pyenv to your shell profile:
macOS/Linux (zsh):
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
Windows:
# Restart your PowerShell or Command Prompt after installation
# pyenv-win will be automatically added to your PATH
Install and set Python 3.11 as your local version:
pyenv install 3.11.9
pyenv local 3.11.9
Verify the Python version:
python --version
# Should output: Python 3.11.9
Install uv for fast Python package management:
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
Verify uv installation:
uv --version
First, create a directory for your project and navigate into it.
mkdir fifth-elephant-mcp
cd fifth-elephant-mcp
uvInitialize a new Python project using uv. This will create a virtual environment and a pyproject.toml file.
uv init --quiet
Create a virtual environment using Python 3.11:
uv venv --python 3.11.9
Activate the virtual environment:
macOS/Linux:
source .venv/bin/activate
Windows (Command Prompt):
.venv\Scripts\activate.bat
Verify you're in the virtual environment (you should see (.venv) in your terminal prompt).
Sync the project dependencies to ensure everything is up to date:
uv sync
Add the mcp library with CLI extras to your project's dependencies.
uv add "mcp[cli]"
Note: When installing MCP CLI, it may ask you to install additional dependencies. Press y to confirm.
Verify that all components are properly installed:
# Verify Python version
python --version
# Should output: Python 3.11.9
# Verify uv version
uv --version
# Verify MCP library is installed (should be version 1.11 or later)
python -c "from mcp.server.fastmcp import __version__; print(__version__)"
When you ran uv init, a main.py file was already created. Edit this file and replace its contents with the following code. This code sets up a FastMCP server with two tools: hello_world and add.
from mcp.server.fastmcp import FastMCP
# Create an MCP server
mcp = FastMCP("Fifth Elephant")
# Add a hello world tool
@mcp.tool()
def hello_world() -> str:
"""Returns a friendly greeting."""
return "hello world"
# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
"""Adds two numbers together."""
return a + b
if __name__ == "__main__":
mcp.run()
For development and testing, you can use the MCP inspector.
Run the following command -
uv run mcp dev main.py
This will spin up the inspector. It will open in your browser. Press connect on the left sidebar.
If you haven't already, install Claude Desktop to use your MCP server:
To use your MCP server with Claude Desktop, you need to configure it using absolute paths.
First, get the absolute paths for your virtual environment's Python and your main.py file:
# Get the absolute path to your virtual environment's Python
which python
# Get the absolute path to your main.py file
pwd
Windows (Command Prompt):
# Get the absolute path to your virtual environment's Python
where python
# Get the absolute path to your main.py file
cd
config.json file:macOS/Linux:
{
"mcpServers": {
"fifth-elephant": {
"command": "/absolute/path/to/your/.venv/bin/python",
"args": ["/absolute/path/to/your/main.py"]
}
}
}
Windows:
{
"mcpServers": {
"fifth-elephant": {
"command": "C:\\absolute\\path\\to\\your\\.venv\\Scripts\\python.exe",
"args": ["C:\\absolute\\path\\to\\your\\main.py"]
}
}
}
Important:
/absolute/path/to/your/.venv/bin/python and /absolute/path/to/your/main.py with the actual absolute paths you obtained from the which python and pwd commands.C:\\absolute\\path\\to\\your\\.venv\\Scripts\\python.exe and C:\\absolute\\path\\to\\your\\main.py with the actual absolute paths you obtained from the where python and cd/Get-Location commands. Note the double backslashes (\\) in Windows paths.Config file locations:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/claude/claude_desktop_config.jsonIf you encounter issues, try these common solutions:
Make sure your virtual environment is activated:
macOS/Linux:
# Activate the virtual environment
source .venv/bin/activate
# Verify you're in the virtual environment
which python
# Should show: /path/to/your/project/.venv/bin/python
Windows (Command Prompt):
# Activate the virtual environment
.venv\Scripts\activate.bat
# Verify you're in the virtual environment
where python
# Should show: C:\path\to\your\project\.venv\Scripts\python.exe
Sync your dependencies:
uv sync
If you're using the MCP inspector and having issues, use these settings:
uvrun --with mcp mcp run main.pyNote: The command should be uv, not mcp-server-everything or similar variants.
Ensure you're using absolute paths in your Claude Desktop configuration. Use:
macOS/Linux:
# Get absolute path to Python in your virtual environment
which python
# Get absolute path to your project directory
pwd
Windows (Command Prompt):
# Get absolute path to Python in your virtual environment
where python
# Get absolute path to your project directory
cd
Then update your config.json with the complete absolute paths. Remember to use double backslashes (\\) for Windows paths in JSON.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"fifth-elephant-mcp-server": {
"command": "npx",
"args": []
}
}
}