工时记录服务

一个用于记录工时到Insider系统的MCP服务器,支持项目列表查看、工时记录和无效工作日检查。

  • by saigontechnology
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 saigontechnology/logtime-mcp

使用说明

时间表MCP服务器

用于将时间记录到Insider系统的MCP(模型上下文协议)服务器。

特性

  • 列出用户可用的所有项目
  • 记录不同费率和活动的特定项目的时间条目
  • 列出不符合8小时工作时间要求的无效天数

设置

先决条件

  • Python 3.10或更高版本
  • MCP框架(pip install mcp)
  • 拥有API访问权限的Insider帐户

环境变量

在运行服务器之前设置以下环境变量:

export INSIDER_AUTH_TOKEN="your-bearer-token-here"
export INSIDER_USER_ID="your-user-id"
export INSIDER_EMP_CODE="your-employee-code"

安装

  1. 克隆此存储库
  2. 安装软件包:
pip install -e .

用法

运行服务器

python -m timesheet_mcp

工具:list_projects

列出用户可用的所有项目。

{
  "name": "list_projects",
  "arguments": {}
}

答复:

{
  "projects": [
    {
      "id": 10522,
      "name": "Project Name"
    },
    ...
  ]
}

工具:log_time_project

记录特定项目的时间。

{
  "name": "log_time_project",
  "arguments": {
    "projectId": 10522,
    "hours": 4,
    "logDates": ["2025-05-29"],
    "hourRate": 1.5,
    "activity": 1,
    "comment": "Working on feature X"
  }
}

参数:

  • projectId (必填):list_projects中的项目ID
  • hours (必填):记录的小时数(0.5到8之间)
  • logDates (必填):以YYYY-MM-DD格式记录时间的日期列表
  • hourRate (可选,默认值:1):小时费率(正常1,加班工作日2,加班周末3,加班假期4)
  • activity (可选,默认值:1):活动类型(1代表代码,2代表测试)
  • comment (可选):时间输入的注释

答复:

{
  "success": true,
  "message": "Time logged successfully",
  "details": {
    "status": "success"
  }
}

工具:list_invalid_hays

列出不符合特定月份所需8小时工作时间的所有无效日期。

{
  "name": "list_invalid_days",
  "arguments": {
    "year": 2025,
    "month": 9
  }
}

参数:

  • year (必填):检查年份(2020年至当前年份+1)
  • month (必填):检查月份(1-12)

响应:返回一个markdown格式的报告,显示:

  • 无效天数总计
  • 对于每个无效日:
    • 日期和当前记录小时数与预期小时数
    • 小时数不足
    • 工作日状态和假期状态
    • 详细的无效消息
    • 包含项目名称和小时数的当前日志条目

输出示例:

# Invalid Days for 2025-09

**Total Invalid Days:** 2

## 2025-09-03
- **Current Hours:** 6.0h
- **Expected Hours:** 8.0h
- **Shortfall:** 2.0h
- **Working Day:** Yes
- **Holiday:** No
- **Issue:** This is normal working day so there should be exact 8 hours log time with hour rate 1.0 in this day.
- **Current Log Entries:**
  - AxiaGram: 6.0h (Working on feature)

## 2025-09-04
- **Current Hours:** 0.0h
- **Expected Hours:** 8.0h
- **Shortfall:** 8.0h
- **Working Day:** Yes
- **Holiday:** No
- **Issue:** This is normal working day so there should be exact 8 hours log time with hour rate 1.0 in this day.
- **Current Log Entries:** None

测试

运行单元测试

uv run python -m unittest tests.timesheet_mcp_test -v

使用测试客户端进行手动测试

# List projects
uv run python test_client.py list_projects

# Log time to a project
uv run python test_client.py log_time 10522 8 2025-09-17 1 1 "Working on new feature"

# List invalid days for a specific month
uv run python test_client.py list_invalid_days 2025 9

手动逻辑测试

# Test the filtering logic without hitting the real API
uv run python manual_test.py

许可证

麻省理工学院