Dify Knowledge MCP Server
This server enables AI assistants like Cursor to query Dify knowledge bases through the Model Context Protocol (MCP).
Core Capabilities:
Query Knowledge Base: Search and retrieve content using the
query_dify_knowledgetool with natural language queriesMultiple Search Methods: Choose from semantic search (meaning-based), full-text search (keyword-based), or hybrid search (combination of both, default)
Configurable Results: Control the number of results returned via
top_kparameter (default: 3) with relevance scores to assess result qualityResult Reranking: Optional reranking to optimize search result relevance (enabled by default)
Configuration Management: Check current API configuration and connection status using the
get_dify_configtoolFlexible Configuration: Support for .env files, environment variables, or command-line arguments for seamless integration with AI assistants
Provides configuration management for API keys and URLs through .env files, ensuring sensitive credentials for Dify knowledge base access are stored securely
Runs the MCP server implementation, allowing Cursor AI to query Dify knowledge bases through a standardized interface
Manages dependencies for the MCP server, facilitating easy installation and setup of required packages
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Dify Knowledge MCP Serversearch for information about product pricing and refund policies"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Dify Knowledge MCP Server
这是一个基于Model Context Protocol (MCP)的服务器,用于访问Dify知识库。它可以让AI助手(如Cursor)直接查询你的Dify知识库内容。
功能特性
🔍 查询Dify知识库内容
📊 支持多种搜索方法(语义搜索、全文搜索、混合搜索)
🎯 支持重新排序结果
⚙️ 灵活的配置选项
🛠️ 标准MCP协议支持
Related MCP server: Docs MCP Server
安全警告
⚠️ 重要:保护你的API密钥
永远不要在代码中硬编码API密钥
不要将包含敏感信息的.env文件提交到版本控制
使用.env文件或环境变量来存储敏感配置
定期更新你的API密钥
快速开始
1. 安装依赖
npm install2. 配置API信息
你需要提供两个重要信息:
Dataset ID: 你的Dify知识库ID
API Key: 你的Dify API密钥
3. 配置API密钥
方式1:使用.env文件(推荐)
# 复制配置模板
cp env.example .env
# 编辑.env文件,填入你的真实配置
# DIFY_API_URL=https://api.dify.ai/v1/datasets/YOUR_DATASET_ID/documents/query
# DIFY_API_KEY=your_actual_api_key方式2:环境变量
# 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方式3:命令行参数
node index.js --api-url="https://api.dify.ai/v1/datasets/YOUR_DATASET_ID/documents/query" --api-key="your_actual_api_key"4. 运行服务器
node index.js在Cursor中使用
1. 配置MCP服务器
在Cursor中,你需要配置MCP服务器。创建或编辑你的MCP配置文件:
{
"mcpServers": {
"dify-knowledge": {
"command": "node",
"args": [
"/path/to/your/dify-knowledge-mcp-server/index.js"
],
"env": {
"DIFY_API_URL": "https://api.dify.ai/v1/datasets/YOUR_DATASET_ID/documents/query",
"DIFY_API_KEY": "your_actual_api_key"
}
}
}
}注意: 替换上面的占位符为你的实际值:
YOUR_DATASET_ID: 你的Dify知识库IDyour_actual_api_key: 你的Dify API密钥/path/to/your/dify-knowledge-mcp-server/index.js: 你的项目路径
2. 可用的工具函数
配置完成后,Cursor可以使用以下工具:
query_dify_knowledge
查询Dify知识库内容
参数:
query(必需): 搜索查询词top_k(可选): 返回结果数量,默认为3search_method(可选): 搜索方法,可选值:semantic_search: 语义搜索full_text_search: 全文搜索hybrid_search: 混合搜索(默认)
reranking_enable(可选): 启用重新排序,默认为true
示例:
请查询关于"产品介绍"的相关内容get_dify_config
检查当前Dify API配置状态
使用示例
在Cursor中的对话示例
用户: 请帮我查询知识库中关于"用户手册"的内容
AI助手: 我来为你查询Dify知识库中关于"用户手册"的内容...
[调用query_dify_knowledge工具]
找到了3个相关的知识条目:
1. (Score: 0.95)
用户手册第一章介绍了产品的基本功能和使用方法...
2. (Score: 0.87)
用户手册第二章详细说明了高级功能的配置步骤...
3. (Score: 0.82)
用户手册常见问题解答部分提供了问题解决方案...配置说明
API URL格式
https://api.dify.ai/v1/datasets/{dataset_id}/documents/query支持的搜索方法
semantic_search: 基于语义理解的搜索
full_text_search: 传统的全文搜索
hybrid_search: 结合语义和全文搜索的混合模式
重新排序
启用重新排序可以提高搜索结果的相关性,但可能会增加响应时间。
故障排除
常见问题
"Please configure DIFY_API_URL and DIFY_API_KEY"
确保API URL和API Key已正确配置
检查Dataset ID是否正确
"Failed to retrieve knowledge from Dify"
检查API Key是否有效
确认Dataset ID是否存在
验证网络连接
连接超时
检查网络连接
确认Dify API服务是否可访问
测试配置
运行以下命令测试配置:
# 测试配置状态
node index.js如果看到"Ready to query knowledge base!"消息,说明配置正确。
清理敏感信息
如果你之前在配置文件中暴露了API密钥,请立即:
更新Cursor配置文件 (通常在
~/.cursor/mcp.json或类似路径)删除或更换暴露的API密钥
检查版本控制历史 确保没有提交敏感信息
使用新的配置方法 通过.env文件或环境变量
开发信息
协议: Model Context Protocol (MCP)
传输方式: Standard I/O
API版本: Dify API v1
Node.js版本: 支持ES模块的版本
许可证
MIT License
Available Tools
2 toolsget_dify_configB
Get current Dify API configuration status
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure. While 'Get' implies a read operation, it doesn't specify whether this requires authentication, what format the configuration status returns, potential rate limits, or error conditions. The description lacks essential operational context for a tool that presumably accesses system configuration.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence that communicates the core purpose without any wasted words. It's appropriately sized for a zero-parameter tool and front-loads the essential information.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a zero-parameter tool with no output schema, the description provides the basic purpose but lacks important context about what 'configuration status' includes, the format of returned data, or operational considerations. Given the complexity of configuration tools and absence of annotations/output schema, more detail would be helpful for an agent to use this effectively.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool has 0 parameters with 100% schema description coverage, so the baseline is 4. The description appropriately doesn't discuss parameters since none exist, and the schema already fully documents this.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('Get') and target resource ('current Dify API configuration status'), providing a specific verb+resource combination. However, it doesn't differentiate from its sibling tool 'query_dify_knowledge' which appears to serve a different purpose (knowledge querying vs configuration status).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus its sibling 'query_dify_knowledge' or any alternatives. It simply states what the tool does without indicating appropriate contexts, prerequisites, or exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
query_dify_knowledgeC
Query Dify knowledge base with a search query
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query to find relevant knowledge | |
| top_k | No | Number of results to return (default: 3) | |
| search_method | No | Search method to use | hybrid_search |
| reranking_enable | No | Enable reranking of search results |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure but only states the basic action without revealing important traits. It doesn't mention whether this is a read-only operation, what permissions are needed, rate limits, error conditions, or what format results are returned in. For a search tool with no annotation coverage, this leaves significant behavioral gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence that states the core purpose without any wasted words. It's appropriately sized for a search tool and front-loads the essential information. Every word earns its place in communicating the tool's function.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool has 4 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what kind of results to expect, how they're structured, or important behavioral aspects like authentication requirements or error handling. For a knowledge base query tool with multiple configuration parameters, more context is needed to guide effective use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description mentions 'with a search query' which aligns with the 'query' parameter, but adds no additional semantic context beyond what the schema already provides. With 100% schema description coverage and detailed parameter documentation including defaults and enums, the description doesn't compensate with extra meaning. The baseline of 3 is appropriate when the schema does the heavy lifting.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb ('Query') and resource ('Dify knowledge base') with the action ('with a search query'), making the purpose immediately understandable. It distinguishes from the sibling tool 'get_dify_config' by focusing on search operations rather than configuration retrieval. However, it doesn't specify what kind of knowledge base content is being queried (documents, FAQs, etc.), keeping it from a perfect score.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives or in what context. There's no mention of prerequisites, limitations, or comparison with the sibling tool 'get_dify_config'. The agent must infer usage purely from the tool name and parameters without any explicit direction.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
2 tool updates
- First observed
get_dify_config - First observed
query_dify_knowledge
TDQS
The two tools have clearly distinct purposes: one retrieves configuration status, while the other queries a knowledge base. There is no overlap in functionality, making it easy for an agent to select the correct tool based on the task.
Both tools follow a consistent verb_noun pattern with snake_case naming (get_dify_config, query_dify_knowledge). The verbs 'get' and 'query' are appropriate and distinct, maintaining a predictable naming convention throughout.
With only 2 tools, the server feels thin for a knowledge base domain. It lacks essential operations like creating, updating, or deleting knowledge entries, which limits its utility and scope compared to typical MCP servers.
The tool surface is severely incomplete for a knowledge base server. It only allows querying and checking configuration, missing critical CRUD operations (e.g., add, update, delete knowledge) and other lifecycle management tools, which will likely cause agent failures in comprehensive workflows.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
A Model Context Protocol server for Wix AI tools
DocBase MCP server for AI agents
- KumbukaOAuthai.kumbuka
Governed, auditable knowledge your team curates for its AI assistants, self-hostable
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables AI assistants to explore and interact with Cursor IDE's SQLite databases, providing access to project data, chat history, and composer information.25-
- AlicenseAqualityDmaintenanceA flexible Model Context Protocol server that makes documentation or codebases searchable by AI assistants, allowing users to chat with code or docs by simply pointing to a git repository or folder.11789MIT
- FlicenseCqualityDmaintenanceA Model Context Protocol server that provides Retrieval-Augmented Generation capabilities using Contextual AI, enabling AI interfaces like Cursor IDE and Claude Desktop to query domain-specific knowledge with context-aware responses and source citations.121-
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides RAG capabilities for markdown documents using Qdrant for vector storage and Ollama for embeddings, enabling semantic search and document ingestion directly from Cursor IDE.-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/liiklin/dify-knowledge-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server