SuperAPI AI 工具集

mcp-datetime

mcp-datetime 是一个以 MCP 服务器形式实现的日期时间格式化服务,主要用于 Claude Desktop 应用。它提供单个工具 get_datetime,可按指定格式返回当前日期时间字符串,支持多种格式,包括标准格式、日文格式和 ISO 格式,并针对文件名生成做了优化。项目注重准确的时区处理,与 Claude Desktop 应用无缝集成。使用前需安装 Python 3.12 或更高版本,以及 uv 和 uvx。注意:该包仅在 macOS 上测试过,Windows 兼容性尚未验证。

访问官网

工具介绍

用途

mcp-datetime 是一个实现为 MCP 服务器的日期时间格式化服务,专为 Claude Desktop 应用设计。它解决的是让模型能够获取当前日期时间并以所需格式返回的问题,支持多种格式,并特别优化了用于生成文件名的格式。

主要能力

  • 支持多种日期时间格式:标准格式、日文格式、ISO 格式等。
  • 支持日文语言。
  • 提供针对文件名生成优化的格式。
  • 准确的时区处理。
  • 与 Claude Desktop 应用无缝集成。

服务器实现了一个工具:

  • get_datetime:获取当前日期和时间,支持多种格式。接受必填的字符串参数 "format",返回基于指定格式的日期时间字符串。支持的格式类型包括标准、日文和 ISO 格式。

命令格式示例:

  • 标准日期时间格式:call datetime-service.get_datetime {"format": "datetime"},结果示例:2024-12-10 00:54:01
  • 日文格式:call datetime-service.get_datetime {"format": "datetime_jp"},结果示例:2024年12月10日 00時54分01秒
  • 文件名格式:call datetime-service.get_datetime {"format": "filename_md"},结果示例:20241210005401.md

使用方式

前置条件

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

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

与 Claude Desktop 应用配合使用

在配置文件中添加相应配置。配置文件位置(macOS):~/Library/Application Support/Claude/claude_desktop_config.json

手动安装

如果需要直接安装该包(例如用于开发或查看源代码),可以使用以下方法之一:

  • 从 PyPI 安装:pip install mcp-datetime
  • 从 GitHub 源代码安装: git clone https://github.com/ZeparHyfar/mcp-datetime.git cd mcp-datetime pip install -e .

手动安装的 claude_desktop_config.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"。

Claude Desktop 应用提示词示例

用户:请用 date_slash 格式告诉我当前时间 Claude:我将以 date_slash 格式获取当前日期。当前日期是 2024/12/12

调试

由于 MCP 服务器通过 stdio 运行,调试可能比较困难。推荐使用 MCP Inspector:

  • 使用 PyPI 包:npx @modelcontextprotocol/inspector uvx mcp-datetime
  • 使用从 GitHub 下载的源代码: git clone https://github.com/ZeparHyfar/mcp-datetime.git npx @modelcontextprotocol/inspector uvx --directory ./mcp-datetime run mcp-datetime

适用场景和限制

适用于需要在 Claude Desktop 中获取格式化日期时间字符串、生成带时间戳的文件名等场景。限制:该包仅在 macOS 上测试过,Windows 兼容性尚未验证。支持的具体格式列表在提供的资料中未完整列出。该项目采用 MIT 许可证。