Dify MCP server

Integrates with the Dify API to enable workflow execution and management for automated task processing and decision making across domains.
Back to servers
Provider
Yanxing Liu
Release date
Dec 25, 2024
Language
Python
Stats
209 stars

The Model Context Protocol (MCP) Server for Dify workflows enables you to use Dify workflows through the Model Context Protocol (MCP). This implementation calls Dify workflows by leveraging MCP tools, allowing seamless integration between MCP-compatible clients and your existing Dify workflows.

Installation

The server can be installed via Smithery or manually following these steps.

Configuration Setup

You can configure the server using either environment variables or a config.yaml file.

Option 1: Using Environment Variables

Set the following environment variables:

export DIFY_BASE_URL="https://cloud.dify.ai/v1"
export DIFY_APP_SKS="app-sk1,app-sk2" # Comma-separated list of your Dify App SKs
  • DIFY_BASE_URL: The base URL for your Dify API
  • DIFY_APP_SKS: Comma-separated list of your Dify App Secret Keys (SKs)

Option 2: Using config.yaml

Create a config.yaml file with your Dify settings:

dify_base_url: "https://cloud.dify.ai/v1"
dify_app_sks:
  - "app-sk1" # SK for workflow 1
  - "app-sk2" # SK for workflow 2
  # Add more SKs as needed

You can create this file quickly using:

mkdir -p ~/.config/dify-mcp-server

cat > ~/.config/dify-mcp-server/config.yaml <<EOF
dify_base_url: "https://cloud.dify.ai/v1"
dify_app_sks:
  - "app-your-sk-1"
  - "app-your-sk-2"
EOF

echo "Configuration file created at ~/.config/dify-mcp-server/config.yaml"

Installation Methods

First, install UV if you haven't already:

curl -Ls https://astral.sh/uv/install.sh | sh

Method 1: Using UVX (Recommended)

Add this configuration to your client's MCP server settings:

{
"mcpServers": {
  "dify-mcp-server": {
    "command": "uvx",
      "args": [
        "--from","git+https://github.com/YanxingLiu/dify-mcp-server","dify_mcp_server"
      ],
    "env": {
       "DIFY_BASE_URL": "https://cloud.dify.ai/v1",
       "DIFY_APP_SKS": "app-sk1,app-sk2"
    }
  }
}
}

Or if using a config file:

{
"mcpServers": {
  "dify-mcp-server": {
    "command": "uvx",
      "args": [
        "--from","git+https://github.com/YanxingLiu/dify-mcp-server","dify_mcp_server"
      ],
    "env": {
       "CONFIG_PATH": "/Users/lyx/Downloads/config.yaml"
    }
  }
}
}

Method 2: Using UV with Local Clone

Clone the repository locally, then configure your client:

{
"mcpServers": {
  "dify-mcp-server": {
    "command": "uv",
      "args": [
        "--directory", "/Users/lyx/Downloads/dify-mcp-server",
        "run", "dify_mcp_server"
      ],
    "env": {
       "DIFY_BASE_URL": "https://cloud.dify.ai/v1",
       "DIFY_APP_SKS": "app-sk1,app-sk2"
    }
  }
}
}

Usage

Once the server is configured and running, you can use Dify tools in any client that supports MCP. The server will automatically expose your configured Dify workflows as MCP tools, making them available to your MCP-compatible clients.

The server handles the communication between your MCP client and the Dify API, translating MCP tool invocations into Dify workflow executions and returning the results back to your client.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later