Skip to main content
Glama

MCP Python Tutorial

MCP Pythonチュートリアル

モックデータを備えたシンプルなローカル DB を使用した 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 http://localhost:5173にアクセスしてください。

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サーバーをセットアップしたら、MCPサーバーを使用してエージェントを構築するLLMクライアントが必要です。以下のガイドは、 Claude Desktopをクライアントとして接続する方法を説明します。

  1. Claude Desktopは、MCPサーバーの依存関係をインストールするためにuv使用します。まず、 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ファイルを見つけるか作成します。場所は OS によって異なります。
  • ウィンドウズ:
C:\Users\%USER%\AppData\Roaming\Claude\claude_desktop_config.json
  • MacOS/Linux:
~/Library/Application\ Support/Claude/claude_desktop_config.json
  1. claude_desktop_config.jsonmcpServers属性を追加します。
{ "mcpServers": { "local_db": { "command": "uv", "args": [ "--directory", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather", "run", "localdb_app.py" ] } } }

注: 複数のMCPサーバーを導入し、それぞれに専用の関心と専門知識を持たせることもできます。関心を分離することは、すべてを単一のMCPサーバーに実装するよりも効果的です。

  1. Claude Desktop を再起動します。
-
security - not tested
F
license - not found
-
quality - not tested

local-only server

The server can only run on the client's local machine because it depends on local resources.

リソース処理、ツール操作、ローカル データベースを備えたシンプルなユーザー/投稿システム用の再利用可能なプロンプトを備えた Python での MCP 実装を示すデモ サーバーです。

  1. インストールと実行
    1. Smithery経由でインストール
    2. 手動インストール
  2. MCPの機能
    1. @mcp.resource
    2. @mcp.tool
    3. @mcp.prompt
  3. クライアントに接続中

    Related MCP Servers

    • A
      security
      A
      license
      A
      quality
      An MCP server to run commands.
      Last updated -
      2
      265
      150
      TypeScript
      MIT License
      • Apple
    • -
      security
      A
      license
      -
      quality
      A Python-based server that implements the Model Context Protocol to interface with Claude Desktop as an MCP client, supporting interaction through efficient memory management.
      Last updated -
      1
      Python
      MIT License
    • -
      security
      F
      license
      -
      quality
      This is an MCP server that facilitates building tools for interacting with various APIs and workflows, supporting Python-based development with potential for customizable prompts and user configurations.
      Last updated -
      Python
    • A
      security
      A
      license
      A
      quality
      A server that provides a persistent Python REPL environment through the MCP protocol, allowing execution of Python code, variable management, and package installation.
      Last updated -
      3
      3
      Python
      MIT License

    View all related MCP servers

    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