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
- 投稿のフィードバックのための対話型プロンプト
[!NOTE] 詳細な注釈については、次をお読みください: 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
- AsecurityAlicenseAqualityAn MCP server to run commands.Last updated -2265150TypeScriptMIT License
- -securityAlicense-qualityA 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 -1PythonMIT License
- -securityFlicense-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 -Python
- AsecurityAlicenseAqualityA server that provides a persistent Python REPL environment through the MCP protocol, allowing execution of Python code, variable management, and package installation.Last updated -33PythonMIT License