Content
📋 Trae Rules Generator MCP
A MCP (Model Context Protocol) service for automatically generating and managing rule files for Trae AI projects.
## ✨ Features
- 🔍 **Read Existing Rules**: Scan and analyze existing rule file structures
- 🎯 **Intelligent Rule Generation**: Generate customized rules based on project type and features
- 💾 **Rule File Management**: Save, update, and backup rule files
- 🌐 **Multi-language Support**: Support for Chinese and English rule generation
- 🔧 **Flexible Configuration**: Support for custom rule paths and file names
## 🚀 Quick Start
### Method 1: Using the Published Package (Recommended)
#### 1. Install the Package
```bash
pip3 install trae-rules-mcp
```
#### 2. Configure MCP in Trae AI
Add the following configuration to the MCP configuration in Trae AI:
```json
{
"mcpServers": {
"trae-rules-mcp": {
"command": "python3",
"args": ["-m", "trae_rules_mcp.main"],
"env": {
"PYTHONPATH": "."
}
}
}
}
```
### Method 2: Running from Source
#### 1. Environment Requirements
- Python 3.8+
- pip or uv package manager
#### 2. Clone the Project
```bash
git clone https://github.com/trae-ai/trae-rules-mcp.git
cd trae-rules-mcp
```
#### 3. Install Dependencies
```bash
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .
```
#### 4. Configure MCP in Trae AI
```json
{
"mcpServers": {
"trae-rules-generator": {
"command": "uv",
"args": ["run", "python", "main.py"],
"cwd": "/path/to/trae-rules-mcp",
"env": {
"PYTHONPATH": "/path/to/trae-rules-mcp"
}
}
}
}
```
> 💡 **Note**: Replace `/path/to/trae-rules-mcp` with the actual project path.
#### 5. Restart Trae AI
After configuration, restart Trae AI to load the new MCP server.
## 🛠️ MCP Tools
### 1. read_existing_rules
Read existing rule file content and structure information.
**Parameters:**
- `rules_path` (str, optional): Rule file directory path, defaults to `.trae/rules`
**Returns:**
- Detailed information of the rule file, including file list, content preview, etc.
### 2. generate_project_rules
Generate new project rule files based on project type and features.
**Parameters:**
- `project_type` (str): Project type (e.g., web, mobile, ai, backend, frontend)
- `features` (List[str]): Project feature list (e.g., ["authentication", "database", "api"])
- `language` (str, optional): Rule file language, defaults to Chinese
**Returns:**
- Generated rule file content (Markdown format)
### 3. save_rules_file
Save the rule file to the specified directory.
**Parameters:**
- `content` (str): Rule file content
- `filename` (str, optional): File name, defaults to `project_rules.md`
- `rules_path` (str, optional): Rule file directory path, defaults to `.trae/rules`
**Returns:**
- Result information of the save operation
### 4. update_existing_rules
Update existing rule file content.
**Parameters:**
- `file_path` (str): Path to the rule file to be updated
- `updates` (Dict[str, Any]): Dictionary of update content
**Returns:**
- Result information of the update operation
## 📖 Usage Examples
### Example 1: Generate Web Project Rules
```
User: Help me generate a web project rule file with user authentication and database features.
AI Assistant will call:
generate_project_rules(
project_type="web",
features=["authentication", "database"],
language="Chinese"
)
```
### Example 2: Read Existing Rules
```
User: View my current project's rule files.
AI Assistant will call:
read_existing_rules(rules_path=".trae/rules")
```
### Example 3: Save Generated Rules
```
User: Save the generated rules as web_project_rules.md.
AI Assistant will call:
save_rules_file(
content="Generated rule content",
filename="web_project_rules.md",
rules_path=".trae/rules"
)
```
### Example of Generated Rule File
```markdown
---
description: web project rules
globs:
alwaysApply: true
---
### 📋 WEB Project Development Rules
#### 🔧 General Development Rules
1. **Code Quality**
* Keep code concise and highly readable
* Add necessary comments and documentation
* Follow project coding standards
#### 🎯 Feature Rules
1. **Authentication**
* Implement secure user authentication
* Use strong password strategy
* Implement session management
2. **Database**
* Design a reasonable database structure
* Implement data backup strategy
* Optimize query performance
```
## 📁 Project Structure
```
trae-rules-mcp/
├── trae_rules_mcp/ # Main package directory
│ ├── __init__.py # Package initialization file
│ └── main.py # MCP service main file
├── main.py # Compatibility entry file
├── pyproject.toml # Project configuration file
├── README.md # Project documentation
├── example_rules.md # Example rule file
├── mcp_config_example.json # MCP configuration example
├── CHANGELOG.md # Update log
├── LICENSE # License file
└── .gitignore # Git ignore file
```
## 🔧 Configuration Instructions
### Default Rule Path
The service defaults to looking for and saving rule files in the `.trae/rules` directory. You can customize the path using tool parameters.
### Supported Project Types
- `web` / `frontend`: Front-end web project
- `backend` / `api`: Back-end API project
- `ai`: AI/machine learning project
- `mobile`: Mobile application project
- Other custom types
### Supported Features
- `authentication`: User authentication
- `database`: Database operation
- `api`: API interface
- `ui`: User interface
- `testing`: Testing related
- `deployment`: Deployment configuration
- `security`: Security related
- `performance`: Performance optimization
- Other custom features
## 🔧 Troubleshooting
### Common Issues
#### 1. "Command not found: python" Error
**Problem**: Encountered "spawn python ENOENT" error in MCP configuration.
**Solution**:
- Use the full Python path: `"command": "/usr/bin/python3"`
- Or ensure Python is in the system PATH: `"command": "python3"`
#### 2. Module Import Failure
**Problem**: "No module named 'trae_rules_mcp'" error.
**Solution**:
```bash
# Reinstall the package
pip3 uninstall trae-rules-mcp -y
pip3 install trae-rules-mcp
# Verify installation
python3 -c "import trae_rules_mcp; print('Installation successful!')"
```
#### 3. MCP Server Fails to Start
**Problem**: Trae AI cannot connect to the MCP server.
**Solution**:
1. Check if the configuration file format is correct
2. Confirm the path setting is correct
3. Restart Trae AI
4. Check Trae AI's error log
#### 4. Permission Issues
**Problem**: Unable to create or write rule files.
**Solution**:
```bash
# Ensure the directory exists and has write permission
mkdir -p .trae/rules
chmod 755 .trae/rules
```
### Debugging Tips
1. **Test MCP Connection**:
```bash
# Manually start the server for testing
python3 -m trae_rules_mcp.main
```
2. **Check Package Installation**:
```bash
pip3 show trae-rules-mcp
pip3 list | grep trae
```
3. **Verify Configuration**:
- Ensure JSON format is correct
- Check if the path exists
- Verify environment variable settings
## 🤝 Contribution Guide
1. Fork this repository
2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## 📄 License
This project uses the MIT License - see the [LICENSE](LICENSE) file for details.
## 🆘 Support
### Get Help
- 📖 **Documentation**: View this README and project Wiki
- 🐛 **Issue Reporting**: [GitHub Issues](https://github.com/trae-ai/trae-rules-mcp/issues)
- 💡 **Feature Suggestions**: [GitHub Discussions](https://github.com/trae-ai/trae-rules-mcp/discussions)
- 📦 **PyPI Package**: [trae-rules-mcp](https://pypi.org/project/trae-rules-mcp/)
### Version Information
- **Current Version**: 1.0.1
- **Python Support**: 3.8+
- **MCP Protocol**: Compatible with the latest version
### Update Log
View [CHANGELOG.md](CHANGELOG.md) for detailed version update information.
---
**🎉 Thank you for using Trae Rules Generator MCP!**
If this project is helpful to you, consider giving us a ⭐ Star
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
servers
Model Context Protocol Servers
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.