yokoba/mcp-server-sample
If you are the rightful owner of mcp-server-sample and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This repository provides a minimal setup for an MCP server and client, demonstrating how to use Gemini function calling to automatically select tools based on context.
Simple MCP Server & Client Sample (with Gemini Function Calling)
概要
-
MCP(Model Context Protocol)とは?
機械学習モデルやAIエージェントに外部のツール(API)を呼ばせるプロトコル。 -
本リポジトリの目的
- 「MCPサーバ・クライアントの最小構成ってどう作るの?」
- 「LLM(Gemini)でどのツールを呼ぶか自動で選ばせたい」
というニーズ向けの備忘録です。
ファイル構成
-
mcp_simple_server1.py
MCPサーバの最小サンプル。 -
mcp_simple_client1.py
MCPクライアントの最小サンプル(接続確認用)。 -
mcp_simple_server2.py
MCPサーバの最小サンプル。
greet
/farewell
の2つのtoolを用意。 -
mcp_simple_client2.py
Gemini function callingを使ったMCPクライアント。
LLMが時刻によって自動でgreet
またはfarewell
を選択し、サーバを呼び出します。
実行環境
- Python 3.13(3.10以上なら動作するはず)
- fastmcp >= 2.5.2
- google-genai >= 1.18.0
- uv (なくても動作するが高速化目的で推奨)
インストールと実行
- 必要なパッケージをインストール
uv init
uv add google-genai
uv add fastmcp
-
Gemini APIキーを取得し、環境変数
GEMINI_API_KEY
に設定
(Google AI Studioで無料発行可能) -
サーバ・クライアントの起動例
-
サーバ単体で起動(例)
python mcp_simple_client1.py
-
クライアント+Gemini連携で実行(例)
python mcp_simple_client2.py
使い方
- サンプルコードはすべてコピペ・実行可能です。
- Geminiのfunction callingで時刻によるtool選択をLLMに委ねています。
注意
- エラーハンドリングや例外処理はシンプルさを優先して省略しています。
- 実際の業務・サービス実装では適切なバリデーション、ログ、例外処理を追加してください。
License
MITライセンス等ご自由に。
備忘録・サンプル用途です。ご自身の責任でご利用ください。