CREATE TABLE students (
student_id TEXT PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
interests TEXT,
home_location TEXT,
grade TEXT
);
CREATE TABLE courses (
course_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE NOT NULL,
domain TEXT NOT NULL,
term_years REAL NOT NULL
);
CREATE TABLE student_courses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_name TEXT NOT NULL,
course_name TEXT NOT NULL,
enrollment_start TEXT NOT NULL,
enrollment_end TEXT,
course_completed INTEGER NOT NULL DEFAULT 0,
UNIQUE(student_name, course_name) -- prevents duplicate enrollment
);
POST /mcp initialize → server creates session
← mcp-session-id: abc123 (capture this!)
POST /mcp notifications/initialized
mcp-session-id: abc123 → session validated ✅
POST /mcp tools/call ...
mcp-session-id: abc123 → session validated ✅
7.命令参考
MCP检查器命令
命令
它做什么
mcp dev server.py
启动检查器UI(端口6274)+代理+服务器.py
mcp --version
检查已安装的MCP CLI版本
pip install "mcp[cli]"
使用检查器安装MCP CLI
pip install --upgrade mcp
升级至最新MCP版本
pip show mcp
显示安装版本和详细信息
端口管理(macOS/Linux)
# Kill a specific port
lsof -ti:6274 | xargs kill -9
lsof -ti:6277 | xargs kill -9
lsof -ti:8000 | xargs kill -9
# Kill all MCP ports at once
lsof -ti:6274,6277,3000,8000 | xargs kill -9
# Check if port is free (no output = free)
lsof -i:8000
端口管理(Windows PowerShell)
# Find process on port
netstat -ano | findstr :8000
# Kill by PID
taskkill /PID <PID_NUMBER> /F
# Initialize — use -v to see mcp-session-id in response headers
curl -v -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl-test","version":"1.0"}}}'
# All subsequent calls — include session ID
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "mcp-session-id: <SESSION_ID>" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'
Python自检命令
# Check what your MCP version accepts in run()
python -c "from mcp.server.fastmcp import FastMCP; help(FastMCP.run)"
# Check FastMCP constructor parameters
python -c "from mcp.server.fastmcp import FastMCP; help(FastMCP.__init__)"
# Get MCP version
python -c "import mcp; print(mcp.__version__)"
# Get absolute paths for config files
which python # macOS/Linux
where python # Windows
realpath server.py # macOS/Linux
echo %cd%\server.py # Windows
# Collapse multi-line JSON to single line
echo '{...}' | jq -c .
echo '{...}' | python -m json.tool
# Pretty print compressed JSON response
echo '{...}' | python -m json.tool
8.MCP检查员指南
键入时运行什么 mcp dev server.py
mcp dev server.py
│
├──► Process 1: Inspector UI → port 6274 (React web app)
├──► Process 2: Proxy Server → port 6277 (HTTP ↔ stdio bridge)
└──► Process 3: server.py → stdin/stdout (spawned on Connect click)
"Get me the details for student STU001"
"Find all students from London"
"Add a new student named Marco Rossi, email marco@example.com, ID STU011, grade B+"
"What courses are available?"
"Show me all science courses"
"Enroll Alice Chen in Data Structures starting 2025-09-01"
"Find all technology courses then enroll Alice in Data Structures"
验证连接
Ctrl+Shift+P → MCP: List Servers # should show: student-records Running
View → Output → MCP: student-records # raw JSON-RPC logs
Ctrl+Shift+P → MCP: Restart Server # if stuck
10.错误参考
连接错误
错误
根本原因
解决方案
Connection Error — proxy token incorrect
跑步 server.py 分开之前 mcp dev,或缺少URL ?token=
停下 server.py.仅运行: mcp dev server.py.从终端复制包括令牌在内的完整URL