mcpField
M
MCP Server Template (Python)

MCP Server Template (Python)

ローカル
github.com/Nisarg38開発ツール284 週間前に更新

MCP Server Template (Python) について

MCP Server Template (Python)は、MCPサーバーを開発するためのPython用スターターテンプレートです。ツールやプロンプトの公開例に加え、HTTPとstdioのトランスポートおよびデプロイ手順を備えています。

主な機能

  1. 01ツールとプロンプトの登録
  2. 02HTTPまたはstdioでの実行
  3. 03ポートとデバッグログの設定
  4. 04Dockerまたはクラウドコンテナへのデプロイ
  5. 05テストとフォーマットの手順

活用シーン

  1. 01Python製MCPサーバープロジェクトの開始
  2. 02モデル向けカスタムツールとプロンプトの公開
  3. 03HTTPまたはstdioによるローカル実行
  4. 04サーバーのコンテナ化とデプロイ

MCP 対応

このテンプレートは、MCPクライアントにツールとプロンプトを公開するMCPサーバーの開発を支援します。HTTPとstdioのトランスポートに対応します。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

インストール方法は未掲載です

このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。

リポジトリ

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

MCP サーバー テンプレート(Python)

Python 3.10+ License: MIT

Python で Model Context Protocol(MCP)サーバーを構築するための、すぐに使えるテンプレートです。このテンプレートを使うと、AI モデルが利用できるツールやプロンプトを登録して公開するサーバーを、すばやく作成できます。

📚 目次

🚀 クイックスタート

前提条件
  • Python 3.10 以降
3 つの簡単な手順でセットアップ
1️⃣ パッケージをインストールする
# Clone the repository
git clone https://github.com/nisarg38/mcp-server-template-python.git my-mcp-server
cd my-mcp-server

# Install in development mode
pip install -e ".[dev]"
2️⃣ サーバーを実行する
# Run with Python
python -m src.main

# Or use the convenient CLI
mcp-server-template
3️⃣ サーバーが起動しました!

次の場所から MCP サーバーにアクセスできます。

  • 🌐 HTTP:http://localhost:8080
  • 💻 または、stdio トランスポートを使用します:mcp-server-template --transport stdio

サーバーが正常に起動したことを示すログが表示されます。

🎮 コマンドラインオプション

次のコマンドラインオプションで、サーバーの動作をカスタマイズできます。

# Change port (default: 8080)
mcp-server-template --port 9000

# Enable debug mode for more detailed logs
mcp-server-template --debug

# Use stdio transport instead of HTTP
mcp-server-template --transport stdio

# Set logging level (options: debug, info, warning, error)
mcp-server-template --log-level debug

🛠️ 独自のツールとプロンプトの作成

ツールを追加する

ツールは AI モデルから呼び出せる関数です。新しいツールを追加するには、次の手順に従います。

  1. src/main.py を編集します
  2. @mcp.tool() デコレーターを使って新しい関数を追加します。
@mcp.tool()
def your_tool_name(param1: str, param2: int) -> Dict[str, Any]:
    """
    Your tool description - this will be shown to the AI.
    
    Args:
        param1: Description of first parameter
        param2: Description of second parameter
        
    Returns:
        Dictionary with your results
    """
    # Your tool logic here
    return {"result": "your result"}
プロンプトを追加する

プロンプトは AI モデルが利用できるテンプレートです。

@mcp.prompt()
def your_prompt_name(param: str) -> str:
    """Your prompt description."""
    return f"""
    Your formatted prompt with {param} inserted.
    Use this for structured prompt templates.
    """

📁 プロジェクト構成

src/                      # Source code directory
├── main.py               # Server entry point with tools & prompts
├── config.py             # Configuration settings
├── utils/                # Utility functions
├── tools/                # Tools implementation
└── resources/            # Resource definitions
test/                     # Tests directory
pyproject.toml            # Package configuration
Dockerfile                # Docker support

🚢 デプロイオプション

Docker でのデプロイ
# Build the Docker image
docker build -t my-mcp-server .

# Run the container
docker run -p 8080:8080 my-mcp-server
クラウドへのデプロイ

このテンプレートは、さまざまなクラウドプラットフォームで適切に動作するように設計されています。

  • AWS、GCP、Azure でコンテナーとしてデプロイできます
  • コンテナー化されたアプリケーションに対応するサーバーレスプラットフォームで実行できます
  • オーケストレーションには Kubernetes を使用できます

🧪 開発ガイド

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src test
isort src test

# Run linting
flake8 src test

❓ お困りですか?

  • 📚 MCP ドキュメント:modelcontextprotocol.io
  • 🐛 問題を報告する:GitHub Issues
  • 💬 コミュニティ:Discord コミュニティに参加してください(リンクは近日公開)

AI 開発者コミュニティのために ❤️ を込めて作成

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。