mcpField
T
Time MCP Server

Time MCP Server

ローカル
github.com/petrarca生産性075 週間前に更新

Time MCP Server について

Time MCP Server は FastMCP 2.0 で構築された時間ツール用サーバーで、現在時刻とその構成要素を返します。タイムゾーンや書式を指定したい LLM クライアント向けです。

主な機能

  1. 01現在の日付と時刻の取得
  2. 02時刻出力の書式指定
  3. 03タイムゾーンの指定
  4. 04時刻の各構成要素を取得

活用シーン

  1. 01指定したタイムゾーンの現在時刻を確認
  2. 02希望する書式で日付を取得
  3. 03曜日や時刻の各項目を取得

MCP 対応

MCP を通じて現在時刻と時刻の構成要素を取得するツールを提供し、stdio と streamable HTTP に対応します。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

インストール方法は未掲載です

このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。

リポジトリ

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

Time MCP Server

大規模言語モデル向けに、時間関連のツールを提供する Model Context Protocol(MCP)サーバーです。FastMCP 2.0 で構築されています。

セットアップ

このプロジェクトでは、Python パッケージ管理に uv を、一般的なコマンドの実行に task を使用します。

前提条件
  • Python 3.12 以上
  • uv - 高速な Python パッケージインストーラー兼リゾルバー
  • Task - タスクランナー/ビルドツール
インストール
  1. リポジトリをクローンします
  2. セットアップタスクを実行して仮想環境を作成します:
    task setup
    
  3. 開発モードでパッケージをインストールします:
    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 向けに以下のツールを提供します:

  1. get_current_time - 現在の日付と時刻を取得します

    • パラメーター:
      • date_format(任意):日時の書式文字列(例:'%Y-%m-%d %H:%M:%S')
      • timezone(任意):タイムゾーン名(例:'Europe/Berlin'、'America/New_York')。デフォルトは 'Europe/Berlin' です
    • 戻り値:現在時刻を ISO 形式で示した値、指定された形式、および使用されたタイムゾーンを含む辞書
  2. 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 に簡単に接続できます。設定方法は次のとおりです:

  1. Claude Desktop を開きます
  2. 上部バーの「Claude」メニュー(macOS の場合)または Windows の該当するメニューをクリックします
  3. 「Settings...」を選択してから、「Developer」>「Edit Config」に移動します
  4. 設定ファイルに 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 をプロジェクトディレクトリの実際のパスに置き換えてください。

  1. 設定ファイルを保存して Claude Desktop を再起動します
  2. Claude の入力欄の右下にハンマーのアイコンが表示されます
  3. そのアイコンをクリックすると、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

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。