dify-api-mcp
v0.0.3
Published
MCP server for Dify API integration - upload files to Dify knowledge base
Maintainers
Readme
Dify API MCP
A Model Context Protocol (MCP) server that integrates with Dify API to upload files to knowledge bases.
Features
- Upload local files to Dify knowledge base via MCP
- Configurable segmentation settings
- Built-in error handling and validation
- Easy integration with Claude Desktop
Installation
npm install dify-api-mcpConfiguration
Add the MCP server to your Claude Desktop configuration file:
macOS
~/Library/Application Support/Claude/claude_desktop_config.json
Windows
%APPDATA%\Claude\claude_desktop_config.json
Configuration Example
{
"mcpServers": {
"dify-api-mcp": {
"command": "node",
"args": ["./node_modules/dify-api-mcp/src/server.js"],
"env": {
"DIFY_API_KEY": "your-api-key-here",
"DIFY_DATASET_ID": "your-dataset-id-here",
"DIFY_BASE_URL": "https://api.dify.ai/v1",
"DIFY_SEPARATOR": "\\n",
"DIFY_MAX_TOKENS": "1000"
}
}
}
}Environment Variables
DIFY_API_KEY(required): Your Dify API keyDIFY_DATASET_ID(required): Target dataset/knowledge base IDDIFY_BASE_URL(optional): Dify API base URL (defaults to https://api.dify.ai/v1)DIFY_SEPARATOR(optional): Segmentation separator (defaults to "\n")DIFY_MAX_TOKENS(optional): Maximum tokens per segment (defaults to 1000)
Segmentation Settings
You can configure document segmentation using these environment variables:
DIFY_SEPARATOR: Text separator for splitting documents (default: "\n")DIFY_MAX_TOKENS: Maximum tokens per document segment (default: 1000)
Usage
After configuration, restart Claude Desktop. You can then use the following MCP tool:
createByFile
Upload a local file to the Dify knowledge base.
Parameters:
filePath(string, required): Path to the local file to upload
Example:
Please upload the file /path/to/document.pdf to the knowledge baseAPI Configuration
The MCP server uses the following fixed settings for Dify API calls:
indexing_technique: "high_quality"doc_form: "text_model"process_rule.mode: "automatic"
Error Handling
The server includes comprehensive error handling for:
- File validation (existence, size limits)
- Network connectivity issues
- API authentication and authorization
- Dify API errors
Development
# Install dependencies
npm install
# Run the server
npm startLicense
MIT
