时间条目获取服务

一个基于TypeScript的MCP服务器,用于获取Toggl Track v9时间条目,支持时区感知和单日时间条目查询。

  • by Hiroto0706
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 Hiroto0706/toggl_track_mcp_server

使用说明

toggl跟踪mcp服务器

TypeScript MCP服务器(stdio)公开了获取Toggl Track v9时间条目的工具。

特性

  • 使用Toggl v9获取单日时间条目(/api/v9/me/time_entries).
  • 通过Temporal polyfill(@js Temporal/polyfill)感知时区:
    • 接受任何IANA时区(例如。 Asia/Tokyo, America/New_York).
    • 如果 timezone 省略,使用您的Toggl帐户时区(通过以下方式获取 /api/v9/me),并回退到 UTC.

目录布局

  • src/index.ts –MCP服务器引导(注册工具)
  • src/tools/ –工具实施
    • ping.ts
    • get_time_entries_for_date.ts
    • check_auth.ts
  • src/toggl/ –Toggl API客户端
    • get.ts (fetchTimeEntries ForDateV9,fetchMe)
  • src/utils/ –公用事业
    • config.ts (env加载器)
    • date.ts (基于时间的日范围)
  • src/schemas/ –Zod和共享类型
    • date.ts, toggl.ts, tools.ts

环境

  1. 复制 .env.template 到 .env 并设定值:
cp .env.template .env

必需

  • TOGGL_API_TOKEN

备注

  • .env 通过以下方式自动加载 dotenv/config.
  • 您还可以通过MCP客户端环境传递令牌。

构建

npm i
npm run build

运行(stdio)

node dist/index.js --transport stdio

与Claude Desktop一起使用

添加 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "toggl-track": {
      "command": "/opt/homebrew/bin/node",
      "args": [
        "--enable-source-maps",
        "/Users/yourname/path/to/toggl-track-mcp-server/dist/index.js",
        "--transport",
        "stdio"
      ],
      "env": {
        "TOGGL_API_TOKEN": "YOUR_TOKEN",
        "TZ": "Asia/Tokyo"
      }
    }
  }
}

与MCP检查器一起使用

npx @modelcontextprotocol/inspector
  • 添加服务器→ Stdio
    • 命令: node (或绝对节点路径)
    • Args: /path/to/dist/index.js --transport stdio
    • 环境: TOGGL_API_TOKEN=..., TZ=Asia/Tokyo

工具

  • ping

    • 退货 ok.
  • check_auth

    • 通过验证令牌 /api/v9/me 并返回一个掩码摘要。
    • 参数:无(使用 TOGGL_API_TOKEN 来自env)。
  • get_time_entries_for_date

    • 获取单个日期的v9时间条目。
    • 参数(JSON):
      • date (字符串,可选;接受 YYYY-MM-DD, YYYY/MM/DD, 今日, 昨日, 一昨日;省略表示今天)
      • timezone (字符串,IANA;可选→ 使用帐户时区;后备方案 UTC)
      • apiToken (string;env的可选覆盖)
    • 返回值(JSON):
      • { meta: { source: 'v9', date, timezone, startUTC, endUTC, count }, entries: [...] }

备注

  • 此项目使用节点ESM module: nodenext.用以下方式写入相对进口 .js 源代码中的扩展。
  • 时区数学使用Temporal via @js-temporal/polyfill.