Time MCP Server について
Time MCP Server は FastMCP 2.0 で構築された時間ツール用サーバーで、現在時刻とその構成要素を返します。タイムゾーンや書式を指定したい LLM クライアント向けです。
主な機能
- 01現在の日付と時刻の取得
- 02時刻出力の書式指定
- 03タイムゾーンの指定
- 04時刻の各構成要素を取得
活用シーン
- 01指定したタイムゾーンの現在時刻を確認
- 02希望する書式で日付を取得
- 03曜日や時刻の各項目を取得
MCP 対応
MCP を通じて現在時刻と時刻の構成要素を取得するツールを提供し、stdio と streamable HTTP に対応します。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。
ツール
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
Time MCP Server
大規模言語モデル向けに、時間関連のツールを提供する Model Context Protocol(MCP)サーバーです。FastMCP 2.0 で構築されています。
セットアップ
このプロジェクトでは、Python パッケージ管理に uv を、一般的なコマンドの実行に task を使用します。
前提条件
インストール
- リポジトリをクローンします
- セットアップタスクを実行して仮想環境を作成します:
task setup - 開発モードでパッケージをインストールします:
task install
使用方法
サーバーの実行
タスクランナーを使用して MCP サーバーを実行します:
task run
デフォルトでは、サーバーは stdio トランスポートを使用して起動します。これは、Claude Desktop やその他のローカル MCP クライアントとの接続に最適です。
コマンドラインオプション
トランスポートの種類とポートを設定できます:
# Run with stdio transport (default)
python -m time_mcp_server.main --transport stdio
# Run with HTTP transport on port 9000
python -m time_mcp_server.main --transport streamable-http --port 9000
また、タスクランナーを使用する場合は、-- の後に引数を渡せます:
# Run with stdio transport (default)
task run
# Run with HTTP transport
task run -- --transport streamable-http --port 9000
利用可能なツール
Time MCP Server は、LLM 向けに以下のツールを提供します:
-
get_current_time - 現在の日付と時刻を取得します
- パラメーター:
date_format(任意):日時の書式文字列(例:'%Y-%m-%d %H:%M:%S')timezone(任意):タイムゾーン名(例:'Europe/Berlin'、'America/New_York')。デフォルトは 'Europe/Berlin' です
- 戻り値:現在時刻を ISO 形式で示した値、指定された形式、および使用されたタイムゾーンを含む辞書
- パラメーター:
-
get_time_components - 現在時刻の各要素を取得します
- パラメーター:
timezone(任意):タイムゾーン名(例:'Europe/Berlin'、'America/New_York')。デフォルトは 'Europe/Berlin' です
- 戻り値:年、月、日、時、分、秒、マイクロ秒、曜日、タイムゾーンを含む辞書
- パラメーター:
クライアントの使用例
この MCP サーバーを LLM クライアントで使用するには、サーバーのエンドポイントに接続してツールを呼び出します:
import asyncio
from fastmcp import Client
async def main():
# Connect to the Time MCP Server
# Make sure to include the root path '/' in the URL
async with Client("http://localhost:8090/") as client:
# Get the current time
result = await client.call_tool("get_current_time", {"date_format": "%Y-%m-%d %H:%M:%S", "timezone": "America/New_York"})
# Parse the JSON response
import json
time_data = json.loads(result[0].text)
print(time_data)
# Output: {'iso_time': '2025-05-09T10:27:31.123456-04:00', 'formatted_time': '2025-05-09 10:27:31', 'timezone': 'America/New_York'}
# Get time components
result = await client.call_tool("get_time_components", {"timezone": "Europe/Berlin"})
components = json.loads(result[0].text)
print(components)
# Output: {'year': 2025, 'month': 5, 'day': 9, 'hour': 16, 'minute': 27, 'second': 31, 'microsecond': 123456, 'weekday': 4, 'timezone': 'Europe/Berlin'}
# Run the async client
asyncio.run(main())
Claude Desktop への接続
Time MCP Server は、デフォルトで stdio トランスポートを使用するため、Claude Desktop に簡単に接続できます。設定方法は次のとおりです:
- Claude Desktop を開きます
- 上部バーの「Claude」メニュー(macOS の場合)または Windows の該当するメニューをクリックします
- 「Settings...」を選択してから、「Developer」>「Edit Config」に移動します
- 設定ファイルに Time MCP Server を追加します:
{
"mcpServers": {
"current-time": {
"command": "/path/to/uv",
"args": [
"run", "--directory", "/path/to/time-mcp-server", "python", "-m", "time_mcp_server.main"
]
}
}
}
/path/to/uv を uv 実行ファイルへのパスに、/path/to/time-mcp-server をプロジェクトディレクトリの実際のパスに置き換えてください。
- 設定ファイルを保存して Claude Desktop を再起動します
- Claude の入力欄の右下にハンマーのアイコンが表示されます
- そのアイコンをクリックすると、Time MCP Server のツールが表示されます
これで、Claude に次のような時間ツールを使うよう依頼できます:
- 「現在の時刻は?」
- 「現在の日付を YYYY-MM-DD 形式で教えてくれますか?」
- 「今日は何曜日ですか?」
- 「今、ニューヨークは何時ですか?」
- 「東京のタイムゾーンでは現在何時ですか?」
プロジェクト構成
プロジェクトは次の構成になっています:
src/time_mcp_server/
├── __init__.py # Package initialization
├── main.py # Command-line interface and entry point
├── server.py # MCP server configuration
└── tools.py # Time tool implementations
tests/
└── test_client.py # Tests for the time tools
開発
- コードをフォーマットする:
task format - リントの問題を確認して修正する:
task check - テストを実行する:
task test
テスト
このプロジェクトには、クライアントとして Time MCP Server を使用する方法を示すテストが含まれています。テストでは FastMCP のインメモリークライアントを使用し、ネットワーク接続を必要とせずにサーバーへ直接接続します。
# Example of using the FastMCP client to connect to the server
from fastmcp import Client
from time_mcp_server.server import mcp # Import the MCP server instance
async with Client(mcp) as client:
# List available tools
tools = await client.list_tools()
# Call the get_current_time tool
result = await client.call_tool("get_current_time", {"date_format": "%Y-%m-%d %H:%M:%S", "timezone": "Europe/Berlin"})
text_content = result[0]
# Parse the JSON response
import json
time_data = json.loads(text_content.text)
print(time_data)
次のコマンドでテストを実行します:
task test
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。