Get the FREE Ultimate OpenClaw Setup Guide →

dify-knowledge

dify knowledge mcp server

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio liiklin-dify-knowledge-mcp-server node /path/to/your/dify-knowledge-mcp-server/index.js \
  --env DIFY_API_KEY="your_actual_api_key" \
  --env DIFY_API_URL="https://api.dify.ai/v1/datasets/YOUR_DATASET_ID/documents/query"

How to use

This MCP server provides access to your Dify knowledge base via the MCP protocol, allowing an AI assistant (such as Cursor) to perform semantic, full-text, or hybrid searches against your knowledge content. After configuring the MCP server, Cursor can invoke the available tools to query the knowledge base and retrieve relevant documents. The primary tool exposed is query_dify_knowledge, which lets you search with a query string and specify options like top_k, search_method, and reranking. You can also run get_dify_config to verify the current Dify API configuration. The server is designed to keep your API keys secure by reading them from environment variables or an .env file rather than hard-coding them into source code.

How to install

Prerequisites:

  • Node.js (supports ES modules) installed on your system
  • Access to a Dify dataset with a valid API key

Step-by-step installation:

  1. Install dependencies
npm install
  1. Configure API information (choose one method):
  • Using a .env file (recommended):
# Copy configuration template and edit
cp env.example .env
# Edit the .env file to set your values
# DIFY_API_URL=https://api.dify.ai/v1/datasets/YOUR_DATASET_ID/documents/query
# DIFY_API_KEY=your_actual_api_key
  • Environment variables:
# Linux/Mac
export DIFY_API_URL="https:// api.dify.ai/v1/datasets/YOUR_DATASET_ID/documents/query"
export DIFY_API_KEY="your_actual_api_key"
# Windows
set DIFY_API_URL=https://api.dify.ai/v1/datasets/YOUR_DATASET_ID/documents/query
set DIFY_API_KEY=your_actual_api_key
  • Command-line arguments (alternative):
node index.js --api-url="https://api.dify.ai/v1/datasets/YOUR_DATASET_ID/documents/query" --api-key="your_actual_api_key"
  1. Run the server
node index.js

Additional notes

Tips and common issues:

  • Keep API keys secure by leveraging .env files or environment variables; never commit keys to version control.
  • Ensure DIFY_API_URL points to the correct dataset documents query endpoint and that DIFY_API_KEY is valid.
  • When configuring Cursor, use the exact MCP server name (e.g., dify-knowledge) and provide the correct path to your server script if you customize locations.
  • If you encounter connectivity errors, verify network access to the Dify API endpoint and confirm the dataset ID exists.
  • The server supports multiple search methods (semantic_search, full_text_search, hybrid_search) and can re-rank results to improve relevance; adjust settings via the query_dify_knowledge tool parameters.
  • For debugging, test running node index.js locally to ensure the server starts and prints readiness messages like Ready to query knowledge base!.

Environment variables and configuration options:

  • DIFY_API_URL: Endpoint to query Dify documents (required)
  • DIFY_API_KEY: Your Dify API key (required)
  • Any additional environment variables required by your implementation can be added to the mcp configuration under env.

Related MCP Servers

Sponsor this space

Reach thousands of developers