@@ -10,6 +10,8 @@ tags: [agent, cursor, ai, cli]
1010
1111Run the Cursor Coding Agent in your workspace using the Cursor CLI directly.
1212
13+ A full example with MCP, rules, and pre/post install scripts:
14+
1315``` tf
1416
1517data "coder_parameter" "ai_prompt" {
@@ -27,15 +29,32 @@ module "cursor_cli" {
2729 # Optional
2830 install_cursor_cli = true
2931 cursor_cli_version = "latest"
30- force = false
32+ force = true
3133 model = "gpt-5"
3234 ai_prompt = data.coder_parameter.ai_prompt.value
35+
36+ # Minimal MCP server (writes `~/.cursor/mcp.json`):
3337 mcp_json = jsonencode({
3438 mcpServers = {
35- # example project-specific servers (see docs)
39+ playwright = {
40+ command = "npx"
41+ args = ["-y", "@playwright/mcp@latest", "--headless", "--isolated", "--no-sandbox"]
42+ }
43+ desktop-commander = {
44+ command = "npx"
45+ args = ["-y", "@wonderwhy-er/desktop-commander"]
46+ }
3647 }
3748 })
3849
50+ # Use a pre_install_script to install the CLI
51+ pre_install_script = <<-EOT
52+ #!/usr/bin/env bash
53+ set -euo pipefail
54+ curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
55+ apt-get install -y nodejs
56+ EOT
57+
3958 # Use post_install_script to wait for the repo to be ready
4059 post_install_script = <<-EOT
4160 #!/usr/bin/env bash
@@ -48,92 +67,8 @@ module "cursor_cli" {
4867 done
4968 echo "timeout waiting for ${TARGET}" >&2
5069 EOT
51- }
52- ```
53-
54- ## Examples
55-
56- ### MCP configuration
57-
58- Minimal MCP server (writes ` ~/.cursor/mcp.json ` ):
59-
60- ``` tf
61- module "cursor_cli" {
62- source = "registry.coder.com/coder-labs/cursor-cli/coder"
63- version = "0.1.0"
64- agent_id = coder_agent.example.id
65- folder = "/home/coder/project"
66-
67- mcp_json = jsonencode({
68- mcpServers = {
69- tools = {
70- command = "/usr/local/bin/tools-server"
71- type = "stdio"
72- }
73- }
74- })
75- }
76- ```
77-
78- Multiple servers with args and env:
79-
80- ``` tf
81- module "cursor_cli" {
82- source = "registry.coder.com/coder-labs/cursor-cli/coder"
83- version = "0.1.0"
84- agent_id = coder_agent.example.id
85- folder = "/home/coder/project"
86-
87- mcp_json = jsonencode({
88- mcpServers = {
89- playwright = {
90- command = "npx"
91- args = ["-y", "@playwright/mcp@latest", "--headless", "--isolated", "--no-sandbox"]
92- }
93- desktop-commander = {
94- command = "npx"
95- args = ["-y", "@wonderwhy-er/desktop-commander"]
96- }
97- }
98- })
99- }
100- ```
101-
102- ### Rules
103-
104- Provide a map of file name to content; files are written to ` ~/.cursor/rules/<name> ` .
105-
106- Single rules file:
107-
108- ``` tf
109- module "cursor_cli" {
110- source = "registry.coder.com/coder-labs/cursor-cli/coder"
111- version = "0.1.0"
112- agent_id = coder_agent.example.id
113- folder = "/home/coder/project"
114-
115- rules_files = {
116- "global.yml" = <<-EOT
117- version: 1
118- rules:
119- - name: frontend
120- include: ['**/*']
121- exclude: ['node_modules/**', '.git/**']
122- description: Frontend rules
123- EOT
124- }
125- }
126- ```
127-
128- Multiple rules files (language-specific):
129-
130- ``` tf
131- module "cursor_cli" {
132- source = "registry.coder.com/coder-labs/cursor-cli/coder"
133- version = "0.1.0"
134- agent_id = coder_agent.example.id
135- folder = "/home/coder/project"
13670
71+ # Provide a map of file name to content; files are written to `~/.cursor/rules/<name>`.
13772 rules_files = {
13873 "python.yml" = <<-EOT
13974 version: 1
@@ -155,7 +90,7 @@ module "cursor_cli" {
15590}
15691```
15792
158- ## Notes
93+ ## References
15994
16095- See Cursor CLI docs: ` https://docs.cursor.com/en/cli/overview `
16196- For MCP project config, see ` https://docs.cursor.com/en/context/mcp#using-mcp-json ` . This module writes your ` mcp_json ` into ` ~/.cursor/mcp.json ` .
0 commit comments