任务管理协议服务器

一个基于MCP协议的Google Tasks服务接口,允许AI助手通过标准化协议管理任务列表和任务项。

  • by overlay-one
  • JavaScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 overlay-one/google-tasks-mcp-server

使用说明

谷歌任务MCP服务器

用于Google任务的模型上下文协议(MCP)服务器,允许AI助手通过MCP协议与Google任务交互。

特性

  • 列出、创建、更新和删除任务列表
  • 列出、搜索、创建、更新、删除和移动任务
  • 具有父子关系的任务组织
  • 查看详细任务信息
  • 清除已完成的任务
  • 带有自动令牌刷新的OAuth2身份验证
  • API并行请求提高性能
  • 用于类型安全的TypeScript接口
  • 全面的错误处理
  • 通过MCP与AI助手集成

安装

# Clone the repository
git clone https://github.com/overlay-one/google-tasks-mcp-server.git
cd google-tasks-mcp-server

# Install dependencies
pnpm install

# Build the project
pnpm build

配置

设置Google Cloud API访问

  1. 在中创建项目 谷歌云控制台.
  2. 启用Google任务API:
    • 导航到API库
    • 搜索“任务API”
    • 点击“启用”
  3. 创建OAuth 2.0凭据:
    • 导航到“凭据”
    • 点击“创建凭据”并选择“OAuth客户端ID”
    • 选择“Web应用程序”作为应用程序类型
    • 添加您的重定向URI (例如, http://localhost:3000/oauth2callback)
    • 创建后,记下您的客户端ID和客户端密码

环境配置

  1. 复制 .env.example 向 .env:
cp .env.example .env
  1. 编辑 .env 使用您的Google API证书提交文件:
# Required credentials
CLIENT_ID=your-client-id
CLIENT_SECRET=your-client-secret
REDIRECT_URI=http://localhost:3000/oauth2callback

# Optional tokens (if you already have them)
# ACCESS_TOKEN=your-access-token
# REFRESH_TOKEN=your-refresh-token

# Optional server configuration
# LOG_LEVEL=info     # Options: error, warn, info, debug

身份验证方法

服务器支持两种身份验证方法:

  1. 环境变量:在.env文件中设置ACCESS_TOKEN和REFRESH_TOKEN
  2. 凭据文件:服务器可以将令牌存储在 .credentials.json 文件

服务器包括自动令牌刷新处理。当访问令牌过期时,服务器将:

  1. 自动使用刷新令牌获取新的访问令牌
  2. 更新内存中的凭据
  3. 将更新的令牌保存到 .credentials.json (如果使用基于文件的存储)

用法

启动服务器

# Production mode
pnpm start

# Development mode (with auto-reloading)
pnpm dev

与Claude Desktop一起使用

Claude Desktop可以与此MCP服务器集成,直接访问Google Tasks。这种集成允许您通过与Claude的自然语言对话来管理您的任务。

在Google任务中使用Claude的好处

  • 自然语言任务管理:使用日常语言创建、搜索和组织任务
  • 情境理解:克劳德明白你说“明天”或“下周”是什么意思
  • 任务优先级协助:向克劳德寻求帮助,组织和安排任务的优先级
  • 智能搜索:使用上下文和含义查找任务,而不仅仅是精确的关键字
  • 批量操作:请Claude帮助您一次创建或修改多个任务
  • 日程安排协助:Claude可以根据您现有的任务建议最佳截止日期
  • 任务总结:在多个列表中获得任务的简明摘要
  • 日计划:让克劳德根据你当前的任务来帮助你规划一天

安装说明

以下是如何设置集成:

  1. 启动Google Tasks MCP服务器:

    pnpm start
    

    服务器将在标准输入/输出通道(stdio)上运行。

  2. 使用MCP服务器连接启动Claude Desktop:

    claude mcp --command "node /path/to/google-tasks-mcp-server/dist/index.js"
    

    替换 /path/to/google-tasks-mcp-server 安装的实际路径。

  3. 备选方案:创建配置文件: 创建一个名为的文件 claude.yaml 在主目录或项目目录中:

    mcp:
      command: node /path/to/google-tasks-mcp-server/dist/index.js
    

    然后简单地运行 claude 使用已配置的MCP服务器。

  4. 克劳德桌面内部: 连接后,Claude将可以通过自定义MCP资源和工具访问您的Google任务。你可以要求克劳德:

    • “显示我的任务列表”
    • 创建一个名为“完成项目报告”的新任务
    • “查找与会议相关的所有任务”
    • “将我的‘审阅文档’任务标记为已完成”

Claude将根据您的请求使用MCP服务器访问您的Google任务数据。

与克劳德的对话示例

以下是一些连接后您可以与Claude进行的示例对话:

列出任务:

You: Show me all my tasks
Claude: I'll retrieve your tasks from Google Tasks.
[Claude uses task.list tool]
Here are your current tasks:
- Complete project documentation (Due: 2025-05-10)
- Schedule team meeting (Due: Not set)
- Review quarterly report (Due: 2025-05-15)

创建任务:

You: Create a new task called "Send follow-up email" due tomorrow at 3 PM
Claude: I'll create that task for you.
[Claude uses task.create tool]
I've created a new task:
Title: Send follow-up email
Due: 2025-05-06T15:00:00Z
Status: needsAction

搜索任务:

You: Find all tasks related to "meeting"
Claude: I'll search for tasks containing "meeting".
[Claude uses task.search tool]
I found 2 tasks related to "meeting":
- Schedule team meeting (Due: Not set)
- Prepare meeting agenda (Due: 2025-05-08)

管理任务列表:

You: Create a new task list called "Personal Projects"
Claude: I'll create that task list for you.
[Claude uses tasklist.create tool]
I've created a new task list named "Personal Projects".
Would you like me to add any tasks to this list?

高级使用场景

以下是一些将Claude用于Google任务的高级方法:

项目规划

You: I need to plan a website launch. Can you help me create tasks for it?
Claude: I'd be happy to help plan your website launch. Let me create a task list and relevant tasks.
[Claude uses tasklist.create and task.create tools]
I've created a new task list "Website Launch" with the following tasks:
1. Finalize website content (Due: 1 week from now)
2. Complete design review (Due: 10 days from now)
3. Run final QA tests (Due: 2 weeks from now)
4. Prepare marketing materials (Due: 2 weeks from now)
5. Configure analytics (Due: 3 days before launch)
6. Launch website (Due: 3 weeks from now)
Would you like me to add more specific tasks?

任务组织和优先级

You: I have too many tasks. Can you help me prioritize them?
Claude: I'll help you organize and prioritize your tasks.
[Claude uses task.list tool]
Based on your current tasks, here's a suggested prioritization:

High Priority (Complete today):
- Submit quarterly report (Due: Today)
- Call client about project delay (Due: Today)

Medium Priority (Complete this week):
- Prepare presentation (Due: In 3 days)
- Review team metrics (Due: In 5 days)

Low Priority (Can be scheduled later):
- Research new tools (Due: Next week)
- Update documentation (Due: In 2 weeks)

Would you like me to update the due dates to reflect these priorities?

常规任务管理

You: What tasks should I focus on today?
Claude: Let me check your tasks due today or overdue.
[Claude uses task.list and task.search tools]
Here are the tasks you should focus on today:

Due Today:
- Prepare client meeting agenda
- Submit expense report

Overdue:
- Follow up on pending approvals (Due yesterday)

Upcoming Soon:
- Project proposal draft (Due tomorrow)

Should I mark any of these as completed?

克劳德桌面集成故障排除

如果您在将Claude Desktop连接到Google Tasks MCP服务器时遇到问题:

  1. 身份验证问题:

    • 确保您的 .env 文件具有正确的 CLIENT_ID, CLIENT_SECRET,以及 REDIRECT_URI
    • 检查您在中是否有有效的刷新令牌 .env 或在 .credentials.json
    • 如果需要,通过Google OAuth流程重新生成令牌
  2. 连接问题:

    • 验证服务器是否正在运行 pnpm start 在连接克劳德之前
    • 检查你的路径 claude mcp --command 是正确的
    • 如果使用配置文件,请确保YAML语法有效
  3. 未找到命令:

    • 确保Claude Desktop CLI在您的PATH中
    • 尝试使用Claude可执行文件的完整路径
  4. MCP协议错误:

    • 如果服务器遇到内部错误,通常会出现这些错误
    • 检查服务器日志以了解有关特定错误的详细信息
    • 确保您使用的是兼容版本的Claude Desktop和MCP SDK

api参考

资源

服务器通过自定义URI方案提供资源:

任务列表资源

  • gtasklists:///:列出所有任务列表
  • gtasklists:///{taskListId}:按ID访问特定任务列表

任务资源

  • gtasks:///:列出所有任务列表中的所有任务
  • gtasks:///default:在默认任务列表中列出任务
  • gtasks:///{taskId}:按ID访问特定任务
  • gtasks:///{taskListId}/tasks/{taskId}:访问特定任务列表中的特定任务

工具

服务器通过MCP工具支持以下操作:

任务列表管理

工具 说明 必需参数 可选参数
tasklist.list 列出所有任务列表 无 maxResults
tasklist.get 按ID获取任务列表 id 没有
tasklist.create 创建新任务列表 title 没有
tasklist.update 更新任务列表 id, title 没有
tasklist.delete 删除任务列表 id 没有

任务管理

工具 说明 必需参数 可选参数
task.search 按标题或注释搜索任务 query taskListId
task.list 列出所有任务 无 taskListId, cursor
task.get 按ID获取任务 id taskListId
task.create 创建新任务 title taskListId, notes, due, status, parent
task.update 更新现有任务 id taskListId, title, notes, status, due, parent
task.move 移动任务(更改父项或位置) id taskListId, parent, previous
task.delete 删除任务 id taskListId
task.clear 清除已完成的任务 无 taskListId

示例操作

创建任务

{
  "name": "task.create",
  "arguments": {
    "title": "Complete project documentation",
    "notes": "Include API reference and setup instructions",
    "due": "2025-05-10T00:00:00.000Z",
    "status": "needsAction"
  }
}

搜索任务

{
  "name": "task.search",
  "arguments": {
    "query": "documentation",
    "taskListId": "MTIzNDU2Nzg5MA"
  }
}

发展

项目结构

  • src/index.ts:主服务器实现和MCP协议处理程序
  • src/Tasks.ts:任务和任务列表资源和行动的实施
  • src/types.ts:用于请求/响应处理的TypeScript接口
  • test/:服务器组件的单元测试

TypeScript类型

该项目使用TypeScript接口进行类型安全。关键接口包括:

  • 请求参数类型:所有工具参数类型的TypeScript接口
    • TaskCreateParams, TaskUpdateParams, TaskSearchParams等等。
  • 资源类型:资源表示的接口
    • TaskResource, TaskListResource
  • 公用设施类型:用于使用Google Tasks API的帮助程序类型

这些接口有助于在将参数传递到Google Tasks API和处理响应时确保类型安全。

错误处理

服务器实现了一致的错误处理系统,该系统:

  1. 将HTTP错误代码映射到相应的MCP错误代码
  2. 提供具有操作上下文的详细错误消息
  3. 适当地处理来自并行API调用的错误

性能优化

服务器对涉及多个任务列表的操作使用并行API调用:

  • 在……里面 TaskResources.list() 和 TaskActions._list(),并行提取多个列表中的任务
  • 即使某些任务列表请求失败,结果也会正确组合
  • 这大大提高了具有许多任务列表的用户的性能

测试

该项目包括一个使用Node.js内置测试运行器的测试框架:

# Run all tests (this will first build the TypeScript code)
pnpm test

# Run tests in watch mode for development
pnpm test:watch

在首次运行测试之前,您需要确保安装了依赖项:

pnpm install

测试套件包括:

  • 身份验证测试:验证令牌刷新处理
  • 任务操作测试:验证任务API功能
  • 错误处理测试:确保正确处理错误

测试是用JavaScript编写的,并针对编译的TypeScript代码运行,确保生产代码按预期工作。测试是为了使用模拟的依赖关系而设计的,因此在测试过程中不会进行真正的Google API调用。

建筑

pnpm build

以开发模式运行

pnpm dev

许可证

阿帕奇-2.0