Dify Connect MCP

by difybase

MCP Client 31 stars
  • other

About

What is Dify Connect MCP?

Dify Connect MCP is a Model Context Protocol (MCP) server that integrates with the Dify API. It runs on Node.js (v16+) and allows developers to send queries to Dify chat applications and retrieve responses from Dify knowledge bases.

How to use Dify Connect MCP?

Install dependencies with npm install, then compile TypeScript code using ./build.sh. Set required environment variables (DIFY_SECRET_KEY, optionally DIFY_BASE_URL, etc.) in a .env file by copying .env.example and editing it. Start the server with ./start-mcp.sh. To use with Cline, add the following to your MCP server settings file: {"mcpServers":{"dify-connect-mcp":{"command":"/bin/bash","args":["<repository-path>/run-mcp.sh"],"disabled":false,"autoApprove":[]}}}. The .env file is automatically loaded by the script, so no API key needs to be written directly in the settings.

Key features of Dify Connect MCP

- dify-chat: Send queries to Dify chat apps and receive responses
- knowledge-base-query: Query Dify knowledge bases and retrieve answers
- Secure credential management via .env file (no hard‑coded API keys)
- Supports development and production environments (NODE_ENV)
- Configurable log levels (LOG_LEVEL: debug/info/warn/error)

Use cases of Dify Connect MCP

- Build a chat assistant that answers user questions through the Dify API
- Retrieve product information or documentation from a Dify knowledge base
- Integrate Dify AI capabilities into MCP‑compatible tools (e.g., Cline) without exposing API keys in configuration files
- Automate queries to Dify applications for testing or internal tooling

FAQ from Dify Connect MCP

What does Dify Connect MCP do?

It provides two MCP tools (dify-chat and knowledge-base-query) that let you send queries to Dify chat apps and knowledge bases, returning the responses to your MCP client.

How do I install and configure Dify Connect MCP?

Clone the repository, run npm install, then ./build.sh. Copy .env.example to .env and set your DIFY_SECRET_KEY. Optional: adjust DIFY_BASE_URL (defaults to https://api.dify.ai/v1), NODE_ENV, and LOG_LEVEL. Start with ./start-mcp.sh.

What environment variables are required?

DIFY_SECRET_KEY is mandatory. DIFY_BASE_URL defaults to https://api.dify.ai/v1. NODE_ENV can be development or production. LOG_LEVEL can be debug, info, warn, or error.

How do I use Dify Connect MCP with Cline?

Add the JSON configuration shown in the README to your MCP server settings file. Point the args to the run-mcp.sh script in the repository path. The script automatically reads the .env file, so you don’t need to put your API key in the MCP settings.

Does Dify Connect MCP work with other MCP clients?

The README only provides configuration instructions for Cline. Compatibility with other MCP clients is not documented.

Details

Author
difybase
GitHub stars
31
Category
other
Repository
difybase/dify-connect-mcp

Dify Connect MCP

Dify APIと連携するModel Context Protocol (MCP) サーバー。

概要

このMCPサーバーは、Dify APIと連携して、チャットアプリケーションにクエリを送信し、結果を取得する機能を提供します。

機能

- dify-chat: Difyチャットアプリにクエリを送信し、応答を取得します
- knowledge-base-query: Difyの知識ベースにクエリを送信し、応答を取得します

セットアップ

前提条件

- Node.js (v16以上)
- npm
- Dify APIキー

インストール

1. 依存関係をインストールします:

npm install

2. TypeScriptコードをコンパイルします:

./build.sh

設定

以下の環境変数を設定する必要があります:

- DIFY_BASE_URL: Dify APIのベースURL(デフォルト: https://api.dify.ai/v1)
- DIFY_SECRET_KEY: Dify APIキー(必須)
- NODE_ENV: 実行環境(development/production)
- LOG_LEVEL: ログレベル(debug/info/warn/error)

これらの環境変数は、.envファイルで設定できます:

1. .env.exampleファイルを.envにコピーします:

cp .env.example .env

2. .envファイルを編集して、実際のDify APIキーを設定します:

# Dify API設定
DIFY_BASE_URL=https://api.dify.ai/v1
DIFY_SECRET_KEY=your_actual_dify_secret_key_here

サーバー設定

NODE_ENV=production LOG_LEVEL=info

スクリプト(start-mcp.shrun-mcp.sh)は自動的に.envファイルから環境変数を読み込みます。

実行

サーバーを起動するには:

./start-mcp.sh

MCPサーバーの設定

Clineで使用するには、MCPサーバー設定ファイルに以下を追加します:

{
  "mcpServers": {
    "dify-connect-mcp": {
      "command": "/bin/bash",
      "args": ["<リポジトリのパス>/run-mcp.sh"],
      "disabled": false,
      "autoApprove": []
    }
  }
}

<リポジトリのパス>は、実際のリポジトリのパスに置き換えてください。

この設定では、run-mcp.shスクリプトが.envファイルから環境変数を読み込むため、MCPサーバー設定ファイルに直接APIキーを記述する必要はありません。

使用例

MCPサーバーが設定されると、以下のようなコマンドでDifyにクエリを送信できます:

dify-chat "こんにちは、今日の天気は?"

または知識ベースにクエリを送信:

```
knowledge-base-query "製品の特徴について教えてください" "knowledge_base_id_here"