ModelContextProtocolServer について
ModelContextProtocolServerは、計算機と天気検索のツールを提供するMCPサーバーの例です。READMEにはSSEまたはstdioでの起動方法と、ツールの一覧取得・呼び出し方法が示されています。
主な機能
- 01基本的な計算機ツールを提供
- 02場所を指定して天気を検索
- 03SSE接続に対応
- 04stdioでの起動に対応
活用シーン
- 01MCPツールで算術計算を実行
- 02都市の天気を確認
- 03SSEまたはstdioのMCP接続をテスト
MCP 対応
MCPサーバーは計算機と天気検索のツールをクライアントに提供し、SSEとstdioのトランスポート例を示しています。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
インストール方法は未掲載です
このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。
ツール
ツール一覧はまだ取得されていません
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
ModelContextProtocolServer
API の例
SSE ストリームに接続する
curl -N -H "Accept: text/event-stream" http://localhost:8081/sse
stdio に接続する
Java アーティファクトを生成する
./mvnw clean install
stdio サーバーを起動する
java -Dtransport.mode=stdio \
-Dspring.main.web-application-type=none \
-Dspring.main.banner-mode=off \
-Dlogging.file.name=mcpserver.log \
-jar target/mcpserver-0.0.1-SNAPSHOT.jar
tool/list リクエストを送信する
例
リクエスト
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' http://localhost:8081/mcp/message
レスポンス
event:message
data:{"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"calculator","description":"Basic calculator","inputSchema":{"type":"object","properties":{"operation":{"type":"string"},"a":{"type":"number"},"b":{"type":"number"}},"required":["operation","a","b"]}},{"name":"get_current_weather","description":"Get the current weather in a given location","inputSchema":{"type":"object","properties":{"location":{"type":"string","description":"The name of the city e.g. San Francisco, CA"},"format":{"type":"string","enum":["celsius","fahrenheit"],"description":"The format to return the weather in"}},"required":["location"]}}]}}
calculator ツールを呼び出す
例
リクエスト
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"calculator","arguments":{"operation":"+","a":2,"b":3}}}' http://localhost:8081/mcp/message
レスポンス
event:message
data:{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","type":"text","text":"2.00 + 3.00 = 5.00"}],"isError":false}}
weather ツールを呼び出す
例
リクエスト
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_current_weather","arguments":{"location":"San Francisco","format":"celsius"}}}' http://localhost:8081/mcp/
レスポンス
event:message
data:{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","type":"text","text":"Current weather in San Francisco, United States of America: Partly cloudy, 11.1°C, Precipitation: 0.0 mm"}],"isError":false}}
コメント
Markdown 対応
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。