mcp-server-dify-workflow

long36708/mcp-server-dify-workflow

3.1

If you are the rightful owner of mcp-server-dify-workflow and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

A Node.js service compliant with the Model Context Protocol (MCP) for invoking Dify workflow interfaces, supporting knowledge base queries and returning results.

Tools
1
Resources
0
Prompts
0

Dify Workflow MCP Server

一个符合 MCP (Model Context Protocol) 规范的 Node.js 服务,用于调用 Dify 工作流接口,支持知识库查询并返回结果。

功能特性

  • 🚀 支持 Dify 工作流的 blocking 模式执行
  • 📊 返回包含知识库查询结果的完整输出
  • 🔧 符合 MCP 协议规范
  • 📝 TypeScript + Node.js + ES6 实现
  • 🛡️ 完整的错误处理和日志记录

快速开始

1. 安装依赖

npm install

2. 配置环境变量

复制 .env.example.env 并填入你的配置:

cp .env.example .env

编辑 .env 文件:

DIFY_API_KEY=your_dify_api_key_here
DIFY_API_BASE_URL=https://api.dify.ai/v1
PORT=8080

3. 启动服务

开发模式:

npm run dev

生产模式:

npm run build
npm start

API 端点

健康检查

GET /health

MCP 发现

GET /mcp/server/discover

MCP 调用

POST /mcp/invoke

MCP 工具

execute_dify_workflow

执行 Dify 工作流并返回最终结果。

输入参数:

{
  "workflow_id": "string",  // 必需:Dify 工作流 ID
  "inputs": {},             // 可选:工作流输入参数
  "user": "string"          // 必需:用户标识符
}

输出格式:

成功时:

{
  "status": "success",
  "result": {},
  "workflow_run_id": "string",
  "task_id": "string",
  "elapsed_time": 1234,
  "total_tokens": 567
}

失败时:

{
  "status": "error",
  "error": {
    "code": "string",
    "message": "string"
  }
}

使用示例

调用工作流

curl -X POST http://localhost:8080/mcp/invoke \
  -H "Content-Type: application/json" \
  -d '{
    "method": "tools/call",
    "params": {
      "name": "execute_dify_workflow",
      "arguments": {
        "workflow_id": "your-workflow-id",
        "inputs": {
          "query": "查询内容"
        },
        "user": "user123"
      }
    }
  }'

项目结构

├── src/
│   ├── server.ts       # HTTP 服务器和路由
│   ├── mcpTools.ts     # MCP 工具定义
│   ├── difyClient.ts   # Dify API 客户端
│   ├── handlers.ts     # 请求处理器
│   └── types.ts        # TypeScript 类型定义
├── package.json
├── tsconfig.json
├── .env.example
└── README.md

技术栈

  • Node.js - 运行时环境
  • TypeScript - 类型安全的 JavaScript
  • Express - Web 框架
  • node-fetch - HTTP 客户端
  • dotenv - 环境变量管理

注意事项

  • Dify blocking 模式请求可能在 100 秒后因 Cloudflare 限制而超时
  • 确保 DIFY_API_KEY 具有执行工作流的权限
  • 工作流必须已在 Dify 平台中创建并发布

许可证

📚 完整文档

  • - 完整文档索引
  • - 5分钟快速部署
  • - 详细使用说明
  • - 完整 API 文档
  • - 各种配置方案
  • - 系统集成方法
  • - 实际使用案例
  • - 生产环境部署

许可证

MIT License