Skip to content

MCP Server 使用指南

TaskFlow AI 提供完整的 MCP (Model Context Protocol) Server 实现,为 Claude、Cursor、Windsurf 等 AI 编辑器提供 38 个强大的工具能力。

什么是 MCP?

MCP (Model Context Protocol) 是一个开放标准,允许 AI 模型与外部工具和服务进行交互。TaskFlow AI 的 MCP Server 实现了以下 MCP 标准:

  • Tools - 可执行的函数/命令集合
  • Resources - 文件、数据库等外部资源访问
  • Prompts - 预设的提示模板
  • Events - 实时事件通知系统

快速配置

Claude Desktop

  1. 安装 TaskFlow AI
bash
npm install -g taskflow-ai
  1. 自动配置
bash
taskflow mcp init -e claude-desktop
  1. 重启 Claude Desktop

配置文件:~/Library/Application Support/Claude/claude_desktop_config.json (macOS)

json
{
  "mcpServers": {
    "taskflow": {
      "command": "/usr/local/bin/taskflow",
      "args": ["mcp", "start"]
    }
  }
}

Cursor

  1. 安装 TaskFlow AI
bash
npm install -g taskflow-ai
  1. 自动配置
bash
taskflow mcp init -e cursor
  1. 重启 Cursor

配置文件:~/.cursor/mcp.json

json
{
  "mcpServers": {
    "taskflow": {
      "command": "taskflow",
      "args": ["mcp", "start"]
    }
  }
}

Windsurf

  1. 安装 TaskFlow AI
bash
npm install -g taskflow-ai
  1. 自动配置
bash
taskflow mcp init -e windsurf
  1. 重启 Windsurf

配置文件:~/.config/Windsurf/mcp.json

json
{
  "mcpServers": {
    "taskflow": {
      "command": "taskflow",
      "args": ["mcp", "start"]
    }
  }
}

工具列表

TaskFlow AI 提供 38 个内置工具,分为以下类别:

文件系统 (8)

工具功能安全级别
fs_read读取文件内容High
fs_write写入文件内容High
fs_append追加内容到文件High
fs_delete删除文件High
fs_list列出目录内容Low
fs_search搜索文件Low
fs_copy复制文件High
fs_move移动/重命名文件High

安全特性

  • ✅ 路径遍历防护
  • ✅ 敏感目录保护
  • ✅ 文件大小限制 (10MB)

HTTP 请求 (7)

工具功能安全级别
http_getGET 请求Medium
http_postPOST 请求Medium
http_putPUT 请求Medium
http_deleteDELETE 请求Medium
http_download下载文件Medium
http_headHEAD 请求Low
http_optionsOPTIONS 请求Low

安全特性

  • ✅ SSRF 防护(禁止访问私有 IP)
  • ✅ URL 协议验证
  • ✅ 响应大小限制 (5MB)
  • ✅ 30 秒超时

数据库 (5)

工具功能安全级别
db_query执行 SQL 查询Medium
db_init初始化数据库Medium
db_schema获取数据库 SchemaLow
db_tables列出所有表Low
db_backup备份数据库Medium

安全特性

  • ✅ SQL 注入防护
  • ✅ 只读模式支持
  • ✅ 查询结果限制

Shell 命令 (3)

工具功能安全级别
shell_exec执行 Shell 命令(同步)High
shell_exec_async异步执行 Shell 命令High
shell_test测试命令是否可用Low

安全特性

  • ✅ 命令白名单(只允许安全命令)
  • ✅ 危险字符过滤 (&&, ||, ;, |, $(), `)
  • ✅ 30 秒超时保护
  • ✅ 禁止命令链和管道

白名单命令

  • ls, cd, pwd, cat, head, tail, grep, find
  • git, npm, yarn, pnpm, node, python, python3
  • cp, mv, rm, mkdir, touch
  • echo, printf, sed, awk

Git 操作 (8)

工具功能安全级别
git_status查看 Git 状态Low
git_log查看提交历史Low
git_commit提交更改Medium
git_push推送更改Medium
git_pull拉取更改Medium
git_branch分支管理Medium
git_checkout切换分支Medium
git_diff查看差异Low

安全特性

  • ✅ Credential 安全管理
  • ✅ 只操作当前仓库
  • ✅ 敏感信息自动脱敏

记忆管理 (4)

工具功能安全级别
memory_set设置记忆Low
memory_get获取记忆Low
memory_clear清除记忆Medium
memory_list列出所有记忆Low

安全特性

  • ✅ 本地存储
  • ✅ 自动过期机制
  • ✅ 大小限制 (1GB)

代码执行 (3)

工具功能安全级别
code_execute执行代码High
code_eval_js评估 JavaScriptMedium
code_eval_python评估 PythonMedium

安全特性

  • ✅ 执行超时限制 (30 秒)
  • ✅ 内存限制 (512MB)
  • ✅ 沙箱环境

使用示例

示例 1: 读取文件

bash
# Claude Desktop 中的对话
用户:帮我读取 README.md 的内容

Claude: (自动调用 fs_read 工具)
文件内容:...

示例 2: 发送 HTTP 请求

bash
# Cursor 中的对话
用户:帮我获取 GitHub API 的仓库信息

Cursor: (自动调用 http_get 工具)
GET https://api.github.com/repos/Agions/taskflow-ai

返回:...

示例 3: 执行 Shell 命令

bash
# Windsurf 中的对话
用户:帮我查看当前目录的文件

Windsurf: (自动调用 shell_exec 工具)
执行:ls -la

返回:...

安全最佳实践

  1. 启用所有安全层 - 不要禁用任何安全检查
  2. 定期更新 - 保持 TaskFlow AI 最新版本
  3. 审查日志 - 定期检查 MCP Server 日志
  4. 最小权限 - 只启用必要的工具
  5. 环境隔离 - 生产环境使用专用配置

故障排除

MCP Server 未启动

bash
# 检查 MCP Server 状态
taskflow mcp status

# 手动启动
taskflow mcp start

# 查看日志
taskflow mcp logs

工具执行失败

  1. 检查命令白名单
  2. 查看安全日志
  3. 验证权限设置

性能问题

bash
# 查看性能统计
taskflow mcp stats

# 清理缓存
taskflow mcp clean

配置文件

全局配置

位置:~/.taskflow/config.yaml

yaml
mcp:
  server:
    port: 3000
    host: "127.0.0.1"
    timeout: 30000

  security:
    enabled: true
    strictMode: true

  tools:
    enabled:
      - fs_read
      - fs_write
      - http_get
      - git_commit

相关文档

基于 MIT 协议发布 | Made with ❤️ by Agions