LibraryMCP
A small MCP server modeling a library with tools to search books, borrow books, and manage members, enabling interaction with a library catalog through natural language.
README
Library Server
A small MCP server modeling a library, plus a client that drives it with the OpenAI Agents SDK. Uses uv for environment and dependency management.
Files
app.py— the MCP server (4 tools, 2 resources, 1 prompt)client.py— connects toapp.pyover stdio using an Agents SDK agentpyproject.toml— project + dependency definition (uv reads this)uv.lock— locked dependency versions (commit this alongside pyproject.toml)
1. Install uv (if you don't have it yet)
# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Restart your terminal, then confirm it's on PATH:
uv --version
2. Set up the project in VS Code
Open this folder in VS Code, open a terminal (Ctrl+` / Cmd+`),
and sync dependencies from the lockfile:
uv sync
This creates a .venv in the project folder and installs exactly what's
pinned in uv.lock. Point VS Code at it: Command Palette
(Ctrl+Shift+P) → Python: Select Interpreter → pick the one at
.venv/bin/python (or .venv\Scripts\python.exe on Windows).
You don't need to manually activate the venv for the commands below —
uv run does that for you automatically.
3. Verify the server structure
This is the check the assignment asks for — it should report 4 tools, 1 prompt, 1 resource, 1 template:
uv run fastmcp inspect app.py
Expected output:
Components
Tools: 4
Prompts: 1
Resources: 1
Templates: 1
You can also run the server directly to confirm it starts cleanly
(it just sits there listening on stdio — Ctrl+C to stop):
uv run python app.py
4. Run the client
The client normally needs an LLM provider to decide which tools to invoke. This project defaults to using a local LLM (via Ollama) instead of the remote OpenAI API.
Option A — Use the local LLM (default)
- Ensure an Ollama daemon is running and the model referenced in
client.pyis available (the client expectshttp://localhost:11434/v1andmodel="gemma4:e4b"by default). - Then run:
uv run python client.py
Option B — Use OpenAI instead
- Set your OpenAI API key in the environment:
# macOS / Linux
export OPENAI_API_KEY="sk-..."
- Edit
client.pyto construct an OpenAI-backed model (or replace the local model block) so the client uses your OpenAI credentials, then run:
uv run python client.py
client.py spawns app.py as a subprocess automatically via MCPServerStdio, using uv run python app.py as the launch command — so it always runs inside this project's own uv-managed environment.
What should happen
The agent receives: "Find me books about space, then borrow one for member M001." It should:
- Call
search_books("space")→ finds 2001: A Space Odyssey (the only catalog entry with "space" in the title — matches per the assignment's title/author search spec). - Call
borrow_book("9780451457998", "M001")→ decrements its stock and records the borrow in M001's history. - Print a final natural-language summary confirming both steps.
If you want to see the raw tool-call trace (not just the final answer),
add print(result.new_items) after result = await Runner.run(...) in
client.py, or inspect result.raw_responses.
Adding more dependencies later
Don't pip install directly into the venv — use uv so pyproject.toml
and uv.lock stay in sync:
uv add some-package
Notes on design choices
- All four tools return plain strings for both success and error cases (e.g. no copies left, unknown ISBN) — never exceptions — so a calling LLM always gets something it can read and relay to the user.
search_booksmatches onlytitle/author(per the assignment spec), case-insensitively, substring match.- The dynamic resource (
member://{member_id}/history) returns JSON as a string; FastMCP resource functions need to returnstr/bytes/specific content types, not raw Python lists of dicts. - The mock catalog is 8 well-known sci-fi/fantasy titles; stock levels are
deliberately mixed (some at 0) so you can test both the success and
no-copies-left paths in
borrow_book.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。