MCP Pythonチュートリアル
モックデータを備えたシンプルなローカル DB を使用した Python の MCP チュートリアル アプリ
インストールと実行
Smithery経由でインストール
Smithery経由で Claude Desktop 用の Python MCP チュートリアル サーバーを自動的にインストールするには:
手動インストール
このリポジトリをクローンする
依存関係をインストールします:
MCP サーバーを開発モードで実行します。
MCPサーバーのデフォルトポートは
5173です。httphttp://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- 投稿のフィードバックのための対話型プロンプト
詳細な注釈については、次をお読みください:https://github.com/modelcontextprotocol/python-sdk?tab=readme-ov-file#core-concepts
クライアントに接続中
MCPサーバーをセットアップしたら、MCPサーバーを使用してエージェントを構築するLLMクライアントが必要です。以下のガイドは、 Claude Desktopをクライアントとして接続する方法を説明します。
Claude Desktopは、MCPサーバーの依存関係をインストールするために
uv使用します。まず、uvをインストールします。
uvを使用して MCP サーバーの依存関係をインストールします。
Claude Desktop のダウンロードはこちら:
claude_desktop_config.jsonファイルを見つけるか作成します。場所は OS によって異なります。
ウィンドウズ:
MacOS/Linux:
claude_desktop_config.jsonにmcpServers属性を追加します。
注: 複数のMCPサーバーを導入し、それぞれに専用の関心と専門知識を持たせることもできます。関心を分離することは、すべてを単一のMCPサーバーに実装するよりも効果的です。
Claude Desktop を再起動します。
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
リソース処理、ツール操作、ローカル データベースを備えたシンプルなユーザー/投稿システム用の再利用可能なプロンプトを備えた Python での MCP 実装を示すデモ サーバーです。
Related MCP Servers
- -security-license-qualityThis 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 -
- Asecurity-licenseAqualityA Python-based server that helps users easily install and configure other MCP servers across different platforms.Last updated -23
- Asecurity-licenseAqualityA template repository for creating custom Model Context Protocol (MCP) servers in Python that can be integrated with applications like Claude Desktop or Cursor.Last updated -35MIT License
- -security-license-qualityA minimal Python package for easily setting up and running MCP servers and clients, allowing functions to be automatically exposed as tools that LLMs can use with just 2 lines of code.Last updated -23