Skip to content

MCP 接口概述

TaskFlow 为每个项目提供一个符合 MCP(Model Context Protocol) 标准的端点,让 AI Agent 直接调用 TaskFlow 的任务执行、状态管理、知识库检索等能力。

端点

POST /api/projects/{project_id}/mcp

支持 GET(连接探测)、HEAD(健康检查)、POST(消息发送)、DELETE 方法。

认证

使用项目 API Key 认证(在「项目设置 → API Keys」页面创建):

Authorization: Bearer tf_b1af5033_<secret>

API Key 格式:tf_{project_id前8位}_{32位随机字符串}

API Key 与项目绑定,只能访问该项目的 MCP 端点。

与 Claude Code 集成

.claude/mcp.json 中添加:

json
{
  "mcpServers": {
    "taskflow": {
      "type": "http",
      "url": "http://localhost:8000/api/projects/YOUR_PROJECT_ID/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_API_KEY"
      }
    }
  }
}

与 Cursor 集成

在 Cursor 设置 → MCP 中添加服务器:

  • Name: taskflow
  • Transport: Streamable HTTP
  • URL: http://localhost:8000/api/projects/YOUR_PROJECT_ID/mcp
  • Headers: Authorization: Bearer YOUR_API_KEY

动态任务 Tools

在元任务的「允许 MCP 调用」开关打开后,该任务类型会自动成为一个 MCP tool,名称为任务类型的 identifier 字段。

# 元任务 identifier = "web-scraper"
工具名称: web-scraper
输入: 元任务的 param_schema 定义的字段
输出: {"task_id": "...", "task_name": "...", "status": "pending"}

调用后立即返回,任务在后台异步执行。使用 get_task 工具轮询结果。

Built with VitePress