Back to MCP directory
publicPublicdnsLocal runtime

mcp-time

一个提供当前时间和计算时间差的MCP服务,支持Windows和macOS平台,通过JSON-RPC接口返回ISO格式时间数据。

article

README

🚀 @dandeliongold/mcp-time

这是一个用于获取当前时间ISO格式(YYYY-MM-DD HH:mm:ss)的MCP服务器,借助JavaScript Date实现。该服务器适用于Claude桌面应用程序,可在Windows和macOS系统上运行。

🚀 快速开始

本项目提供了便捷的时间获取和时间差计算功能,以下是简单的使用说明:

  1. 安装依赖:
npm install @dandelion/mcp-time
  1. 在Claude桌面应用程序的config.json中添加配置:
{
  "modules": {
    "time": {
      "url": "http://localhost:3000",
      "type": "mcp"
    }
  }
}

✨ 主要特性

  • 能够获取当前时间。
  • 可以计算两个时间戳之间的差异。
  • 支持以分钟和秒为单位进行计算。

📦 安装指南

使用以下命令安装本项目:

npm install @dandelion/mcp-time

💻 使用示例

基础用法

getCurrentTime

该工具用于返回当前时间的ISO格式,无需输入参数。 示例JSON-RPC请求:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getCurrentTime"
}

示例JSON-RPC响应:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "time": "2024-02-08 11:04:33",
    "success": true
  }
}

getTimeDifference

该工具用于计算给定时间戳与当前时间之间的差异。 示例JSON-RPC请求:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getTimeDifference",
  "params": {
    "timestamp": "2024-02-08 12:30:00",
    "interval": "minutes"
  }
}

示例JSON-RPC响应:

// 对于过去时间戳(30分钟前)
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "difference": -30,
    "interval": "minutes",
    "inputTimestamp": "2024-02-08 12:30:00",
    "currentTime": "2024-02-08 13:00:00"
  }
}

// 对于未来时间戳(在45分钟后)
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "difference": 45,
    "interval": "minutes",
    "inputTimestamp": "2024-02-08 12:30:00",
    "currentTime": "2024-02-08 13:15:00"
  }
}

📚 详细文档

组件

工具

  1. getCurrentTime
    • 功能:返回当前时间的ISO格式。
    • 参数:无。
    • 返回值
{
  "time": "2024-02-08 11:04:33",
  "success": true
}
  1. getTimeDifference
    • 功能:计算给定时间戳与当前时间之间的差异。
    • 参数
      • timestamp:ISO格式时间戳(YYYY-MM-DD HH:mm:ss)。
      • interval:'分钟'(默认)或 '秒'。
    • 返回值:一个带符号的差异值,遵循以下约定:
      • 正值(+)表示未来时间戳("在X分钟后/秒后")。
      • 负值(-)表示过去时间戳("X分钟后/秒前")。
      • 零(0)表示相同时间戳。

在Claude桌面应用程序中的使用

config.json中添加以下内容:

{
  "modules": {
    "time": {
      "url": "http://localhost:3000",
      "type": "mcp"
    }
  }
}

🔧 技术细节

开发流程

  1. 克隆仓库:
git clone https://github.com/your-username/dandelion.git
cd dandelion/packages/mcp-time
  1. 安装依赖:
npm install
  1. 运行测试:
npm test
  1. 启动开发服务器:
npm start

📄 许可证

此项目受MIT许可证保护。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client