时间服务协议服务器

一个提供时间相关功能的模型上下文协议服务器,支持获取当前时间、时区转换、夏令时信息和时差计算。

  • by okooo5km
  • Go
  • 本地部署
  • 9 星标
  • 更新于
在 GitHub 查看 okooo5km/time-mcp-server

使用说明

时间MCP服务器

提供时间相关功能的模型上下文协议服务器。此服务器使LLM能够访问当前时间信息,并在不同时区之间转换时间。这是一个使用MCP Swift SDK的时间MCP服务器的Swift实现。

✨ 特性

  • 当前时间查询:获取任何时区的当前时间
  • 时区转换:在不同时区之间转换时间
  • 夏令时信息:检查时区当前是否为夏令时
  • 时差计算:转换时获取时区之间的时差

可用工具

  • get_current_time -获取特定时区的当前时间

    • timezone (字符串,必填):IANA时区名称(例如,“美国/纽约”、“欧洲/伦敦”)。如果为空或未提供,将使用系统时区。
  • convert_time -在时区之间转换时间

    • source_timezone (string,必填):源IANA时区名称。如果为空或未提供,将使用系统时区。
    • time (字符串,必填):转换为24小时格式的时间(HH:MM)
    • target_timezone (string,必填):目标IANA时区名称。如果为空或未提供,将使用系统时区。

安装

选项1:下载预构建二进制文件

从以下网址下载适用于您平台的最新预构建二进制文件 GitHub发布 页面:

从以下网址下载适用于您平台的二进制文件 GitHub发布 请参阅第页,并按照下面的安装说明进行操作。

macOS Installation

带苹果硅(M1/M2/M3)的macOS:

# Download the arm64 version
curl -L https://github.com/okooo5km/time-mcp-server/releases/latest/download/time-mcp-server-macos-arm64.zip -o time-mcp-server.zip
unzip time-mcp-server.zip
chmod +x time-mcp-server

# Remove quarantine attribute to avoid security warnings
xattr -d com.apple.quarantine time-mcp-server

# Install to your local bin directory
mkdir -p ~/.local/bin
mv time-mcp-server ~/.local/bin/
rm time-mcp-server.zip

配备英特尔处理器的macOS:

# Download the x86_64 version
curl -L https://github.com/okooo5km/time-mcp-server/releases/latest/download/time-mcp-server-macos-x86_64.zip -o time-mcp-server.zip
unzip time-mcp-server.zip
chmod +x time-mcp-server

# Remove quarantine attribute to avoid security warnings
xattr -d com.apple.quarantine time-mcp-server

# Install to your local bin directory
mkdir -p ~/.local/bin
mv time-mcp-server ~/.local/bin/
rm time-mcp-server.zip

macOS通用二进制(适用于Apple Silicon和Intel):

# Download the universal version
curl -L https://github.com/okooo5km/time-mcp-server/releases/latest/download/time-mcp-server-macos-universal.zip -o time-mcp-server.zip
unzip time-mcp-server.zip
chmod +x time-mcp-server

# Remove quarantine attribute to avoid security warnings
xattr -d com.apple.quarantine time-mcp-server

# Install to your local bin directory
mkdir -p ~/.local/bin
mv time-mcp-server ~/.local/bin/
rm time-mcp-server.zip
Linux Installation

x86_64上的Linux(最常见):

# Download the amd64 version
curl -L https://github.com/okooo5km/time-mcp-server/releases/latest/download/time-mcp-server-linux-amd64.tar.gz -o time-mcp-server.tar.gz
tar -xzf time-mcp-server.tar.gz
chmod +x time-mcp-server

# Install to your local bin directory
mkdir -p ~/.local/bin
mv time-mcp-server ~/.local/bin/
rm time-mcp-server.tar.gz

ARM64上的Linux(例如Raspberry Pi 4、AWS Graviton):

# Download the arm64 version
curl -L https://github.com/okooo5km/time-mcp-server/releases/latest/download/time-mcp-server-linux-arm64.tar.gz -o time-mcp-server.tar.gz
tar -xzf time-mcp-server.tar.gz
chmod +x time-mcp-server

# Install to your local bin directory
mkdir -p ~/.local/bin
mv time-mcp-server ~/.local/bin/
rm time-mcp-server.tar.gz
Windows Installation

x86_64上的Windows(最常见):

  • 下载 Windows AMD64版本
  • 解压缩ZIP文件
  • 移动 time-mcp-server.exe 到路径中的某个位置

ARM64上的Windows(例如ARM设备上的Windows):

  • 下载 Windows ARM64版本
  • 解压缩ZIP文件
  • 移动 time-mcp-server.exe 到路径中的某个位置

确保安装目录在PATH中:

  • macOS/Linux:添加 export PATH="$HOME/.local/bin:$PATH" 到您的shell配置文件(.bashrc, .zshrc等等)
  • 视窗:通过“系统属性”>“环境变量”对话框将目录添加到系统PATH中

选项2:从源代码构建

  1. 克隆存储库:

    git clone https://github.com/okooo5km/time-mcp-server.git
    cd time-mcp-server
    
  2. 构建项目:

    使用Make(推荐):

    # Build for your current platform
    make
    
    # Or build for a specific platform
    make build-darwin-universal    # macOS Universal Binary
    make build-darwin-arm64        # macOS Apple Silicon
    make build-darwin-amd64        # macOS Intel
    make build-linux-amd64         # Linux x86_64
    make build-linux-arm64         # Linux ARM64
    make build-windows-amd64       # Windows x86_64
    
    # Or build for all platforms at once
    make build-all
    
    # Create distribution packages for all platforms
    make dist
    

    二进制文件将被放置在 .build 目录。

    直接使用Swift:

    swift build -c release
    
  3. 安装二进制文件:

    # Install to user directory (recommended, no sudo required)
    mkdir -p ~/.local/bin
    cp time-mcp-server ~/.local/bin/
    

    确保 ~/.local/bin 通过将以下内容添加到shell配置文件中,将其添加到PATH中:

    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc  # or ~/.bashrc
    source ~/.zshrc  # or source ~/.bashrc
    

命令行参数

服务器支持以下命令行参数:

  • -h, --help:显示有关服务器、其使用情况和可用选项的帮助信息
  • -v, --version:显示时间mcp服务器的版本号
  • -t, --transport <string>:要使用的传输类型(默认值:“stdio”)
    • stdio:与LLM直接集成的标准输入/输出模式
    • sse:基于web的连接的服务器发送事件模式
  • -p, --port <int>:在SSE模式下运行时使用的端口(默认值:8080)
  • -l, --local-timezone <string>:用特定的IANA时区名称覆盖自动检测到的本地时区

示例用法:

# Display help information
time-mcp-server --help

# Display version information
time-mcp-server --version

# Start server with default settings (stdio mode)
time-mcp-server

# Start server in SSE mode on the default port (8080)
time-mcp-server --transport sse

# Start server in SSE mode on a custom port
time-mcp-server --transport sse --port 9090

# Start server with a specific local timezone
time-mcp-server --local-timezone Europe/London

在SSE模式下运行时,服务器将可通过指定端口上的HTTP访问,从而允许基于web的客户端连接。在stdio模式(默认)下,服务器通过标准输入/输出进行通信,这非常适合与LLM应用程序直接集成。

为Claude.app进行配置

添加到您的Claude设置中:

"mcpServers": {
  "RealTime": {
    "command": "time-mcp-server",
    "args": ["-l", "Asia/Shanghai"]
  }
}

配置光标

将以下配置添加到游标编辑器的设置-mcp.json中:

{
  "mcpServers": {
    "RealTime": {
      "command": "time-mcp-server",
      "args": ["-l", "Asia/Shanghai"]
    }
  }
}

配置ChatWise

将内存MCP服务器添加到Chatwise设置-工具中。

系统提示示例

您可以使用以下系统提示来帮助Claude有效地利用时间mcp服务器:

You have access to time-related tools through MCP. Use these to help users:

- Get the current time in any timezone
- Convert times between timezones
- Calculate time differences between locations
- Plan meetings across different timezones

Use the following tools appropriately:
- `get_current_time` for checking the current time in a specific timezone
- `convert_time` when the user needs to convert between timezones

Always use proper IANA timezone names (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo')
rather than abbreviations or common names.

开发要求

  • Swift 6.0或更高版本
  • macOS 14.0或更高版本
  • MCP Swift SDK 0.2.0或更高版本

使用示例

获取当前时间

{
  "timezone": "America/New_York"
}

答复:

{
  "timezone": "America/New_York",
  "datetime": "2024-11-05T14:30:45-05:00",
  "is_dst": false
}

转换时间

{
  "source_timezone": "America/Los_Angeles",
  "time": "15:30",
  "target_timezone": "Asia/Tokyo"
}

答复:

{
  "source": {
    "timezone": "America/Los_Angeles",
    "datetime": "2024-11-05T15:30:00-08:00",
    "is_dst": false
  },
  "target": {
    "timezone": "Asia/Tokyo",
    "datetime": "2024-11-06T08:30:00+09:00",
    "is_dst": false
  },
  "time_difference": "+17h"
}

用例

  • 国际会议策划:跨时区安排会议
  • 旅行计划:查看目的地当地时间
  • 远程工作协调:与国际团队协调工作时间
  • 事件调度:使用正确的当地时间设置全球活动
  • 时间敏感型操作:确保操作在正确的当地时间进行

版本历史记录

有关版本历史记录和更改日志,请参阅GitHub Release。

☕️ 支持项目

如果您觉得time-mcp服务器有用,请考虑支持其开发:

  • ⭐️ 在GitHub上启动该项目
  • 🐛 报告错误或建议功能
  • 💝 支持方式:

许可证

time-mcp服务器根据MIT许可证获得许可。这意味着您可以根据MIT许可证的条款和条件自由使用、修改和分发软件。

关于

模型上下文协议(MCP)时间服务器的Swift实现,使AI助手能够访问当前时间信息并在时区之间进行转换。这个项目是使用MCP Swift SDK构建的。