任务图MCP服务器
实际工作的代理任务工作流。
当你让人工智能代理处理复杂的任务时,事情很快就会出错。代理失去上下文,跳过步骤,忘记协调。任务图通过结构化的工作流解决了这个问题:指导工作的阶段、自动指导的提示、强制质量的门以及多代理场景的协调原语——所有这些都通过模型上下文协议实现。
为什么是任务图?
问题:你有复杂的任务需要结构化执行。可能是单个代理分阶段工作,也可能是多个代理并行协调。如果没有适当的工作流程,代理会失去跟踪、跳过步骤并产生不一致的结果。
你得到了什么:
- 结构化工作流 --阶段(探索、实施、审查、测试)指导代理完成工作。过渡提示在每个步骤提供自动指导。
- 质量门 --要求在转换之前通过测试、提交代码或完成审查。自动执行您的标准。
- 即用型拓扑 --为单人工作、平行集群、专业中继或分层委托预先构建的工作流程。立即开始,稍后自定义。
- 可配置的工作流 --定义自己的状态、阶段、提示和门。匹配你的流程,而不是我们的。
- 多智能体协调 --咨询文件锁、DAG依赖关系、原子声明。不再有冲突或重复工作。
- 代币高效 --专为LLM上下文限制而设计。紧凑的查询、最少的往返、结构化的输出。
- 内置会计 --跟踪每个任务的令牌、成本和时间。确切地知道你的代理人在花什么。
- 零基础设施 --带WAL模式的SQLite。没有要运行的数据库服务器。只需指向一个文件。
特性
| 特性 | 描述 |
|---|---|
| 任务层次结构 | 与父母/子女关系无限嵌套 |
| DAG依赖关系 | 带循环检测的键入边(块、跟随、包含) |
| 阶段 | 对工作类型进行分类(探索、实施、审查、测试、部署) |
| 工作流 | 命名工作流拓扑(单独、集群、中继、分层) |
| 过渡提示 | 状态/相位变化的自动代理指导 |
| 大门 | 状态/阶段转换的退出要求 |
| 原子能索赔 | 严格锁定限制和基于标签的路由 |
| 文件协调 | 带有原因的咨询锁和更改轮询 |
| 成本跟踪 | 令牌使用量和每项任务的美元成本 |
| 时间追踪 | 状态转换的自动累积 |
| 实时状态 | 其他代理可见的实时“当前想法” |
| 全文搜索 | 基于FTS5的跨任务和附件搜索 |
| 附件 | 内联内容、文件引用或媒体存储 |
| 代理商反馈 | 具有分类反馈的代理间通信(取决于配置) |
| 动态覆盖 | 通过添加/删除覆盖工具自定义运行时工作流 |
快速开始
# Install
cargo install task-graph-mcp
# Add to your MCP client (Claude Code, etc.){
"mcpServers": {
"task-graph": {
"command": "task-graph-mcp"
}
}
}# Agent workflow (worker_id auto-generated if omitted)
connect(workflow="swarm", tags=["code"]) → "bright-lunar-swift-fox"
list_tasks(ready=true, agent="bright-lunar-swift-fox") → claimable work
claim(worker_id="bright-lunar-swift-fox", task="add-auth") → you own it
update(..., phase="implement") → enter implementation phase
thinking(agent="bright-lunar-swift-fox", thought="Adding JWT...") → visible to others
update(worker_id="bright-lunar-swift-fox", task="add-auth",
status="completed",
attachments=[{type:"commit", content:"abc123"}]) → done安装
来自crates.io(推荐)
cargo install task-graph-mcp预构建二进制文件
从以下网址下载适用于您平台的最新版本 :
| 平台 | 下载 |
|---|---|
| Linux(x64) | task-graph-mcp-x86_64-unknown-linux-gnu.tar.gz |
| macOS(英特尔) | task-graph-mcp-x86_64-apple-darwin.tar.gz |
| macOS(苹果硅) | task-graph-mcp-aarch64-apple-darwin.tar.gz |
| Windows(x64) | task-graph-mcp-x86_64-pc-windows-msvc.zip |
提取二进制文件并将其放置在PATH中。
源自源头
git clone https://github.com/Oortonaut/task-graph-mcp.git
cd task-graph-mcp
cargo build --release二进制文件将位于 target/release/task-graph-mcp.
用法
作为MCP服务器
添加到MCP客户端配置中:
{
"mcpServers": {
"task-graph": {
"command": "task-graph-mcp",
"args": []
}
}
}CLI选项
task-graph-mcp [OPTIONS]
Options:
-c, --config Path to configuration file
-d, --database Path to database file (overrides config)
-v, --verbose Enable verbose logging
-h, --help Print help
-V, --version Print version配置
全参考:参见 docs/CONFIGURATION.md 获取完整的配置文档,包括工作流、提示、门、角色和标签。
创建 .task-graph/config.yaml:
server:
db_path: .task-graph/tasks.db
media_dir: .task-graph/media # Directory for file attachments
skills_dir: .task-graph/skills # Custom skill overrides
stale_timeout_seconds: 900
default_format: json # or markdown
paths:
style: relative # or project_prefixed
auto_advance:
enabled: false # Auto-transition unblocked tasks
target_state: ready # Target state (requires custom state in states config)状态配置
任务状态是可配置的。默认状态: pending, working, completed, failed, cancelled.
要添加 ready 自动前进状态:
states:
initial: pending
disconnect_state: pending # State for tasks when owner disconnects (must be untimed)
blocking_states: [pending, working]
definitions:
pending:
exits: [ready, working, cancelled]
ready:
exits: [working, cancelled]
working:
exits: [completed, failed, pending]
timed: true # Time in this state counts toward time_actual_ms
completed:
exits: []
failed:
exits: [pending]
cancelled:
exits: []
auto_advance:
enabled: true
target_state: ready看 SCHEMA.md 关于州定义的完整文档。
依赖关系配置
依赖类型定义了任务之间的相互关系。默认类型: blocks, follows, contains, duplicate, see-also, relates-to.
dependencies:
definitions:
blocks:
display: horizontal # Same-level relationship
blocks: start # Blocks claiming the dependent task
follows:
display: horizontal
blocks: start
contains:
display: vertical # Parent-child relationship
blocks: completion # Blocks completing the parent
duplicate:
display: horizontal
blocks: none # Informational only
see-also:
display: horizontal
blocks: none
relates-to:
display: horizontal
blocks: none| 属性 | 值 | 描述 |
|---|---|---|
display | horizontal, vertical | 视觉关系(同级vs亲子) |
blocks | none, start, completion | 依赖性阻碍了什么 |
附件配置
预配置的附件密钥提供默认的MIME类型和模式,减少了附加常见内容类型时的样板。
attachments:
unknown_key: warn # allow | warn (default) | reject
definitions:
commit:
mime: text/git.hash
mode: append
checkin:
mime: text/p4.changelist
mode: append
meta:
mime: application/json
mode: replace
note:
mime: text/plain
mode: append| 属性 | 值 | 描述 |
|---|---|---|
unknown_key | allow, warn, reject | 未定义附件键的行为 |
definitions..mime | MIME类型字符串 | 此密钥的默认MIME类型 |
definitions..mode | append, replace | 默认模式(追加保持现有,替换覆盖) |
内置默认值:
| 关键字 | MIME类型 | 模式 | 用例 |
|---|---|---|---|
commit | text/git.hash | append | git提交哈希 |
checkin | text/p4.changelist | append | 执行更改列表 |
changelist | text/plain | append | 文件已更改 |
meta | application/json | 替换 | 结构化元数据 |
note | text/plain | append | 一般注释 |
log | text/plain | append | 日志输出 |
error | text/plain | append | 错误消息 |
output | text/plain | append | 命令/工具输出 |
diff | text/x-diff | append | 补丁和差异 |
plan | text/markdown | 替换 | 计划和规格 |
result | application/json | 替换 | 结构化结果 |
context | text/plain | 替换 | 当前上下文/状态 |
用法:
# MIME and mode auto-filled from config:
attach(task="123", name="commit", content="abc1234")
# → mime=text/git.hash, mode=append
attach(task="123", name="meta", content='{"v":1}')
# → mime=application/json, mode=replace (overwrites existing meta)
# Explicit values override defaults:
attach(task="123", name="commit", mime="text/plain", content="override")环境变量:
TASK_GRAPH_CONFIG_PATH:配置文件的路径(优先于.task-graph/config.yaml)TASK_GRAPH_DB_PATH:数据库文件路径(如果没有配置文件,则回退)TASK_GRAPH_MEDIA_DIR:文件附件的媒体目录(如果没有配置文件,则回退)TASK_GRAPH_LOG_DIR:日志目录路径(如果没有配置文件,则回退)
MCP工具
工人管理
| 工具 | 说明 |
|---|---|
connect(worker_id?, tags?, workflow?, force?, db_path?, media_dir?, log_dir?, config_path?, overlays?: str[]) | 注册一名工人。可选的 workflow 选择命名工作流(单独、群集、中继、分层)。退货 worker_id 并且活跃 paths. |
disconnect(worker_id: worker_str, final_status?: status_str = "pending") | 注销worker并释放所有声明/锁。 |
list_agents(tags?: str[], file?: filename, task?: task_str, depth?: int, stale_timeout?: int) | 使用筛选器列出已连接的工作者。 |
cleanup_stale(timeout?: int, final_status?: status_str) | 开除不称职的员工,并释放他们的索赔。 |
add_overlay(worker_id: str, overlay: str) | 为已连接的工作者添加动态工作流覆盖。 |
remove_overlay(worker_id: str, overlay: str) | 从连接的worker中删除工作流覆盖。 |
任务CRUD
| 工具 | 说明 |
|---|---|
create(description: str, id?: task_str, parent?: task_str, priority?: int = 5, points?: int, time_estimate_ms?: int, tags?: str[]) | 创建任务。优先级0-10(较高=更重要)。 |
create_tree(tree, parent?, child_type?, sibling_type?) | 创建嵌套任务树。 child_type (默认值:“包含”)为父级→儿童deps, sibling_type 对于兄弟姐妹deps。 |
get(task: task_str) | 使用附件元数据和计数按ID获取任务。 |
list_tasks(status?: status_str[], ready?: bool, blocked?: bool, claimed?: bool, owner?: worker_str, parent?: task_str, recursive?: bool, agent?: worker_str, tags_any?: str[], tags_all?: str[], sort_by?: str, sort_order?: str, limit?: int, offset?: int) | 使用筛选器查询任务。使用 ready=true 对于可索赔的任务。 |
update(worker_id: worker_str, task: task_str, status?: status_str, phase?: str, assignee?: worker_str, title?: str, description?: str, priority?: int, points?: int, tags?: str[], needed_tags?: str[], wanted_tags?: str[], time_estimate_ms?: int, reason?: str, force?: bool, attachments?: object[]) | 更新任务。状态/阶段更改自动管理所有权并触发提示。包含 attachments 记录提交/更改列表。 |
delete(worker_id: worker_str, task: task_str, cascade?: bool, reason?: str, obliterate?: bool, force?: bool) | 删除任务。默认软删除; obliterate=true 永久。 |
scan(task: task_str, before?: int, after?: int, above?: int, below?: int) | 从多个方向扫描任务图。深度:0=无,N=水平,-1=全部。 |
search(query: str, limit?: int = 20, include_attachments?: bool, status_filter?: status_str) | FTS5搜索。支持短语、前缀\*、AND/OR/NOT、标题:单词。 |
rename(worker_id: worker_str, task: task_str, new_id: task_str) | 在所有引用表中原子重命名任务ID。 |
任务索赔
| 工具 | 说明 |
|---|---|
claim(worker_id: worker_str, task: task_str, force?: bool) | 申请一项任务。如果deps不满意、达到极限或缺少标签,则失败。使用 force 偷窃。 |
备注:通过发布 update(status="pending").通过完成 update(status="completed")。状态更改自动管理所有权。
依赖项
| 工具 | 说明 | ||
|---|---|---|---|
| `link(from: task_str\ | task_str[], to: task_str\ | task_str[], type?: dep_str = "blocks")` | 创建依赖关系。类型:块、跟随、包含、重复,另请参见,相关 |
| `unlink(from: task_str\ | "*", to: task_str\ | "*", type?: dep_str)` | 删除依赖项。使用 * 作为通配符。 |
relink(prev_from: task_str[], prev_to: task_str[], from: task_str[], to: task_str[], type?: dep_str = "contains") | 原子移动依赖关系(先取消链接,然后再链接)。 |
追踪
| 工具 | 说明 | |
|---|---|---|
thinking(worker_id: worker_str, thought: str, tasks?: task_str[]) | 直播状态。对其他工人可见。恢复心跳。 | |
task_history(task: task_str, states?: status_str[]) | 通过时间跟踪获取状态转换历史记录。 | |
project_history(from?: datetime_str, to?: datetime_str, states?: status_str[], limit?: int = 100) | 带有日期范围过滤器的项目范围历史记录。 | |
log_metrics(worker_id: worker_str, task: task_str, cost_usd?: float, values?: int[8]) | 记录指标(汇总)。 | |
| `get_metrics(task: task_str\ | task_str[])` | 获取任务的指标。 |
give_feedback(message: str, category?: str, sentiment?: str, agent_id?: str, tool_name?: str, task_id?: str) | 记录有关工具、工作流程或用户体验的反馈。默认启用;拒绝超过大小限制的写入(默认值:1MB)。 | |
list_feedback() | 阅读反馈标记文件。 |
文件协调
| 工具 | 说明 | ||
|---|---|---|---|
| `mark_file(worker_id: worker_str, file: filename\ | filename[], task?: task_str, reason?: str)` | 标记文件以表示意图。咨询,非阻塞。 | |
| `unmark_file(worker_id: worker_str, file?: filename\ | filename[]\ | "*", task?: task_str, reason?: str)` | 去除标记。使用 * 为了所有人。 |
list_marks(files?: filename[], worker_id?: worker_str, task?: task_str) | 获取当前文件标记。 | ||
mark_updates(worker_id: worker_str) | 轮询自上次通话以来的标记更改。 |
附件
| 工具 | 说明 | |
|---|---|---|
| `attach(task: task_str\ | task_str[], name: str, content?: str, mime?: mime_str, file?: filename, store_as_file?: bool, mode?: str)` | 添加附件。使用 file 作为参考, store_as_file 用于媒体存储。 |
attachments(task: task_str, name?: str, mime?: mime_str) | 获取附件元数据。名称支持Glob模式。 | |
detach(worker_id: worker_str, task: task_str, name: str, delete_file?: bool) | 按名称删除附件。 |
高级
| 工具 | 说明 |
|---|---|
check_gates(task: task_str) | 在状态/相位转换之前检查闸门要求。返回未满足的门,状态为通过/警告/失败。 |
get_advisory(topic?: str, task?: task_str, worker_id?: worker_str) | 获取治理咨询指导。无主题:列出所有主题。使用topic:通过模板扩展返回完整的咨询内容。 |
query(sql: str, params?: str[], limit?: int = 100, format?: str) | 执行只读SQL。仅选择。需要许可。 |
get_schema(table?: str, include_sql?: bool) | 获取数据库架构。返回表名、列、类型和外键。 |
get_prompts(status?: str, phase?: str, task?: task_str, worker_id?: worker_str) | 获取工作流提示。没有参数:列表触发器。使用状态/阶段:返回该转换的扩展提示。 |
list_workflows() | 列出可用的工作流配置(单独、群集、中继、分层等)。 |
list_skills() | 列出可用的捆绑技能及其描述。 |
get_skill(name: str) | 获取捆绑技能的全部内容。 |
MCP资源
| URI | 描述 |
|---|---|
query://tasks/all | 带有依赖关系的完整任务图 |
query://tasks/ready | 准备索赔的任务 |
query://tasks/blocked | 被依赖项阻止的任务 |
query://tasks/claimed | 所有声称的任务 |
query://tasks/agent/{id} | 代理拥有的任务 |
query://tasks/tree/{id} | 所有子代的任务 |
query://files/marks | 所有文件标记 |
query://agents/all | 注册代理人 |
query://stats/summary | 汇总统计数据 |
config://current | 一次响应中的所有配置 |
config://states | 任务状态定义 |
config://phases | 阶段定义 |
config://dependencies | 依赖类型定义 |
config://tags | 标签定义 |
docs://index | 列出所有可用的文档文件 |
docs://search/{query} | 文档全文搜索 |
docs://skills/list | 列出可用技能 |
docs://skills/{name} | 获取特定技能内容 |
docs://workflows/list | 列出可用工作流 |
docs://workflows/{name} | 获取工作流详细信息 |
docs://overlays/list | 列出可用覆盖层 |
docs://overlays/{name} | 获取叠加细节 |
docs://{path} | 具体文档文件内容 |
任务树结构
使用创建分层任务 create_tree:
{
"tree": {
"title": "Implement auth",
"children": [
{ "title": "Design schema" },
{ "title": "Write migrations" },
{ "title": "Implement endpoints", "children": [
{ "title": "Login endpoint" },
{ "title": "Logout endpoint" },
{ "title": "Refresh endpoint" }
]},
{ "title": "Write tests" }
]
},
"sibling_type": "follows"
}树节点字段
| 字段 | 描述 |
|---|---|
title | 任务标题(新任务需要) |
description | 任务描述 |
id | 自定义任务ID(如果省略,则生成UUID 7) |
ref | 按ID引用现有任务(设置时忽略其他字段) |
priority | 优先级0-10(默认值5) |
points | 故事点/复杂性估计 |
time_estimate_ms | 估计持续时间(毫秒) |
tags | 任务的分类标签 |
needed_tags | 代理人必须拥有所有这些标签才能索赔(AND) |
wanted_tags | 代理人必须至少拥有其中一个标签才能索赔(或) |
children | 嵌套子节点 |
顶层参数
| 参数 | 默认值 | 说明 |
|---|---|---|
tree | 必需 | 任务树的根节点 |
parent | null | 将树根附加到现有父任务 |
child_type | “包含” | 从父级到子级的依赖关系类型 |
sibling_type | null | 兄弟姐妹之间的依赖类型(“follows”表示顺序,null表示并行) |
引用现有任务
使用 ref 将现有任务整合到树结构中:
{
"tree": {
"title": "Sprint 5",
"children": [
{ "title": "New feature" },
{ "ref": "existing-task-id" },
{ "title": "Another task" }
]
},
"sibling_type": "follows"
}基于标签的亲和力
连接时,工人通过标签声明能力。任务可能需要特定的标签来控制哪些工人可以领取它们。
标签类别示例:
- 模型功能:
image-in,audio-out,video-in,code,bulk - 访问级别:
prod-access,admin,external - 专业:
rust,python,frontend,database
*注意:协调员/审阅者/部署者等角色最好使用阶段来表示。*
任务要求:
needed_tags(AND):代理人必须拥有所有这些wanted_tags(或):代理人必须至少有一个
{
"title": "Analyze screenshot and generate code",
"needed_tags": ["image-in", "code"],
"wanted_tags": ["bulk"]
}{
"title": "Deploy to production",
"phase": "deploy",
"needed_tags": ["prod-access"],
"wanted_tags": ["aws", "gcp"]
}工作流程和阶段
阶段
任务可以有 phase 对正在执行的工作类型进行分类:
{
"title": "Add authentication",
"phase": "implement"
}内置阶段: explore, implement, review, test, security, deploy, triage, diagnose, design, plan, doc, integrate, monitor, optimize
阶段实现:
- 过渡提示 --进入/退出阶段时的自动引导
- 大门 --相变前必须满足的要求
- 基于角色的路由 --在中继工作流程中,专家拥有特定的阶段
命名工作流
预构建的工作流拓扑针对不同的协调模式进行了优化:
| 工作流 | 描述 | 最适合 |
|---|---|---|
solo | 单代理,完全自主 | 简单任务,原型制作 |
swarm | 并行多面手,基于拉取 | 高吞吐量,独立任务 |
relay | 连续专家、交接 | 复杂任务、领域专业知识 |
hierarchical | 领导/工人代表团 | 大型项目,团队协调 |
push | 基于推送的任务分布拓扑 | 集中分配、负载平衡 |
kanban | 具有WIP限制的板式任务管理 | 连续流程,视觉跟踪 |
sprint | 时间框迭代计划 | Scrum团队,固定节奏 |
在连接时选择工作流:
connect(worker_id="agent-1", workflow="swarm")每个工作流程都提供量身定制的提示和协调指导。看 工作流程_拓扑.md 查看详细图案。
过渡提示
当状态或阶段发生变化时,代理会收到自动指导:
# workflows.yaml
states:
working:
prompts:
enter: |
You are now working on this task.
From {{current_status}} you can transition to: {{valid_exits}}
exit: |
Before leaving:
- [ ] Attach results
- [ ] Log costs提示支持模板变量: {{current_status}}, {{valid_exits}}, {{current_phase}}, {{valid_phases}}
大门
闸门是状态或阶段转换前必须满足的要求:
gates:
status:working:
- type: gate/tests
enforcement: warn
description: "Tests must pass"通过附上证据来满足大门:
attach(task="123", type="gate/tests", content="All tests passing")执行级别: allow (咨询), warn (除非 force=true), reject (硬块)
文件协调
代理可以使用带有更改跟踪的咨询标记来协调文件编辑:
Worker A: connect() -> "worker-a"
Worker A: mark_file("worker-a", "src/main.rs", "refactoring")
Worker B: connect() -> "worker-b"
Worker B: mark_updates("worker-b") -> sees worker-a's mark
Worker A: unmark_file("worker-a", "src/main.rs", "ready for review")
Worker B: mark_updates("worker-b") -> sees removal with reason
Worker B: mark_file("worker-b", "src/main.rs", "adding tests")建筑
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Agent A │ │ Agent B │ │ Agent C │
│ (Claude) │ │ (GPT-4) │ │ (Worker) │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ stdio │ stdio │ stdio
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ task-graph │ │ task-graph │ │ task-graph │
│ MCP │ │ MCP │ │ MCP │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
└───────────────────┼───────────────────┘
▼
┌─────────────────┐
│ SQLite + WAL │
│ .task-graph/ │
│ tasks.db │
└─────────────────┘- 运输:Stdio--每个工作进程都生成自己的服务器进程
- 数据库:SQLite具有WAL模式,可跨进程并发访问
- 部署:单个二进制文件,无外部依赖,脱机工作
与替代方案相比
| 任务图 | 线性任务列表 | 自定义数据库 | |
|---|---|---|---|
| 工作流阶段 | ✓ 内置提示 | ✗ 手动跟踪 | DIY |
| 质量门 | ✓ 可配置的执行 | ✗ | DIY |
| 多代理安全 | ✓ 原子声明、文件锁 | ✗ 比赛条件 | 也许,DIY |
| 依赖跟踪 | ✓ 带循环检测的DAG | ✗ 手动订购 | DIY |
| MCP本地 | ✓ 头等舱 | ✗ 需要包装 | ✗ 需要包装 |
| 代币会计 | ✓ 内置 | ✗ | DIY |
| 需要安装 | 无 | 无 | 数据库服务器 |
文档
| 文档 | 描述 |
|---|---|
| 配置.md | 完整的配置参考(config.yaml、工作流、提示、门、标签) |
| SCHEMA.md | 数据库模式和状态机文档 |
| 设计.md | 架构和设计决策 |
| 工作流程_拓扑.md | 多代理工作流模式(单独、集群、中继、分层) |
| 出口_进口.md | 数据导出和导入功能 |
| 进程.md | 发布流程、变更日志维护 |
| GATES.md | 工作流入口条件和执行 |
| METRIC.md | 实验指标定义和SQL示例 |
许可证
Apache 2.0
______________________________________________________________________
专为需要结构化工作流程和可靠协调的AI代理而构建。
