使用说明
时钟化MCP服务器
模块化模型上下文协议(MCP)服务器,用于与Clockify时间跟踪API集成。
安装
来自npm(推荐)
npm install -g clockify-mcp-server
来源
git clone https://github.com/yourusername/clockify-mcp-server.git
cd clockify-mcp-server
npm install
特性
此MCP服务器提供三个工具:
- 之前 -从Clockify API获取当前用户信息
- 获取所有项目 -获取特定工作区的所有项目
- logTimeEntry -使用灵活的时间规范记录时间条目
建筑
服务器采用模块化架构构建:
src/server.js-主服务器类registerTool接口src/api.js-用于Clockify请求的共享API实用程序src/tools/-具有Zod模式验证的单个工具模块index.js-注册所有工具的入口点
设置
1.设置环境变量
创建一个 .env 使用Clockify API密钥文件或设置环境变量:
export CLOCKIFY_API_KEY=your_api_key_here
您可以从获取API密钥 Clockify设置>API.
2.运行服务器
如果全局安装:
clockify-mcp-server
如果从源代码运行:
npm start
或者用于自动重启的开发:
npm run dev
MCP客户端中的使用
安装后,您可以配置MCP客户端以使用此服务器。例如,在Claude Desktop中:
{
"mcpServers": {
"clockify": {
"command": "clockify-mcp-server",
"env": {
"CLOCKIFY_API_KEY": "your_api_key_here"
}
}
}
}
工具
之前
从Clockify API获取当前用户信息。
参数: 无
例子:
{
"name": "iam"
}
获取所有项目
获取特定工作区的所有项目。
参数:
workspaceId(string,必填):用于获取项目的工作区ID
例子:
{
"name": "getAllProjects",
"arguments": {
"workspaceId": "60c1beaf8747147d9ac70b4b"
}
}
logTimeEntry
在Clockify中记录时间条目。
参数:
date(字符串,必填):YYYY-MM-DD格式的时间输入日期description(string,必填):所执行工作的描述projectId(string,必填):记录时间的项目IDworkspaceId(string,必填):工作区的IDstartTime(字符串,可选):HH:MM格式的开始时间(默认为“09:00”)endTime(字符串,可选):HH:MM格式的结束时间(默认为“17:00”)
例子:
{
"name": "logTimeEntry",
"arguments": {
"date": "2024-01-15",
"description": "Working on project documentation",
"projectId": "662f81c0b682f06d79bff487",
"workspaceId": "60c1beaf8747147d9ac70b4b",
"startTime": "09:30",
"endTime": "12:30"
}
}
获取工作区和项目ID
- 使用
iam获取用户信息和可用工作区的工具 - 使用
getAllProjects使用工作区ID获取项目ID的工具 - 在中使用这些ID
logTimeEntry工具
错误处理
该服务器包括全面的错误处理功能,用于:
- 缺少API密钥或密钥无效
- 日期/时间格式无效
- 缺少必要参数
- API请求失败
- 时间验证(结束时间必须在开始时间之后)
所有错误都会返回描述性消息,以帮助解决问题。
发展
添加新工具
服务器使用干净的 registerTool 界面。要添加新工具,请执行以下操作:
- 在中创建新文件
src/tools/根据您的工具定义:
import { z } from "zod";
import { makeApiRequest } from "../api.js";
export const myNewTool = {
name: "myNewTool",
config: {
title: "My New Tool",
description: "Description of what the tool does",
inputSchema: z.object({
param1: z.string().describe("Description of param1"),
param2: z.number().optional().describe("Optional param2")
})
},
handler: async ({ param1, param2 }) => {
// Your tool logic here
const result = await makeApiRequest("/some-endpoint");
return {
content: [{
type: "text",
text: JSON.stringify(result, null, 2)
}]
};
}
};
- 从导出
src/tools/index.js - 在中注册
index.js:
server.registerTool(
myNewTool.name,
myNewTool.config,
myNewTool.handler
);
服务器自动处理:
- Zod模式验证
- MCP的JSON模式转换
- 错误处理和格式化
- 工具注册和发现
出版
要发布npm更新:
- 更新中的版本
package.json - 跑
npm publish
许可证
麻省理工学院
需求
- Node.js 18.0.0或更高版本
- Clockify API密钥
