Python MCP Server Template

by nictuku
MIT License
4
  • Apple
  • Linux

py-mcp-server-テンプレート

このリポジトリは、Pythonで独自のMCP(モデルコンテキストプロトコル)サーバーを作成するのに役立つテンプレートです。始めるには、このリポジトリをフォークしてください。

UVを使ったセットアップ

このプロジェクトでは、Pythonのパッケージングと仮想環境の管理にuvを使用しています。UV uvインストールされていない場合は、公式のUVインストールガイドを参照してください。

  1. フォークしたリポジトリをクローンします。
    git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git cd YOUR_REPOSITORY_NAME
  2. **仮想環境を作成してアクティブ化します。**通常、 uvプロジェクト ルートに.venvディレクトリを作成します。
    uv venv source .venv/bin/activate # On macOS/Linux # .venv\Scripts\activate # On Windows
  3. **依存関係のインストール:**このプロジェクトは、依存関係を管理するためにpyproject.tomlを使用します。
    uv pip install .
    新しい依存関係を追加する場合は、 pyproject.tomlファイルで定義し、このコマンドを再度実行してください。何らかの理由でrequirements.txtファイルを使用している場合は、 uv pip install -r requirements.txtでインストールできます。

サーバーの実行

mcp_server.pyスクリプトは MCP サーバーを起動します。

サーバーを直接実行するには:

uv run python mcp_server.py

Claude DesktopまたはCursorとの統合

このMCPサーバーをClaude DesktopやCursorなどのアプリケーションで使用するには、アプリケーションの設定で設定する必要があります。設定には通常、サーバーを実行するコマンドの指定が含まれます。

設定例を以下に示します。/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME /ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAMEシステム上のプロジェクトディレクトリへの実際の絶対パスに置き換える必要があります。

{ "mcpServers": { "my-custom-python-server": { "command": "uv", "args": [ "run", "--python", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME/.venv/bin/python", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME/mcp_server.py" ], "workingDirectory": "/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME" } } }

構成の説明:

  • "my-custom-python-server" : これはサーバー構成に付ける名前です。
  • "command": "uv" : 実行するコマンドとしてuvを指定します。
  • "args" : uvコマンドの引数のリスト:
    • "run" : 管理対象環境内でコマンドを実行するようにuvに指示します。
    • "--python" : 使用するPythonインタープリタを指定します。UV uv環境( .venv/bin/python )内のPythonインタープリタを指定することが重要です。
    • "/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME/mcp_server.py" : サーバー スクリプトへの絶対パス。
  • "workingDirectory" : サーバー プロセスの作業ディレクトリを指定します。これはプロジェクトのルート ディレクトリである必要があります。

重要:

  • argsworkingDirectory内のパスがシステムに対して正しいことを確認してください。
  • アプリケーションがuvを見つけられない場合は、 "command"フィールドにフルパスを指定する必要があるかもしれません。通常、macOSまたはLinuxのターミナルでwhich uv実行するか、Windowsの場合はwhere uv実行することで、このパスを見つけることができます。
  • サーバーは、 mcp_server.py ( mcp.run(transport='stdio') ) で設定されているとおり、デフォルトでstdioをリッスンします。これは通常、Cursor などのアプリケーションが期待するものです。

設定後、アプリケーションは Python MCP サーバーと通信できるようになります。

-
security - not tested
A
license - permissive license
-
quality - not tested

Claude Desktop や Cursor などのアプリケーションと統合できる、Python でカスタム モデル コンテキスト プロトコル (MCP) サーバーを作成するためのテンプレート リポジトリです。

  1. UVを使ったセットアップ
    1. サーバーの実行
      1. Claude DesktopまたはCursorとの統合

        Related MCP Servers

        • -
          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
          A Model Context Protocol server built with mcp-framework that allows users to create and manage custom tools for processing data, integrating with the Claude Desktop via CLI.
          Last updated -
          48
          4
          TypeScript
          • Apple
        • -
          security
          A
          license
          -
          quality
          A 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 -
          13
          Python
          MIT License
        • -
          security
          F
          license
          -
          quality
          A 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 -
          TypeScript
          • Apple

        View all related MCP servers

        ID: 48pzj21eqm