dify-knowledge
本项目是一个现代化的 **Model Context Protocol (MCP) 服务器**,采用 Python 服务化微服务架构,为 AI 助手提供强大的 Dify 知识库访问能力。支持多种 MCP 客户端(Cursor、Lobe Chat、Cherry 等),提供完整的知识库管理和查询功能。
claude mcp add --transport stdio mocha-s-dify-knowledge-mcp-server node dist/index.js \ --env MCP_HOST="127.0.0.1" \ --env MCP_PORT="3000" \ --env DIFY_API_KEY="your-dify-api-key" \ --env DIFY_TIMEOUT="30000" \ --env MCP_LOG_LEVEL="INFO" \ --env DIFY_MAX_RETRIES="3" \ --env DIFY_API_BASE_URL="https://api.dify.ai/v1" \ --env DIFY_KB_API_VERSION="v1"
How to use
This MCP server implements a Dify Knowledge base integration using the official MCP TypeScript SDK. It exposes tools for managing knowledge bases and documents, including listing knowledge bases, viewing details, listing and inspecting documents, and handling document segments and sub-segments. It also provides a robust search capability across knowledge bases with various methods and ranking controls. The server supports multiple transports (stdio and HTTP) so you can run it in a variety of environments and wire it into your existing MCP client workflows. You can interact with the server via the provided tools, which follow MCP’s standard JSON-RPC 2.0 response format and the tool result patterns required by MCP clients.
How to install
Prerequisites:
- Node.js 18+ installed on your machine
- npm or pnpm installed
- Optional: Docker and Docker Compose for containerized deployment
-
Clone the repository and install dependencies git clone <repository-url> cd dify-knowledge-mcp-server npm install
-
Configure environment variables Create a .env file or export the following variables: export DIFY_API_KEY="your-dify-api-key" export DIFY_API_BASE_URL="https://api.dify.ai/v1" # optional, defaults to https://api.dify.ai/v1 export MCP_HOST="127.0.0.1" # MCP server host export MCP_PORT="3000" # MCP server port export MCP_LOG_LEVEL="INFO" # log level export DIFY_TIMEOUT="30000" # API timeout in ms export DIFY_MAX_RETRIES="3" # max retries
-
Run the server (stdio transport by default) npm start
or directly with Node.js
node dist/index.js
-
(Optional) Run with HTTP transport npm run start:http
or node dist/index.js --http --host 0.0.0.0 --port 8080
-
Docker deployment (optional)
Build and run with docker-compose if provided
docker-compose up -d
-
Verify the server curl http://127.0.0.1:3000/health
Additional notes
Tips and common configs:
- The server uses environment-based configuration. If a variable is missing, it may fall back to defaults; ensure DIFY_API_KEY is set for any Dify API calls.
- The MCP host/port can be adjusted via MCP_HOST and MCP_PORT to fit your network.
- For production, enable HTTPS in HTTP transport and secure your endpoints.
- Logs are emitted at the level defined by MCP_LOG_LEVEL; set to INFO or DEBUG during development.
- When integrating with MCP clients, you can use the provided client example in the README to call tools such as dify_list_knowledge_bases, dify_show_document_details, and dify_search_knowledge_base.
- If you run into CORS or network issues with HTTP transport, verify MCP_ALLOWED_ORIGINS and network accessibility.
- Docker deployment: ensure volume mounts for logs if you rely on log persistence.
Related MCP Servers
iterm
A Model Context Protocol server that executes commands in the current iTerm session - useful for REPL and CLI assistance
mcp
Octopus Deploy Official MCP Server
furi
CLI & API for MCP management
editor
MCP Server for Phaser Editor
DoorDash
MCP server from JordanDalton/DoorDash-MCP-Server
mcp
MCP сервер для автоматического создания и развертывания приложений в Timeweb Cloud