From 443db3b7dc372b418ff218197027f31520394d43 Mon Sep 17 00:00:00 2001 From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:56:14 +0000 Subject: [PATCH] Add MCP and force mode support to cursor-cli module - Add MCP (Model Context Protocol) configuration options - Add force mode for non-interactive automation - Add default model selection - Add rules system configuration - Update install script to configure MCP and rules - Update start script with environment variables - Add comprehensive Coder Tasks integration examples - Add configuration variables table - Add screenshot section placeholder - Update terminal usage examples with force mode Features added: - enable_mcp: Enable/disable MCP support - mcp_config_path: Custom MCP configuration file path - enable_force_mode: Enable force mode for automation - default_model: Set default AI model - enable_rules: Enable rules system Co-authored-by: matifali <10648092+matifali@users.noreply.github.com> --- registry/coder/modules/cursor-cli/README.md | 104 +++++++++++++++++- registry/coder/modules/cursor-cli/main.tf | 35 ++++++ .../modules/cursor-cli/scripts/install.sh | 58 ++++++++++ .../coder/modules/cursor-cli/scripts/start.sh | 22 ++++ 4 files changed, 214 insertions(+), 5 deletions(-) diff --git a/registry/coder/modules/cursor-cli/README.md b/registry/coder/modules/cursor-cli/README.md index eac86a6e..dacb9d70 100644 --- a/registry/coder/modules/cursor-cli/README.md +++ b/registry/coder/modules/cursor-cli/README.md @@ -1,14 +1,14 @@ --- display_name: Cursor CLI -description: Run Cursor CLI agent in your workspace +description: Run Cursor CLI agent in your workspace with MCP and force mode support icon: ../../../../.icons/cursor.svg verified: true -tags: [cli, cursor, ai, agent] +tags: [cli, cursor, ai, agent, mcp, automation] --- # Cursor CLI -Run the [Cursor CLI](https://docs.cursor.com/en/cli/overview) agent in your workspace for terminal-based AI coding assistance. +Run the [Cursor CLI](https://docs.cursor.com/en/cli/overview) agent in your workspace for terminal-based AI coding assistance. Supports both interactive and non-interactive modes, MCP (Model Context Protocol), and automation features. ```tf module "cursor-cli" { @@ -72,6 +72,67 @@ module "cursor-cli" { } ``` +### With MCP and force mode for automation + +```tf +module "cursor-cli" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/cursor-cli/coder" + version = "1.0.0" + agent_id = coder_agent.example.id + folder = "/home/coder/project" + + # MCP Configuration + enable_mcp = true + mcp_config_path = "/home/coder/.cursor/custom-mcp.json" + + # Automation Features + enable_force_mode = true + default_model = "gpt-5" + + # Rules System + enable_rules = true +} +``` + +### Integration with Coder Tasks + +```tf +# Cursor CLI module with automation features +module "cursor-cli" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/cursor-cli/coder" + version = "1.0.0" + agent_id = coder_agent.example.id + enable_force_mode = true + default_model = "claude-4-sonnet" +} + +# Automated code review task +resource "coder_task" "ai_code_review" { + agent_id = coder_agent.example.id + name = "AI Code Review" + command = "cursor-agent -p 'review the latest git changes for security issues and best practices' --force --output-format text" + cron = "0 9 * * 1-5" # Weekdays at 9 AM +} + +# Automated test generation +resource "coder_task" "generate_tests" { + agent_id = coder_agent.example.id + name = "Generate Missing Tests" + command = "cursor-agent -p 'analyze the src/ directory and generate unit tests for functions missing test coverage' --force" + cron = "0 18 * * *" # Daily at 6 PM +} + +# Documentation updates +resource "coder_task" "update_docs" { + agent_id = coder_agent.example.id + name = "Update Documentation" + command = "cursor-agent -p 'review and update README.md to reflect any new features or API changes' --force --model gpt-5" + cron = "0 12 * * 0" # Sundays at noon +} +``` + ### With custom pre-install script ```tf @@ -107,9 +168,15 @@ cursor-agent "refactor the auth module to use JWT tokens" # Non-interactive mode with text output cursor-agent -p "find and fix performance issues" --output-format text +# Force mode for automation (non-interactive) +cursor-agent -p "review code for security issues" --force + # Use specific model cursor-agent -p "add error handling" --model "gpt-5" +# Combine force mode with model selection +cursor-agent -p "generate comprehensive tests" --force --model "claude-4-sonnet" + # Session management cursor-agent ls # List all previous chats cursor-agent resume # Resume latest conversation @@ -131,14 +198,41 @@ cursor-agent --resume="chat-id" # Resume specific conversation - Model selection support - Git integration for change reviews +## Screenshots + +### Cursor CLI with Coder Tasks Integration + +*Screenshot showing the cursor-cli module working with automated Coder Tasks will be added here* + +- Interactive web interface for cursor-agent +- Automated code review tasks running in background +- Terminal output showing force mode execution +- MCP integration with custom tools + ## Configuration -The module supports the same configuration options as the Cursor CLI: +The module supports comprehensive configuration options: -- **MCP (Model Context Protocol)**: Automatically detects `mcp.json` configuration +### Core Features +- **MCP (Model Context Protocol)**: Automatically detects `mcp.json` configuration or uses custom path - **Rules System**: Supports `.cursor/rules` directory for custom agent behavior +- **Force Mode**: Enable non-interactive automation for CI/CD pipelines +- **Model Selection**: Set default AI model (gpt-5, claude-4-sonnet, etc.) - **Environment Variables**: Respects Cursor CLI environment settings +### Available Variables + +| Variable | Type | Default | Description | +|----------|------|---------|-------------| +| `enable_mcp` | bool | `true` | Enable MCP (Model Context Protocol) support | +| `mcp_config_path` | string | `""` | Path to custom MCP configuration file | +| `enable_force_mode` | bool | `false` | Enable force mode for non-interactive automation | +| `default_model` | string | `""` | Default AI model (e.g., gpt-5, claude-4-sonnet) | +| `enable_rules` | bool | `true` | Enable the rules system (.cursor/rules directory) | +| `install_cursor_cli` | bool | `true` | Whether to install Cursor CLI | +| `install_agentapi` | bool | `true` | Whether to install AgentAPI web interface | +| `folder` | string | `"/home/coder"` | Working directory for cursor-agent | + ## Troubleshooting The module creates log files in the workspace's `~/.cursor-cli-module` directory. Check these files if you encounter issues: diff --git a/registry/coder/modules/cursor-cli/main.tf b/registry/coder/modules/cursor-cli/main.tf index f05e48fe..75e86a87 100644 --- a/registry/coder/modules/cursor-cli/main.tf +++ b/registry/coder/modules/cursor-cli/main.tf @@ -78,6 +78,36 @@ variable "post_install_script" { default = null } +variable "enable_mcp" { + type = bool + description = "Whether to enable MCP (Model Context Protocol) support." + default = true +} + +variable "mcp_config_path" { + type = string + description = "Path to the MCP configuration file (mcp.json)." + default = "" +} + +variable "enable_force_mode" { + type = bool + description = "Whether to enable force mode for non-interactive automation." + default = false +} + +variable "default_model" { + type = string + description = "Default AI model to use (e.g., gpt-5, claude-4-sonnet)." + default = "" +} + +variable "enable_rules" { + type = bool + description = "Whether to enable the rules system (.cursor/rules directory)." + default = true +} + locals { app_slug = "cursor-cli" install_script = file("${path.module}/scripts/install.sh") @@ -114,6 +144,11 @@ module "agentapi" { ARG_FOLDER='${var.folder}' \ ARG_INSTALL='${var.install_cursor_cli}' \ + ARG_ENABLE_MCP='${var.enable_mcp}' \ + ARG_MCP_CONFIG_PATH='${var.mcp_config_path}' \ + ARG_ENABLE_FORCE_MODE='${var.enable_force_mode}' \ + ARG_DEFAULT_MODEL='${var.default_model}' \ + ARG_ENABLE_RULES='${var.enable_rules}' \ /tmp/install.sh EOT } diff --git a/registry/coder/modules/cursor-cli/scripts/install.sh b/registry/coder/modules/cursor-cli/scripts/install.sh index 4a0fadd0..60f4d006 100644 --- a/registry/coder/modules/cursor-cli/scripts/install.sh +++ b/registry/coder/modules/cursor-cli/scripts/install.sh @@ -10,6 +10,11 @@ set -o nounset echo "--------------------------------" echo "folder: $ARG_FOLDER" echo "install: $ARG_INSTALL" +echo "enable_mcp: $ARG_ENABLE_MCP" +echo "mcp_config_path: $ARG_MCP_CONFIG_PATH" +echo "enable_force_mode: $ARG_ENABLE_FORCE_MODE" +echo "default_model: $ARG_DEFAULT_MODEL" +echo "enable_rules: $ARG_ENABLE_RULES" echo "--------------------------------" set +o nounset @@ -28,6 +33,59 @@ if [ "${ARG_INSTALL}" = "true" ]; then fi echo "Cursor CLI installed" + + # Configure MCP if enabled + if [ "${ARG_ENABLE_MCP}" = "true" ]; then + echo "Configuring MCP (Model Context Protocol)..." + + # Create MCP config directory if it doesn't exist + mkdir -p "$HOME/.cursor" + + # If custom MCP config path is provided, copy it + if [ -n "${ARG_MCP_CONFIG_PATH}" ] && [ -f "${ARG_MCP_CONFIG_PATH}" ]; then + cp "${ARG_MCP_CONFIG_PATH}" "$HOME/.cursor/mcp.json" + echo "MCP configuration copied from ${ARG_MCP_CONFIG_PATH}" + else + # Create a basic MCP config if none exists + if [ ! -f "$HOME/.cursor/mcp.json" ]; then + cat > "$HOME/.cursor/mcp.json" << 'EOF' +{ + "mcpServers": { + "filesystem": { + "command": "npx", + "args": ["@modelcontextprotocol/server-filesystem", "/tmp"] + } + } +} +EOF + echo "Basic MCP configuration created" + fi + fi + fi + + # Configure rules system if enabled + if [ "${ARG_ENABLE_RULES}" = "true" ]; then + echo "Setting up Cursor rules system..." + mkdir -p "$HOME/.cursor/rules" + + # Create a basic rules file if none exists + if [ ! -f "$HOME/.cursor/rules/general.md" ]; then + cat > "$HOME/.cursor/rules/general.md" << 'EOF' +# General Coding Rules + +## Code Style +- Use consistent indentation (2 spaces for JS/TS, 4 for Python) +- Add meaningful comments for complex logic +- Follow language-specific naming conventions + +## Best Practices +- Write tests for new functionality +- Handle errors gracefully +- Use descriptive variable and function names +EOF + echo "Basic rules configuration created" + fi + fi else echo "Skipping Cursor CLI installation" fi diff --git a/registry/coder/modules/cursor-cli/scripts/start.sh b/registry/coder/modules/cursor-cli/scripts/start.sh index b397c188..a44e7f82 100644 --- a/registry/coder/modules/cursor-cli/scripts/start.sh +++ b/registry/coder/modules/cursor-cli/scripts/start.sh @@ -30,10 +30,32 @@ echo " - Start interactive session: cursor-agent" echo " - Non-interactive mode: cursor-agent -p 'your prompt here'" echo " - With specific model: cursor-agent -p 'prompt' --model 'gpt-5'" echo " - Text output format: cursor-agent -p 'prompt' --output-format text" +echo " - Force mode (non-interactive): cursor-agent -p 'prompt' --force" echo " - List sessions: cursor-agent ls" echo " - Resume session: cursor-agent resume" echo "" +# Set up environment variables for configuration +if [ -n "${ARG_DEFAULT_MODEL:-}" ]; then + export CURSOR_DEFAULT_MODEL="${ARG_DEFAULT_MODEL}" + echo "Default model set to: ${ARG_DEFAULT_MODEL}" +fi + +if [ "${ARG_ENABLE_FORCE_MODE:-false}" = "true" ]; then + export CURSOR_FORCE_MODE="true" + echo "Force mode enabled for non-interactive automation" +fi + +if [ "${ARG_ENABLE_MCP:-true}" = "true" ]; then + echo "MCP (Model Context Protocol) support enabled" +fi + +if [ "${ARG_ENABLE_RULES:-true}" = "true" ]; then + echo "Rules system enabled (.cursor/rules directory)" +fi + +echo "" + # Configure for interactive mode with text output # If no arguments provided, start in interactive mode if [ $# -eq 0 ]; then