ZeparHyfar/mcp-datetime

分类General
作者Community
星标411
定价Free

简介

mcp-datetime 是一个轻量级的 MCP 服务端,旨在解决 LLM 经常在处理实时日期和时间计算时出现“幻觉”的问题。它为 AI 提供了标准化的时间接口,使其能够准确获取当前时间,并支持多种格式的转换与日期运算。对于需要处理日程规划、日志分析或时间戳转换的开发者来说,它能让 AI 从一个“猜测时间”的聊天机器人变成一个具备精准时间感知能力的助手。配置简单,无需复杂环境,通过 MCP 协议即可快速集成到支持的 IDE 或客户端中。

核心亮点

  • 消除 AI 时间幻觉,提供精准的实时日期查询
  • 支持多种时间格式转换,适配不同开发场景
  • 简化日期计算逻辑,无需手动输入当前时间
  • 即插即用,快速增强 AI 的时间感知能力

完整文档

mcp-datetime

![Python Version](https://www.python.org/downloads/)
![MCP Version](https://github.com/anaisbetts/mcp)
![License](LICENSE)

English | 日本語

一个为 Claude Desktop Application 实现的 MCP server 日期时间格式化服务。支持生成多种格式的 datetime 字符串。

> 注意:本软件包仅在 macOS 上经过测试。Windows 兼容性尚未验证。

Prerequisites

在使用 mcp-datetime 之前,请确保已安装以下工具:

  • Python 3.12 或更高版本
  • uv (Python 包安装程序)
  • uvx (Python 包运行器)

Features

  • ✨ 支持多种 datetime 格式
  • 🇯🇵 支持日语
  • 📁 针对文件名生成的优化格式
  • 🌏 精确的时区处理
  • 🔧 与 Claude Desktop App 无缝集成

MCP Server Components

Tools

该 server 实现了以下工具:

  • get_datetime: 以多种格式获取当前日期和时间
- 接收 format 作为必需的 string 参数 - 根据指定的格式返回格式化后的 datetime 字符串 - 支持多种格式类型,包括标准格式、日语格式和 ISO 格式

Usage with Claude Desktop App

将以下内容添加到你的配置文件中:

配置文件位置 (macOS):
~/Library/Application Support/Claude/claude_desktop_config.json

json
{
"mcpServers": {
"mcp-datetime": {
"command": "uvx",
"args": ["mcp-datetime"]
}
}
}
## 关于安装

如果您需要直接安装该 package(例如为了进行开发或查看源代码),可以使用以下方法之一:

  • 从 PyPI 安装
    bash
    pip install mcp-datetime
    - 从 GitHub 源码安装
    bash
    git clone https://github.com/ZeparHyfar/mcp-datetime.git
cd mcp-datetime pip install -e .
- 用于手动安装的 claude_desktop_config.json 示例
json
{
    "mcpServers": {
      "mcp-datetime": {
        "command": "python",
        "args": ["-m", "mcp_datetime"],
        "env": {
          "PYTHON": "/path/to/your/python"
        }
      }
    }
  }
/path/to/your/python 替换为您实际的 Python 解释器路径 > 例如 "/usr/local/bin/python3""/Users/username/.pyenv/versions/3.12.0/bin/python3"

基础示例

  • 命令格式
    code
    # Standard datetime format
call datetime-service.get_datetime {"format": "datetime"} # Result: 2024-12-10 00:54:01

# Japanese format
call datetime-service.get_datetime {"format": "datetime_jp"}
# Result: 2024年12月10日 00時54分01秒

# Filename format
call datetime-service.get_datetime {"format": "filename_md"}
# Result: 20241210005401.md

- Claude Desktop App 提示词示例

- 用户

code
Please tell me the current time in date_slash format
- Claude
code
I'll get the current date in date_slash format.

The current date is 2024/12/12

## 支持的格式| Format Name | Example | Description |
| ------------ | --------------------------- | ---------------------------- |
| date | 2024-12-10 | 标准日期格式 |
| date_slash | 2024/12/10 | 斜杠分隔日期 |
| date_jp | 2024年12月10日 | 日式日期格式 |
| datetime | 2024-12-10 00:54:01 | 标准日期时间 |
| datetime_jp | 2024年12月10日 00時54分01秒 | 日式日期时间 |
| datetime_t | 2024-12-10T00:54:01 | 带 T 分隔符的日期时间 |
| compact | 20241210005401 | 用于 ID 的紧凑格式 |
| compact_date | 20241210 | 仅紧凑日期 |
| compact_time | 005401 | 仅紧凑时间 |
| filename_md | 20241210005401.md | Markdown 文件名 |
| filename_txt | 20241210005401.txt | 文本文件名 |
| filename_log | 20241210005401.log | 日志文件名 |
| iso | 2024-12-10T00:54:01+0900 | ISO 8601 格式 |
| iso_basic | 20241210T005401+0900 | 基础 ISO 格式 |
| log | 2024-12-10 00:54:01.123456 | 带微秒的日志格式 |
| log_compact | 20241210_005401 | 紧凑日志格式 |
| time | 00:54:01 | 仅时间 |
| time_jp | 00時54分01秒 | 日式时间格式 |## 调试

由于 MCP server 通过 stdio 运行,调试可能会比较困难。我们建议使用 MCP Inspector

npx @modelcontextprotocol/inspector uvx --directory ./mcp-datetime run mcp-datetime## License

本项目采用 MIT License 许可 - 详见 LICENSE 文件。

查看官方来源