
mcp server sample
MCPサーバーの使用サンプル
Repository Info
About This Server
MCPサーバーの使用サンプル
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP サーバー
このリポジトリは Model Context Protocol (MCP) を使用した天気予報サーバーの実装例です。
プロジェクト概要
Model Context Protocol (MCP) は、大規模言語モデル (LLM) とツールを接続するためのプロトコルです。このプロジェクトでは、MCP SDK を使用して、National Weather Service (NWS) API に接続する天気予報ツールを提供するサーバーを実装しています。
このサーバーは、緯度と経度を入力として受け取り、その場所の天気予報を返します。
使用技術
- TypeScript: 静的型付けを提供するJavaScriptのスーパーセット
- Node.js: JavaScriptランタイム環境
- MCP SDK: Model Context Protocol の実装を提供するSDK
- National Weather Service API: 米国の天気予報データを提供するAPI
インストール方法
- リポジトリをクローンします:
git clone <repository-url>
cd mcp-server-quickstart
- 依存関係をインストールします:
npm install
- プロジェクトをビルドします:
npm run build
使い方
サーバーの実行
ビルド後、以下のコマンドでサーバーを実行できます:
./build/index.js
または、パッケージをインストールした場合:
my-mcp-server
MCP クライアントからの接続
このサーバーは標準入出力 (stdio) を使用して MCP クライアントと通信します。MCP 対応のクライアント(例:MCP 対応の LLM)からこのサーバーを呼び出すことができます。
利用可能なツール
このサーバーは以下のツールを提供しています:
- get_forecast: 指定された緯度と経度の天気予報を取得します
- 入力パラメータ:
latitude: 場所の緯度(数値)longitude: 場所の経度(数値)
- 出力: 指定された場所の天気予報テキスト
- 入力パラメータ:
実装の詳細
サーバーの実装は主に以下の3つのステップで構成されています:
-
サーバーインスタンスの初期化:
const server = new Server( { name: "weather", version: "1.0.0", }, { capabilities: { tools: {}, }, }, ); -
利用可能なツールの一覧を返す:
server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "get_forecast", description: "Get weather forecast for a location", inputSchema: { // ... }, }, ], }; }); -
ツールの実行:
server.setRequestHandler(CallToolRequestSchema, async (request) => { // ツールの実行ロジック });
注意事項
- このサーバーは米国の National Weather Service API を使用しているため、米国内の場所の天気予報のみ取得できます。
- API の利用制限に注意してください。
ライセンス
このプロジェクトのライセンス情報については、LICENSE ファイルを参照してください。
Quick Start
Clone the repository
git clone https://github.com/moriokameda/mcp-server-sampleInstall dependencies
cd mcp-server-sample
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.