StudyBuddy

StudyBuddy

An educational MCP server demonstrating the MCP protocol with simple tools like rolling dice and returning vocabulary words.

Category
访问服务器

README

MCP in 45 Minutes — A Classroom Walkthrough

You've already given the theory. This is the "now let's see it" session. Two files, ~90 lines of Python total, nothing exotic.

Setup (5 min, do this before class starts)

pip install "mcp[cli]==1.29.0"

That's the only dependency. Both files run with plain python3.

The three files

File Role What it plays the part of
study_buddy_server.py MCP server The "tool box" — e.g. a school's database, a weather API, a calculator
simple_client.py MCP client (scripted) The "app" that wants to use those tools — calls are hardcoded so you can read the protocol steps in order
interactive_client.py MCP client (REPL) Same idea, but it asks you which tool to call and for its arguments, live in the terminal

About interactive_client.py

Run it with:

python3 interactive_client.py

It connects to the server, calls list_tools(), and prints whatever tools come back as a numbered menu — nothing is hardcoded, so if a student adds a new tool to study_buddy_server.py, it just shows up next time this runs. Pick a number, and for each argument the tool needs it prompts you for a value (reading the schema FastMCP built from the function's type hints — this is a nice moment to point out that the schema is not hand-written). Type q to quit.

This is the best one to leave running on a projector: it's the closest students will get to "talking to the server" without wiring up a real LLM, and it makes the discovery step (menu built live from list_tools()) visually obvious in a way the scripted client doesn't.

Suggested flow in class

1. Read the server first, run nothing yet (10 min)

Open study_buddy_server.py on the projector. Walk through it top to bottom:

  • mcp = FastMCP("StudyBuddy") — creating the server and naming it.
  • @mcp.tool() — point out this is the entire difference between "a Python function" and "a function an AI can discover and call." Nothing else changes.
  • The docstring under each function ("""Roll a dice...""") is not just a comment — the client/model reads this text to decide when to use the tool. This is worth emphasizing: MCP tool descriptions are part of the protocol, not decoration.
  • mcp.run() at the bottom — starts the server listening for a connection.

Ask students: "If I wanted to add a tool that looks up tomorrow's weather, what three things would I need to write?" (a function, a docstring, the decorator) — this checks they got the pattern.

2. Run the server alone (2 min)

python3 study_buddy_server.py

It will appear to hang / do nothing. That's the point — a server on its own is inert. It's just sitting there waiting for something to talk to it over stdin/stdout. Ctrl+C to stop.

3. Read and run the client (15 min)

Open simple_client.py. This is the file that shows the protocol steps explicitly, because normally an AI app hides them from you:

  1. Launchstdio_client(server_params) starts the server as a subprocess and opens a pipe to it.
  2. Handshakesession.initialize(). Client and server introduce themselves and agree on what they support.
  3. Discoversession.list_tools(). The client asks "what can you do?" and gets back the tool names + docstrings + expected inputs.
  4. Callsession.call_tool("roll_dice", {"sides": 20}). The client asks the server to actually run one specific tool with specific arguments, and gets a result back.

Run it:

python3 simple_client.py

Point out: no AI model was involved anywhere in this script. We (the humans) hardcoded which tool to call. That's deliberate — it isolates "what MCP does" from "what an LLM adds on top," which is normally where the confusion is. The LLM's job in a real app is just step 4: deciding which tool to call and what arguments to pass, based on the tool descriptions from step 3 and the user's message.

4. Live-code a new tool together (10 min)

Add a fourth tool to study_buddy_server.py as a class, e.g.:

@mcp.tool()
def word_of_the_day() -> str:
    """Return a random vocabulary word with its definition."""
    words = {
        "ephemeral": "lasting for a very short time",
        "resilient": "able to recover quickly from difficulty",
        "lucid": "clear and easy to understand",
    }
    word, definition = random.choice(list(words.items()))
    return f"{word}: {definition}"

Then add one line to simple_client.py to call it, and re-run. This is the moment that usually makes it click: adding a capability took one decorator and zero protocol code.

5. Bonus, if time allows: connect it to Claude Desktop

If any students have Claude Desktop installed, show them that the same study_buddy_server.py file can be registered in Claude Desktop's config (claude_desktop_config.json) instead of simple_client.py, and then Claude itself — not a hardcoded script — decides when to roll a dice or quiz them, based on what they type in chat. This is the "aha": the server code never changes, only who's driving the client side.

Key takeaway to write on the board

MCP doesn't make the AI smarter. It gives the AI a standard way to discover and call tools it doesn't know about in advance — so anyone can plug new capabilities into any AI app without custom integration code.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选