what is Dify Connect MCP?
Dify Connect MCP is a Model Context Protocol (MCP) server that integrates with the Dify API to send queries to chat applications and retrieve results.
how to use Dify Connect MCP?
To use Dify Connect MCP, set up the server by installing dependencies, configuring environment variables, and starting the server. You can then send queries to the Dify chat application or knowledge base.
key features of Dify Connect MCP?
- dify-chat: Send queries to the Dify chat application and receive responses.
- knowledge-base-query: Send queries to Dify's knowledge base and retrieve answers.
use cases of Dify Connect MCP?
- Integrating chat functionalities into applications using Dify API.
- Retrieving information from a knowledge base for customer support.
- Automating responses in chat applications based on user queries.
FAQ from Dify Connect MCP?
- What are the prerequisites for using Dify Connect MCP?
You need Node.js (v16 or higher), npm, and a Dify API key.
- Is there a specific way to set up the environment variables?
Yes, you need to create a
.env
file and set the required variables like DIFY_BASE_URL and DIFY_SECRET_KEY.
- How do I start the MCP server?
You can start the server by running the command
./start-mcp.sh
after setting up the environment.
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キー
インストール
- 依存関係をインストールします:
npm install
- 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
ファイルで設定できます:
.env.example
ファイルを.env
にコピーします:
cp .env.example .env
.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.sh
とrun-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"