py-mcp-server-テンプレート
このリポジトリは、Pythonで独自のMCP(モデルコンテキストプロトコル)サーバーを作成するのに役立つテンプレートです。始めるには、このリポジトリをフォークしてください。
UVを使ったセットアップ
このプロジェクトでは、Pythonのパッケージングと仮想環境の管理にuvを使用しています。UV uvインストールされていない場合は、公式のUVインストールガイドを参照してください。
フォークしたリポジトリをクローンします。
git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git cd YOUR_REPOSITORY_NAME**仮想環境を作成してアクティブ化します。**通常、
uvプロジェクト ルートに.venvディレクトリを作成します。uv venv source .venv/bin/activate # On macOS/Linux # .venv\Scripts\activate # On Windows**依存関係のインストール:**このプロジェクトは、依存関係を管理するために
pyproject.tomlを使用します。uv pip install .新しい依存関係を追加する場合は、
pyproject.tomlファイルで定義し、このコマンドを再度実行してください。何らかの理由でrequirements.txtファイルを使用している場合は、uv pip install -r requirements.txtでインストールできます。
サーバーの実行
mcp_server.pyスクリプトは MCP サーバーを起動します。
サーバーを直接実行するには:
Claude DesktopまたはCursorとの統合
このMCPサーバーをClaude DesktopやCursorなどのアプリケーションで使用するには、アプリケーションの設定で設定する必要があります。設定には通常、サーバーを実行するコマンドの指定が含まれます。
設定例を以下に示します。/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME /ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAMEシステム上のプロジェクトディレクトリへの実際の絶対パスに置き換える必要があります。
構成の説明:
"my-custom-python-server": これはサーバー構成に付ける名前です。"command": "uv": 実行するコマンドとしてuvを指定します。"args":uvコマンドの引数のリスト:"run": 管理対象環境内でコマンドを実行するようにuvに指示します。"--python": 使用するPythonインタープリタを指定します。UVuv環境(.venv/bin/python)内のPythonインタープリタを指定することが重要です。"/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME/mcp_server.py": サーバー スクリプトへの絶対パス。
"workingDirectory": サーバー プロセスの作業ディレクトリを指定します。これはプロジェクトのルート ディレクトリである必要があります。
重要:
argsとworkingDirectory内のパスがシステムに対して正しいことを確認してください。アプリケーションが
uvを見つけられない場合は、"command"フィールドにフルパスを指定する必要があるかもしれません。通常、macOSまたはLinuxのターミナルでwhich uv実行するか、Windowsの場合はwhere uv実行することで、このパスを見つけることができます。サーバーは、
mcp_server.py(mcp.run(transport='stdio')) で設定されているとおり、デフォルトでstdioをリッスンします。これは通常、Cursor などのアプリケーションが期待するものです。
設定後、アプリケーションは Python MCP サーバーと通信できるようになります。
Claude Desktop や Cursor などのアプリケーションと統合できる、Python でカスタム モデル コンテキスト プロトコル (MCP) サーバーを作成するためのテンプレート リポジトリです。
Related MCP Servers
- -security-license-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 -1MIT License
- -security-license-qualityA streamlined foundation for building Model Context Protocol servers in Python, designed to make AI-assisted development of MCP tools easier and more efficient.Last updated -13MIT License
- -security-license-qualityA starter template for building Model Context Protocol (MCP) servers, enabling developers to create and add custom tools that can be integrated with Claude Desktop.Last updated -2
- -security-license-qualityA Python template for building Model Context Protocol (MCP) servers that expose tools via JSON-RPC, enabling secure and scalable context and tool invocation for language models.Last updated -