Fifth Elephant MCP Server

Fifth Elephant MCP Server

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.

Category
访问服务器

README

Fifth Elephant MCP Server: A DIY Guide

This guide provides a complete walkthrough to create and run a simple Model Context Protocol (MCP) server from scratch.

Table of Contents

  1. Prerequisites
  2. Step 1: Project Setup
  3. Step 2: Initialize a Python Project with uv
  4. Step 3: Create and Activate Virtual Environment
  5. Step 4: Sync Dependencies (Not Required)
  6. Step 5: Add MCP Dependency
  7. Step 6: Verify Installation
  8. Step 7: Edit the Server Code
  9. Step 8: Debug Locally with MCP Inspector
  10. Step 9: Configure Claude Desktop
  11. Troubleshooting

Prerequisites

Before we begin, ensure you have the following installed:

1. Install pyenv (if not already 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

2. Install Python 3.11

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

3. Install uv

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

Step 1: Project Setup

First, create a directory for your project and navigate into it.

mkdir fifth-elephant-mcp
cd fifth-elephant-mcp

Step 2: Initialize a Python Project with uv

Initialize a new Python project using uv. This will create a virtual environment and a pyproject.toml file.

uv init --quiet

Step 3: Create and Activate Virtual Environment

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).

Step 4: Sync Dependencies (not required)

Sync the project dependencies to ensure everything is up to date:

uv sync

Step 5: Add MCP Dependency

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.

Step 6: Verify Installation

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__)"    

Step 7: Edit the Server Code

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()

Step 8: Debug Locally with MCP Inspector

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.

Step 9: Configure Claude Desktop

If you haven't already, install Claude Desktop to use your MCP server:

  1. Download Claude Desktop from claude.ai
  2. Install and set up Claude Desktop

To use your MCP server with Claude Desktop, you need to configure it using absolute paths.

Get 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

Configure Claude Desktop

  1. Open Claude Desktop
  2. Go to Settings → Developer → Edit Config
  3. Add your MCP server configuration to the 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:

  • macOS/Linux: Replace /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.
  • Windows: Replace 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:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/claude/claude_desktop_config.json

Troubleshooting

If you encounter issues, try these common solutions:

1. Virtual Environment Issues

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

2. Dependency Issues

Sync your dependencies:

uv sync

3. MCP Inspector Configuration

If you're using the MCP inspector and having issues, use these settings:

  • Command: uv
  • Args: run --with mcp mcp run main.py

Note: The command should be uv, not mcp-server-everything or similar variants.

4. Path Issues

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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选