logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Dify-Workflow-Gateway-as-MCP-Endpoint

Serves Dify automation pipelines via the Model Context Protocol (MCP) interface, facilitating native integration with advanced AI agents such as Claude. This mechanism supports automatic tool schema discovery and execution utilizing a standardized JSON-RPC backend, complete with robust session lifecycle oversight.

Author

Dify-Workflow-Gateway-as-MCP-Endpoint logo

Yevanchen

No License

Quick Info

GitHub GitHub Stars 34
NPM Weekly Downloads 0
Tools 1
Last Updated 2026-02-19

Tags

difyapp_as_mcp_serverworkflowsmcpyevanchen difyapp_as_mcp_serverworkflows mcpdify workflows

Dify Workflow Gateway via MCP Server

This utility establishes an interface layer, presenting Dify's orchestration flows as consumable services conforming to the Model Context Protocol (MCP) specification. This allows compatible AI clients (e.g., Claude Desktop, specialized IDE assistants) to invoke these workflows directly.

Core Proposition

This module bridges Dify's operational logic with external intelligent systems by:

  • Exposing Dify workflows as discoverable tools for AI agents.
  • Enabling immediate utilization of custom Dify logic by clients without necessitating client-side code adjustments to the workflow definitions.

Key Capabilities

  • ✅ Adherence to MCP's JSON-RPC methodology for request handling.
  • ✅ Automated registration and schema provisioning of exposed tools.
  • ✅ Verified interoperability with leading MCP consumers (e.g., Cursor, Claude platforms).
  • ✅ Secure, stateful communication channel implementation via Server-Sent Events (SSE).
  • ✅ Server-managed session lifecycle control.
  • 🔄 Compliance with emerging MCP Streamable HTTP transport standards (incorporating advancements from PR #206 specifications).

Architectural Context

The transition within the MCP framework favors a "Streamable HTTP" model over legacy patterns, better accommodating stateless service deployments. This project is architecturally aligned with these modern requirements, focusing on:

  • Server-initiated session identifier generation and maintenance.
  • Optimal configuration for stateless operational modes (ideal for Dify's plugin hosting environment).
  • Canonical message formatting and efficient stream processing.
  • Secure session association and authentication mechanisms.

Deployment & Setup

Dify Configuration Step:

  1. Ensure your targeted Dify application possesses at least one fully defined and functional workflow.
  2. Configure the necessary API access credentials within the gateway settings.
  3. Specify the Application Identifier corresponding to the Dify application you wish to publish.

Client Consumption:

To integrate this service within an AI client (e.g., Cursor or Claude):

  1. Navigate to the MCP Server configuration area.
  2. Register a new server entry using the following endpoint format:

    https://[Your-Dify-Instance-Host]/difyapp_as_mcp_server

  3. Activate and persist the new configuration.

  4. The AI agent's tool discovery mechanism will now enumerate the available Dify workflows.

Technical Deep Dive

Endpoint Implementation

The gateway employs two distinct request handlers to satisfy MCP requirements within the Dify plugin container constraints:

  • HTTP GET: Primarily manages the persistent SSE connection required for bidirectional communication setup and serves the initial handshake HTML/metadata.
  • HTTP POST: Handles synchronous JSON-RPC calls directed toward executing specific workflow operations.

To meet the minimal requirements for a functional SSE handshake in this environment, the implementation incorporates:

  • On-the-fly generation of session identifiers by the host server.
  • A time-boxed heartbeat mechanism (approximately 5 minutes).
  • Logic for automatic reconnection attempts following client disconnections.
  • Strict adherence to the latest Streamable HTTP specification parameters.

Workflow Schema Generation

Tool definitions are dynamically synthesized directly from the metadata of accessible Dify workflows. The exposed MCP tool manifest accurately details:

  • Canonical function name and semantic description.
  • Required input schemas and data types.
  • Expected output structure.
  • Parameter constraint validation rules.

Stateless Operation Compliance

This implementation strictly adheres to the contemporary MCP standard for stateless servers. This paradigm shift ensures:

  • Elimination of long-lived, connection-dependent server state.
  • Transactional independence for every incoming request.
  • Correlation of request/response pairs solely via the passed session token.
  • Optimized deployment suitability for transient API gateways like Dify plugins.

Troubleshooting Guide

  1. Connectivity Failures: Verify network accessibility to the endpoint URL. Investigate potential obstructions from proxies or security policies.
  2. Tool Visibility Issues: Confirm the correct Dify Application ID is set. Ensure the associated workflow is published and the Dify API key possesses necessary invocation permissions.
  3. Execution Errors: Review diagnostic output within the Dify application logs to pinpoint workflow runtime exceptions.

Development & Licensing

License: MIT

Acknowledgment: Gratitude extended to the maintainers of the Model Context Protocol specification, particularly for the groundwork laid in Streamable HTTP transport PR #206.

Status: Experimental Release (VIBE CODING Research Artifact) Author: yevanchen Version: 0.0.1 Type: Extension

See Also

`