MCP Python Tutorial
MCP Python 教程
使用 Python 编写的 MCP 教程应用程序,带有简单的本地数据库和模拟数据
安装和运行
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 Python MCP 教程服务器:
npx -y @smithery/cli install @jhj0517/mcp-python-tutorial --client claude手动安装
克隆此存储库
安装依赖项:
pip install -r requirements.txt以开发模式运行 MCP 服务器:
mcp dev localdb_app.pyMCP 服务器默认端口为
5173。访问http://localhost:5173。
Related MCP server: xmcp Demo Application
MCP 功能
本教程演示了 MCP 的核心概念。你可以在tutorial_app/mcp_server.py中查看每个角色的注解:
@mcp.resource
基本上,这个注释是关于代理“获取”资源,就像 RESTAPI 中的GET一样。
users://all- 获取所有用户users://{user_id}/profile- 获取用户的个人资料posts://all- 获取所有帖子posts://{post_id}- 通过 ID 获取帖子
@mcp.tool
这是关于代理“生成”新资源,就像 RESTAPI 中的POST一样。
create_user创建新用户create_post创建新帖子search_posts- 按标题或内容搜索帖子
@mcp.prompt
这只是一个可重复使用的模板,以便于与 LLM 方便地交互。
user_profile_analysis- 生成用户个人资料的分析post_feedback- 帖子反馈的交互式提示
[!NOTE] 有关更多注释,请阅读: https://github.com/modelcontextprotocol/python-sdk? tab=readme-ov-file#core-concepts
连接到客户端
设置好 MCP 服务器后,您需要一个 LLM 客户端,该客户端将使用 MCP 服务器来构建代理。以下指南将帮助您使用Claude Desktop作为客户端进行连接。
Claude Desktop 使用
uv安装 MCP 服务器依赖项。首先,安装uv:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"使用
uv安装 MCP 服务器依赖项:
# Create virtual environment and activate it
uv venv
.venv\Scripts\activate
uv pip install -r requirements.txt下载 Claude Desktop 请访问:
找到或创建
claude_desktop_config.json文件。具体位置因操作系统而异:
视窗:
C:\Users\%USER%\AppData\Roaming\Claude\claude_desktop_config.jsonMacOS/Linux:
~/Library/Application\ Support/Claude/claude_desktop_config.json将
mcpServers属性添加到您的claude_desktop_config.json中:
{
"mcpServers": {
"local_db": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather",
"run",
"localdb_app.py"
]
}
}
}注意:您可以部署多个 MCP 服务器,每个服务器都有各自的关注点和专长。这种关注点分离比将所有功能都集成到单个 MCP 服务器中效果更好。
重新启动 Claude Desktop。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
An MCP server that provides an API to LLMs to manage their JumpCloud resources.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA minimal demonstration server showcasing MCP protocol capabilities including tools, resources, and prompts with basic examples like hello world functionality.2MIT
- FlicenseNot gradedqualityDmaintenanceA demonstration MCP server showcasing the xmcp framework's structured approach to defining tools, prompts, and resources with automatic discovery from their respective directories.-
- FlicenseNot gradedqualityDmaintenanceA Python-based MCP server demonstrating tools for math calculations, time retrieval, and echo messages, along with resources and prompt templates.-
- FlicenseCqualityCmaintenanceA simple MCP server demonstrating resources, tools, and prompts using a local task list. It enables reading, creating, and analyzing tasks through MCP.1-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/jhj0517/mcp-python-tutorial'
If you have feedback or need assistance with the MCP directory API, please join our Discord server