@wallacewen/dify-mcp-server
Version:
Model Context Protocol server for Dify AI integration - supports server management, monitoring, and system tools
258 lines (185 loc) • 5.66 kB
Markdown
# Dify MCP Server
[](https://badge.fury.io/js/@wallacewen%2Fdify-mcp-server)
[](https://opensource.org/licenses/MIT)
A Model Context Protocol (MCP) server that integrates with Dify AI to provide server management, monitoring, and system administration tools through conversational AI.
## Features
- 🧹 **Log Cleaning**: Automated server log cleaning and maintenance
- 🚀 **Server Deployment**: Environment deployment and Jenkins integration
- 📊 **Server Monitoring**: Real-time server resource monitoring (CPU, memory, disk)
- 🔧 **System Tools**: Network connectivity checks, port monitoring, and system utilities
- 🔒 **Secure Configuration**: Environment-based configuration for sensitive data
- 🎯 **MCP Compatible**: Works with Claude Desktop and other MCP clients
## Installation
```bash
npm install -g @wallacewen/dify-mcp-server
```
Or with pnpm:
```bash
pnpm add -g @wallacewen/dify-mcp-server
```
## Configuration
### Required Environment Variables
Before using the server, you must configure these environment variables:
| Variable | Description | Required |
|----------|-------------|----------|
| `DIFY_API_TOKEN` | Your Dify API authentication token | ✅ |
| `DIFY_BASE_URL` | Base URL of your Dify instance | ✅ |
| `DIFY_DEFAULT_USER` | Default user ID for Dify API requests | ✅ |
### Environment Setup
Create a `.env` file or set environment variables:
```bash
# .env file
DIFY_API_TOKEN=your_dify_api_token_here
DIFY_BASE_URL=https://your-dify-instance.com
DIFY_DEFAULT_USER=your_user_id_here
```
Or export them in your shell:
```bash
export DIFY_API_TOKEN="your_dify_api_token_here"
export DIFY_BASE_URL="https://your-dify-instance.com"
export DIFY_DEFAULT_USER="your_user_id_here"
```
### Claude Desktop Configuration
Add the server to your Claude Desktop configuration file:
**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
```json
{
"mcpServers": {
"dify-server": {
"command": "dify-mcp-server",
"env": {
"DIFY_API_TOKEN": "your_dify_api_token_here",
"DIFY_BASE_URL": "https://your-dify-instance.com",
"DIFY_DEFAULT_USER": "your_user_id_here"
}
}
}
}
```
## Usage
Once configured, the server provides the following tools through your MCP client:
### 🧹 Log Cleaning (`dify_log_clean`)
Clean server logs and manage log files:
```
Query: "清理服务器日志,10.0.19.41"
Query: "清理10.0.19.41 /var/log 目录下的旧日志文件"
```
### 🚀 Server Deployment (`dify_server_deployment`)
Manage server deployments and Jenkins integration:
```
Query: "服务器环境到jenkins"
Query: "配置生产环境jenkins"
```
### 📊 Server Monitoring (`dify_server_monitoring`)
Monitor server resources and performance:
```
Query: "查看服务器10.0.19.41的CPU和内存使用情况"
Query: "监控生产环境服务器资源状态"
```
### 🔧 System Tools (`dify_system_tools`)
Execute system utilities and checks:
```
Query: "检查网络连通性ping baidu.com"
Query: "查看磁盘空间df -h"
Query: "检查端口8080占用netstat -tulpn | grep 8080"
```
## Development
### Prerequisites
- Node.js >= 18.0.0
- pnpm (recommended) or npm
### Setup
1. Clone the repository:
```bash
git clone https://github.com/wallacewen/dify-mcp-server.git
cd dify-mcp-server
```
2. Install dependencies:
```bash
pnpm install
```
3. Set up environment variables:
```bash
cp .env.example .env
# Edit .env with your configuration
```
4. Build the project:
```bash
pnpm run build
```
5. Run in development mode:
```bash
pnpm run dev
```
### Testing
Run the test suite:
```bash
pnpm test
```
Run tests with coverage:
```bash
pnpm run test:coverage
```
### Code Quality
Format code:
```bash
pnpm run format
```
Lint code:
```bash
pnpm run lint
```
Type check:
```bash
pnpm run check-types
```
Run all checks:
```bash
pnpm run ci
```
## How to Get Dify Configuration
### 1. Get Your Dify API Token
1. Log in to your Dify instance
2. Go to your application settings
3. Navigate to the "API Access" section
4. Copy your API key
### 2. Get Your Dify Base URL
This is the base URL of your Dify instance, for example:
- `https://api.dify.ai` (for Dify Cloud)
- `https://your-domain.com` (for self-hosted)
### 3. Get Your User ID
The user ID can be found in:
- Your Dify application logs
- API response headers
- Contact your Dify administrator
## Troubleshooting
### Common Issues
**Missing Environment Variables**
```
❌ Missing required environment variables:
DIFY_API_TOKEN
DIFY_BASE_URL
DIFY_DEFAULT_USER
```
Solution: Ensure all required environment variables are set correctly.
**Connection Errors**
- Verify your `DIFY_BASE_URL` is correct and accessible
- Check your `DIFY_API_TOKEN` is valid and has proper permissions
- Ensure your network allows connections to the Dify instance
**Authentication Errors**
- Verify your API token is correct
- Check if the token has expired
- Ensure the user ID has proper permissions
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Run the test suite
6. Submit a pull request
## License
MIT © [Wallace Wen](https://github.com/wallacewen)
## Support
- 🐛 [Report Issues](https://github.com/wallacewen/dify-mcp-server/issues)
- 💬 [Discussions](https://github.com/wallacewen/dify-mcp-server/discussions)
- 📧 Contact: wallacewen@example.com