MCP Learning Project
A custom MCP server providing tools for date/time, calculations, mock weather, and note management, enabling AI agents to perform these tasks via natural language.
README
MCP Learning Project
A hands-on project to learn Model Context Protocol (MCP) by building a custom MCP server, an AI agent, and a full-stack web application with semantic document search.
What is MCP?
Model Context Protocol (MCP) is an open standard that lets AI models (like Claude) call external tools and services in a structured, language-agnostic way. Think of it like USB — any tool built to the MCP standard works with any MCP-compatible AI.
Project Structure
MCP Project/
├── api.py — FastAPI web server (primary entry point)
├── agent.py — CLI agent (original learning version)
├── mcp_server.py — MCP server with 8 tools
├── database.py — SQLite layer (notes + sessions)
├── rag.py — ChromaDB semantic search
├── convert_pdfs.py — Tesseract OCR for scanned PDFs
├── inspect_db.py — Utility to view SQLite contents
├── templates/
│ └── chat.html — Browser chat UI
├── docs/ — Drop your documents here
├── LEARNING_JOURNEY.md — Full phase-by-phase learning record
└── requirements.txt
Architecture
Browser (http://localhost:8000)
│
│ HTTP / Server-Sent Events
▼
api.py (FastAPI)
│
├──► Claude Sonnet 4.6 (Anthropic API)
│ │ tool calls
│ ▼
└──► mcp_server.py (8 MCP Tools)
├──► database.py → SQLite (notes + sessions persist across restarts)
├──► rag.py → ChromaDB (semantic document search)
└──► docs/ → your documents (txt, md, PDF)
All 8 Tools
| Tool | Description |
|---|---|
get_current_datetime |
Current date and time |
calculate |
Safe math expression evaluator |
get_weather |
Mock weather data by city |
manage_notes |
Persistent CRUD notes (SQLite) |
list_docs |
Lists files in docs/ folder |
read_doc |
Reads full content of a document |
index_docs |
Indexes docs into ChromaDB for semantic search |
search_docs |
Semantic search — finds relevant chunks for any query |
Setup
Prerequisites
- Python 3.10+
- An Anthropic API key (console.anthropic.com)
- Tesseract OCR (for scanned PDFs):
github.com/UB-Mannheim/tesseract/wiki
Install dependencies
pip install anthropic[mcp] mcp pymupdf pytesseract pypdf fastapi "uvicorn[standard]" chromadb sentence-transformers
Set your API key (one-time, permanent)
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-...", "User")
Run the web app
$env:ANTHROPIC_API_KEY = [System.Environment]::GetEnvironmentVariable("ANTHROPIC_API_KEY", "User")
python -m uvicorn api:app --reload --port 8000
Open http://localhost:8000 in your browser.
Or run the CLI agent
python agent.py
How to Add a New Tool
Step 1 — Declare the tool in list_tools() inside mcp_server.py:
types.Tool(
name="my_tool",
description="What it does and WHEN Claude should use it.",
inputSchema={"type": "object", "properties": {"param": {"type": "string"}}, "required": ["param"]},
),
Step 2 — Handle it in call_tool() inside mcp_server.py:
if name == "my_tool":
result = do_something(arguments["param"])
return [types.TextContent(type="text", text=result)]
Restart the server — Claude discovers the new tool automatically.
How to Add Documents
- Drop
.txt,.md, or.pdffiles into thedocs/folder - For scanned PDFs: run
python convert_pdfs.pyfirst - Restart the server (auto-indexes on startup) or say "Re-index my documents" in chat
RAG — How Semantic Search Works
Indexing (once):
docs/*.txt → split into ~500 char chunks → embed with all-MiniLM-L6-v2 → store in ChromaDB
Querying (every question):
question → embed → ChromaDB similarity search → top 4 relevant chunks → Claude
This handles documents of any size — only the relevant parts are sent to Claude.
Key Concepts
| Concept | File | Purpose |
|---|---|---|
@app.list_tools() |
mcp_server.py |
Declares tools to any MCP client |
@app.call_tool() |
mcp_server.py |
Executes tools and returns results |
lifespan |
api.py |
Keeps MCP server alive across all HTTP requests |
StreamingResponse |
api.py |
SSE streaming to the browser |
init_db() |
database.py |
Creates SQLite tables on startup |
index_all() |
rag.py |
Chunks + embeds all docs into ChromaDB |
search() |
rag.py |
Semantic similarity search |
async_mcp_tool() |
agent.py / api.py |
Bridges MCP tools to Anthropic SDK |
Dependencies
| Package | Purpose |
|---|---|
anthropic[mcp] |
Anthropic SDK + MCP integration |
mcp |
MCP protocol implementation |
fastapi |
Web framework |
uvicorn[standard] |
ASGI web server |
pypdf |
Text-based PDF extraction |
pymupdf |
PDF → image rendering for OCR |
pytesseract |
Tesseract OCR wrapper |
chromadb |
Vector database |
sentence-transformers |
Local embedding model |
GitHub
github.com/vijayanan6/mcp-project
Next Steps
- Replace mock weather with real OpenWeatherMap API
- Add user authentication (JWT tokens)
- Switch SQLite → PostgreSQL
- Deploy to cloud (Railway / Render)
- Add React frontend
- Connect GitHub MCP server
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。