using your grep tools locate def prep_workspace (it's located in src/codegen_lab/prompt_library.py), I want you to enhance this to do the following:
You are an expert Python developer tasked with enhancing the prep_workspace
function in our MCP-based tool. The current function prepares a workspace for cursor rules by creating directories and providing instructions. Your task is to expand this function to:
-
Write four mandatory cursor rule files to the client repo's cursor rules directory:
- tree.mdc.md
- repo_analyzer.mdc.md
- notify.mdc.md
- repomix.mdc.md
-
Update the client repo's
.cursor/mcp.json
file to include new entries if they don't already exist.
Here's the current implementation of prep_workspace
:
@mcp.tool(
name="prep_workspace",
description="Prepare the workspace for cursor rules by returning natural language instructions",
)
def prep_workspace() -> dict[str, str]:
"""Prepare the workspace for cursor rules.
This function provides natural language instructions and commands
for cursor rules, including directory creation and file preparation steps.
Returns:
dict[str, str]: A dictionary containing instructions and commands
"""
# Get the current working directory
current_dir = Path.cwd()
# Define the cursor rules directory path
cursor_rules_dir = current_dir / "hack" / "drafts" / "cursor_rules"
# Check if the directory exists
dir_exists = cursor_rules_dir.exists()
# Prepare instructions
mkdir_cmd = f"mkdir -p {cursor_rules_dir}"
try:
# Create the directory if it doesn't exist
if not dir_exists:
cursor_rules_dir.mkdir(parents=True, exist_ok=True)
instructions = {
"status": "success",
"message": f"""
To prepare the workspace for cursor rules, the following steps are needed:
1. Create the cursor rules directory structure:
{mkdir_cmd}
2. Ensure the .cursor/rules directory exists for deployment:
mkdir -p .cursor/rules
3. Check if Makefile exists with an update-cursor-rules task:
The update-cursor-rules task should copy files from hack/drafts/cursor_rules to .cursor/rules. This command updates Cursor editor rules by copying rule definitions from a drafts directory into the Cursor configuration folder. It first creates a .cursor/rules directory if it doesn't exist. Then it finds all Markdown (.md) files in the hack/drafts/cursor_rules directory (excluding any README files), copies them to the .cursor/rules directory, and preserves their filenames without the .md extension. The comment notes that Cursor doesn't support generating .mdc files directly through the Composer Agent at the time this was written
4. Update .dockerignore to exclude the cursor rules drafts directory:
Add 'hack/drafts/cursor_rules' to .dockerignore if it exists
Enhance this function to:
-
Copy the four mandatory rule files from the source repository (where this code is running) to the client repository's
hack/drafts/cursor_rules
directory. The source files are located at:/Users/malcolm/dev/bossjones/codegen-lab/hack/drafts/cursor_rules/tree.mdc.md
/Users/malcolm/dev/bossjones/codegen-lab/hack/drafts/cursor_rules/repo_analyzer.mdc.md
/Users/malcolm/dev/bossjones/codegen-lab/hack/drafts/cursor_rules/notify.mdc.md
/Users/malcolm/dev/bossjones/codegen-lab/hack/drafts/cursor_rules/repomix.mdc.md
-
Check if the client repo has a
.cursor/mcp.json
file. If it exists, read it and ensure it contains entries for the MCP servers. If any entries are missing, add them. If the file doesn't exist, create it with the necessary entries.
The structure of the .cursor/mcp.json
file should be:
{
"mcpServers": {
"memory": {
"command": "env",
"args": [
"MEMORY_FILE_PATH=./ai_docs/memory.json",
"npx",
"-y",
"@modelcontextprotocol/server-memory"
]
},
"prompt_library": {
"command": "uv",
"args": [
"run",
"--with",
"mcp[cli]",
"mcp",
"run",
"/Users/malcolm/dev/bossjones/codegen-lab/src/codegen_lab/prompt_library.py"
]
},
"sequentialthinking": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sequential-thinking"
]
}
}
}
Make sure to handle errors gracefully and provide clear status messages. The function should return a dictionary with a status and a detailed message about what was done.
Use the existing save_cursor_rule
function as a reference for how to write files to the cursor rules directory. Make sure to maintain the existing functionality of the prep_workspace
function while adding these new features.