Skip to main content
Glama
jhj0517

MCP Python Tutorial

by jhj0517

MCP Python 教程

铁匠徽章使用 Python 编写的 MCP 教程应用程序,带有简单的本地数据库和模拟数据

安装和运行

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 Python MCP 教程服务器:

npx -y @smithery/cli install @jhj0517/mcp-python-tutorial --client claude

手动安装

  1. 克隆此存储库

  2. 安装依赖项:

pip install -r requirements.txt
  1. 以开发模式运行 MCP 服务器:

mcp dev localdb_app.py
  1. MCP 服务器默认端口为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作为客户端进行连接。

  1. Claude Desktop 使用uv安装 MCP 服务器依赖项。首先,安装uv

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  1. 使用uv安装 MCP 服务器依赖项:

# Create virtual environment and activate it
uv venv
.venv\Scripts\activate

uv pip install -r requirements.txt
  1. 下载 Claude Desktop 请访问:

  1. 找到或创建claude_desktop_config.json文件。具体位置因操作系统而异:

  • 视窗:

C:\Users\%USER%\AppData\Roaming\Claude\claude_desktop_config.json
  • MacOS/Linux:

~/Library/Application\ Support/Claude/claude_desktop_config.json
  1. mcpServers属性添加到您的claude_desktop_config.json中:

{
    "mcpServers": {
        "local_db": {
            "command": "uv",
            "args": [
                "--directory",
                "/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather",
                "run",
                "localdb_app.py"
            ]
        }
    }
}

注意:您可以部署多个 MCP 服务器,每个服务器都有各自的关注点和专长。这种关注点分离比将所有功能都集成到单个 MCP 服务器中效果更好。

  1. 重新启动 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.

Maintenance

ActivityInactive
ResponsivenessNo issues

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

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A minimal demonstration server showcasing MCP protocol capabilities including tools, resources, and prompts with basic examples like hello world functionality.
    2
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A demonstration MCP server showcasing the xmcp framework's structured approach to defining tools, prompts, and resources with automatic discovery from their respective directories.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    A Python-based MCP server demonstrating tools for math calculations, time retrieval, and echo messages, along with resources and prompt templates.
    -

Latest Blog Posts

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