Model Context Protocol (MCP) Server
モデルコンテキストプロトコル(MCP)のPython実装
このプロジェクトは、Anthropic MCP仕様に準拠した、Pythonで動作するモデルコンテキストプロトコル(MCP)サーバーとクライアントを実装します。MCPプロトコルの主要なパターンを、シンプルでインタラクティブな例を通して示します。
MCPとは何ですか?
モデルコンテキストプロトコル(MCP)は、JSON-RPC 2.0を基盤とするオープンスタンダードで、AIモデルを外部データソースやツールに接続するためのものです。MCPは、AIアプリケーションが1つ以上のMCPサーバーと通信するクライアントサーバーアーキテクチャを定義します。各MCPサーバーは、以下のような機能を公開します。
ツール: アクションを実行する実行可能な関数
リソース: 情報を提供するデータソース
プロンプト: 定義済みのテンプレートまたはワークフロー
MCP は、これらの機能の検出および呼び出し方法を標準化し、モデルが外部システムと構造化された方法で対話できるようにする「AI 向け USB-C」として機能します。
Related MCP server: simple_mcp
プロジェクト構造
server/: MCPサーバーの実装server.py: MCP リクエストを処理し、サンプルツール/リソースを提供する WebSocket サーバー
client/: MCPクライアント実装client.py: サーバーに接続し、すべての MCP 機能を実行するデモ クライアント
デモされた機能
この実装は、コア MCP プロトコル フローを紹介します。
機能ネゴシエーション:
initialize介したクライアント・サーバー間のハンドシェイク能力発見:利用可能なツールとリソースの一覧
ツールの呼び出し: パラメータを指定して
add_numbersツールを呼び出すリソースアクセス: リソースからテキストコンテンツを読み取る
設定
仮想環境を作成します。
python3 -m venv .venv source .venv/bin/activate依存関係をインストールします:
pip install -r requirements.txt
使用法
MCP サーバーを起動します (1 つのターミナルで):
python server/server.pyMCP クライアントを実行します (別のターミナルで)。
python client/client.py
クライアントはサーバーに接続し、MCP ハンドシェイクを実行し、機能を検出し、フォーマットされた出力でツールの呼び出しとリソースへのアクセスを実演します。
仕組み
MCPサーバー
サーバー:
WebSocket接続を受け入れる
MCP仕様に従ってJSON-RPCリクエストに応答します
サンプルツール(
add_numbers)を提供しますサンプルリソース(
example.txt)を提供しますMCPハンドシェイクと機能検出をサポート
MCPクライアント
クライアント:
WebSocket経由でサーバーに接続する
MCPハンドシェイクを実行する
利用可能なツールとリソースを発見する
ツールの呼び出しとリソースの読み取りを実演します
結果をフォーマットされた形式で表示します
プロトコルの詳細
MCP は次の主要なメソッドを実装します。
方法 | 説明 |
| 能力を確立するためのハンドシェイク |
| 利用可能なツールの一覧 |
| 引数を指定してツールを呼び出す |
| 利用可能なリソースを一覧表示する |
| リソースコンテンツを読む |
| 利用可能なプロンプトを一覧表示する |
プロジェクトの拡張
この実装は次のように拡張できます。
さまざまな機能を備えたツールを追加する
読み取りごとに変化する動的リソースの追加
ガイド付きインタラクションのためのプロンプトテンプレートの実装
よりインタラクティブなクライアントアプリケーションの作成
参考文献
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-quality-maintenanceAn MCP server implementation that standardizes how AI applications access tools and context, providing a central hub that manages tool discovery, execution, and context management with a simplified configuration system.13
- Flicense-qualityDmaintenanceAn educational MCP server that teaches implementing the Model Context Protocol from scratch, enabling AI models to discover and invoke tools via JSON-RPC over stdio.
- Flicense-qualityDmaintenanceA basic MCP server implementation using Node.js and TypeScript that bridges AI models with external tools and data sources via JSON-RPC.2
- Flicense-qualityBmaintenanceA demo MCP server that connects an AI to external systems by exposing Python functions as tools and data as resources, using the stdio transport.
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
MCP server exposing the Backtest360 engine API as tools for AI agents.
MCP server for Clipkit — gives AI agents a video toolbox via the Clipkit schema.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/suspicious-cow/MCP2'
If you have feedback or need assistance with the MCP directory API, please join our Discord server