Content
# Dify Doc MCP Server
A MCP (Model Context Protocol) Server for integrating Dify knowledge base, allowing AI assistants to directly access and retrieve content from Dify knowledge base.
## Technical Selection
- **Language**: TypeScript
- **Runtime Environment**: Node.js v18+
- **MCP Framework**: @modelcontextprotocol/sdk
- **HTTP Client**: axios
- **Data Validation**: zod
- **Transport Method**: StdioServerTransport (standard input/output)
## Main Architecture
This project implements three core tools:
1. **dify_retrieve_knowledge** - Knowledge Base Retrieval
2. **dify_list_datasets** - Get Knowledge Base List
3. **dify_get_dataset_detail** - Get Knowledge Base Details
Through MCP protocol integration with Dify REST API, it supports multiple retrieval methods such as semantic search, keyword search, full-text search, and hybrid search.
## Installation
### Global Installation
```bash
npm install -g dify-doc-mcp-server
```
### Or use npx (no installation required)
```bash
npx dify-doc-mcp-server
```
## Quick Start
### Method 1: Using npx (recommended)
```bash
# Run directly without installation
DIFY_BASE_URL="http://your-dify-host:8031" DIFY_API_KEY="your-api-key" npx dify-doc-mcp-server
```
### Method 2: Local Development
```bash
# 1. Clone the project
git clone <repository-url>
cd difydocmcpserver
# 2. Install dependencies
npm install
# 3. Configure environment variables
export DIFY_BASE_URL="http://localhost:8031"
export DIFY_API_KEY="your-dify-api-key"
# 4. Build and run
npm run build
npm start
```
## Available Tools
### dify_list_datasets
Get Dify knowledge base list
- `keyword` (optional): Search keyword
- `limit` (optional): Return count (1-100, default 20)
### dify_get_dataset_detail
Get Dify knowledge base details
- `dataset_id` (required): Knowledge base ID
### dify_retrieve_knowledge
Retrieve relevant content from Dify knowledge base
- `dataset_id` (required): Knowledge base ID
- `query` (required): Retrieval query content
- `search_method` (optional): Retrieval method (semantic_search/keyword_search/full_text_search/hybrid_search)
- `top_k` (optional): Return result count (1-20, default 3)
- `score_threshold` (optional): Similarity threshold (0-1, default 0)
## MCP Client Configuration
```json
{
"mcpServers": {
"dify-doc": {
"command": "npx",
"args": ["dify-doc-mcp-server"],
"env": {
"DIFY_BASE_URL": "http://your-dify-host:8031",
"DIFY_API_KEY": "your-dify-api-key"
}
}
}
}
```
## API Key Acquisition
1. Log in to Dify console
2. Go to "Settings" → "Knowledge Base" → "API" → "API Key"
3. Create a new API key
4. Copy the key and set it to environment variables
## Testing
```bash
# Set environment variables and run test
DIFY_BASE_URL="http://your-dify-host:8031" DIFY_API_KEY="your-api-key" DATASET="your-dataset-name" QUERY="引导" node test-mcp.js
```
The test script will verify:
- MCP Server connection
- Tool list acquisition
- Knowledge base list, details, and retrieval functionality
## Related Links
- [Dify Official Documentation](https://docs.dify.ai/)
- [MCP Protocol Specification](https://modelcontextprotocol.io/)
- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
markitdown
Python tool for converting files and office documents to Markdown.
firecrawl
Firecrawl MCP Server enables web scraping, crawling, and content extraction.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
mempalace
The highest-scoring AI memory system ever benchmarked. And it's free.