From 4ab6fb2a2541c0e52a41a0a6c1c679616ecf9de8 Mon Sep 17 00:00:00 2001
From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com>
Date: Sat, 9 Aug 2025 18:30:52 +0000
Subject: [PATCH 1/6] cursor(module): add mcp input and write
 ~/.cursor/mcp.json via coder_script\n\nCo-authored-by: matifali
 <10648092+matifali@users.noreply.github.com>

---
 registry/coder/modules/cursor/main.test.ts | 29 +++++++++++++++++++++-
 registry/coder/modules/cursor/main.tf      | 26 +++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/registry/coder/modules/cursor/main.test.ts b/registry/coder/modules/cursor/main.test.ts
index ed92b9c9..5d10c823 100644
--- a/registry/coder/modules/cursor/main.test.ts
+++ b/registry/coder/modules/cursor/main.test.ts
@@ -1,8 +1,13 @@
-import { describe, expect, it } from "bun:test";
+import { describe, it, expect } from "bun:test";
 import {
   runTerraformApply,
   runTerraformInit,
   testRequiredVariables,
+  runContainer,
+  execContainer,
+  removeContainer,
+  findResourceInstance,
+  readFileContainer,
 } from "~test";
 
 describe("cursor", async () => {
@@ -85,4 +90,26 @@ describe("cursor", async () => {
     expect(coder_app?.instances.length).toBe(1);
     expect(coder_app?.instances[0].attributes.order).toBe(22);
   });
+
+  it("writes ~/.cursor/mcp.json when mcp provided", async () => {
+    const id = await runContainer("alpine");
+    try {
+      const mcp = JSON.stringify({ servers: { demo: { url: "http://localhost:1234" } } });
+      const state = await runTerraformApply(import.meta.dir, {
+        agent_id: "foo",
+        mcp,
+      });
+      const script = findResourceInstance(state, "coder_script", "cursor_mcp").script;
+      const resp = await execContainer(id, ["sh", "-c", script]);
+      if (resp.exitCode !== 0) {
+        console.log(resp.stdout);
+        console.log(resp.stderr);
+      }
+      expect(resp.exitCode).toBe(0);
+      const content = await readFileContainer(id, "/root/.cursor/mcp.json");
+      expect(content).toBe(mcp);
+    } finally {
+      await removeContainer(id);
+    }
+  });
 });
diff --git a/registry/coder/modules/cursor/main.tf b/registry/coder/modules/cursor/main.tf
index 47d35b62..a30c05ed 100644
--- a/registry/coder/modules/cursor/main.tf
+++ b/registry/coder/modules/cursor/main.tf
@@ -50,9 +50,20 @@ variable "display_name" {
   default     = "Cursor Desktop"
 }
 
+variable "mcp" {
+  type        = string
+  description = "JSON-encoded string to configure MCP servers for Cursor. When set, writes ~/.cursor/mcp.json."
+  default     = ""
+}
+
 data "coder_workspace" "me" {}
+
 data "coder_workspace_owner" "me" {}
 
+locals {
+  mcp_b64 = var.mcp != "" ? base64encode(var.mcp) : ""
+}
+
 resource "coder_app" "cursor" {
   agent_id     = var.agent_id
   external     = true
@@ -75,6 +86,21 @@ resource "coder_app" "cursor" {
   ])
 }
 
+resource "coder_script" "cursor_mcp" {
+  count         = var.mcp != "" ? 1 : 0
+  agent_id      = var.agent_id
+  display_name  = "Cursor MCP"
+  icon          = "/icon/cursor.svg"
+  run_on_start  = true
+  start_blocks_login = false
+  script        = <<-EOT
+    #!/bin/sh
+    set -eu
+    mkdir -p "$HOME/.cursor"
+    echo -n "${local.mcp_b64}" | base64 -d > "$HOME/.cursor/mcp.json"
+  EOT
+}
+
 output "cursor_url" {
   value       = coder_app.cursor.url
   description = "Cursor IDE Desktop URL."

From 0dbdbec38c66288b6efe933e773998b138d05377 Mon Sep 17 00:00:00 2001
From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com>
Date: Sat, 9 Aug 2025 18:31:31 +0000
Subject: [PATCH 2/6] docs(cursor): document mcp input and
 example\n\nCo-authored-by: matifali
 <10648092+matifali@users.noreply.github.com>

---
 registry/coder/modules/cursor/README.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/registry/coder/modules/cursor/README.md b/registry/coder/modules/cursor/README.md
index 9dba52b5..5f5fd8de 100644
--- a/registry/coder/modules/cursor/README.md
+++ b/registry/coder/modules/cursor/README.md
@@ -34,3 +34,21 @@ module "cursor" {
   folder   = "/home/coder/project"
 }
 ```
+
+### Configure MCP servers for Cursor
+
+Provide a JSON-encoded string via the `mcp` input. When set, the module writes the value to `~/.cursor/mcp.json` using a `coder_script` on workspace start.
+
+```tf
+module "cursor" {
+  count    = data.coder_workspace.me.start_count
+  source   = "registry.coder.com/coder/cursor/coder"
+  version  = "1.2.1"
+  agent_id = coder_agent.example.id
+  mcp      = jsonencode({
+    servers = {
+      demo = { url = "http://localhost:1234" }
+    }
+  })
+}
+```

From dd4c1c4bcd373c48417e64793195cab1265e1499 Mon Sep 17 00:00:00 2001
From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com>
Date: Sat, 9 Aug 2025 18:36:41 +0000
Subject: [PATCH 3/6] chore(cursor): fix Prettier formatting for
 README\n\nCo-authored-by: matifali
 <10648092+matifali@users.noreply.github.com>

---
 registry/coder/modules/cursor/README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/registry/coder/modules/cursor/README.md b/registry/coder/modules/cursor/README.md
index 5f5fd8de..4ff3107f 100644
--- a/registry/coder/modules/cursor/README.md
+++ b/registry/coder/modules/cursor/README.md
@@ -45,7 +45,7 @@ module "cursor" {
   source   = "registry.coder.com/coder/cursor/coder"
   version  = "1.2.1"
   agent_id = coder_agent.example.id
-  mcp      = jsonencode({
+  mcp = jsonencode({
     servers = {
       demo = { url = "http://localhost:1234" }
     }

From 699d7da33edd91da965a7ffd37ede1a6e641d8b2 Mon Sep 17 00:00:00 2001
From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com>
Date: Sat, 9 Aug 2025 18:37:57 +0000
Subject: [PATCH 4/6] chore(cursor): terraform fmt for
 main.tf\n\nCo-authored-by: matifali
 <10648092+matifali@users.noreply.github.com>

---
 registry/coder/modules/cursor/main.tf | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/registry/coder/modules/cursor/main.tf b/registry/coder/modules/cursor/main.tf
index a30c05ed..71aff72f 100644
--- a/registry/coder/modules/cursor/main.tf
+++ b/registry/coder/modules/cursor/main.tf
@@ -87,13 +87,13 @@ resource "coder_app" "cursor" {
 }
 
 resource "coder_script" "cursor_mcp" {
-  count         = var.mcp != "" ? 1 : 0
-  agent_id      = var.agent_id
-  display_name  = "Cursor MCP"
-  icon          = "/icon/cursor.svg"
-  run_on_start  = true
+  count              = var.mcp != "" ? 1 : 0
+  agent_id           = var.agent_id
+  display_name       = "Cursor MCP"
+  icon               = "/icon/cursor.svg"
+  run_on_start       = true
   start_blocks_login = false
-  script        = <<-EOT
+  script             = <<-EOT
     #!/bin/sh
     set -eu
     mkdir -p "$HOME/.cursor"

From 2aff889116ed3dda3950f115698826fb7f5dc9e2 Mon Sep 17 00:00:00 2001
From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com>
Date: Sat, 9 Aug 2025 18:41:31 +0000
Subject: [PATCH 5/6] chore: bump module versions (minor)

Co-authored-by: matifali <10648092+matifali@users.noreply.github.com>
---
 registry/coder/modules/cursor/README.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/registry/coder/modules/cursor/README.md b/registry/coder/modules/cursor/README.md
index 4ff3107f..99180a17 100644
--- a/registry/coder/modules/cursor/README.md
+++ b/registry/coder/modules/cursor/README.md
@@ -16,7 +16,7 @@ Uses the [Coder Remote VS Code Extension](https://github.com/coder/vscode-coder)
 module "cursor" {
   count    = data.coder_workspace.me.start_count
   source   = "registry.coder.com/coder/cursor/coder"
-  version  = "1.2.1"
+  version = "1.3.0"
   agent_id = coder_agent.example.id
 }
 ```
@@ -29,7 +29,7 @@ module "cursor" {
 module "cursor" {
   count    = data.coder_workspace.me.start_count
   source   = "registry.coder.com/coder/cursor/coder"
-  version  = "1.2.1"
+  version = "1.3.0"
   agent_id = coder_agent.example.id
   folder   = "/home/coder/project"
 }
@@ -43,7 +43,7 @@ Provide a JSON-encoded string via the `mcp` input. When set, the module writes t
 module "cursor" {
   count    = data.coder_workspace.me.start_count
   source   = "registry.coder.com/coder/cursor/coder"
-  version  = "1.2.1"
+  version = "1.3.0"
   agent_id = coder_agent.example.id
   mcp = jsonencode({
     servers = {

From 32d704dc8d7c0aad014b27cd4ede1945ce180556 Mon Sep 17 00:00:00 2001
From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com>
Date: Sat, 9 Aug 2025 18:42:25 +0000
Subject: [PATCH 6/6] docs(cursor): use realistic MCP server example (coder exp
 mcp server)

Co-authored-by: matifali <10648092+matifali@users.noreply.github.com>
---
 registry/coder/modules/cursor/README.md | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/registry/coder/modules/cursor/README.md b/registry/coder/modules/cursor/README.md
index 99180a17..3551e831 100644
--- a/registry/coder/modules/cursor/README.md
+++ b/registry/coder/modules/cursor/README.md
@@ -16,7 +16,7 @@ Uses the [Coder Remote VS Code Extension](https://github.com/coder/vscode-coder)
 module "cursor" {
   count    = data.coder_workspace.me.start_count
   source   = "registry.coder.com/coder/cursor/coder"
-  version = "1.3.0"
+  version  = "1.3.0"
   agent_id = coder_agent.example.id
 }
 ```
@@ -29,7 +29,7 @@ module "cursor" {
 module "cursor" {
   count    = data.coder_workspace.me.start_count
   source   = "registry.coder.com/coder/cursor/coder"
-  version = "1.3.0"
+  version  = "1.3.0"
   agent_id = coder_agent.example.id
   folder   = "/home/coder/project"
 }
@@ -43,11 +43,18 @@ Provide a JSON-encoded string via the `mcp` input. When set, the module writes t
 module "cursor" {
   count    = data.coder_workspace.me.start_count
   source   = "registry.coder.com/coder/cursor/coder"
-  version = "1.3.0"
+  version  = "1.3.0"
   agent_id = coder_agent.example.id
   mcp = jsonencode({
-    servers = {
-      demo = { url = "http://localhost:1234" }
+    mcpServers = {
+      coder = {
+        command = "coder"
+        args    = ["exp", "mcp", "server"]
+        env = {
+          CODER_MCP_APP_STATUS_SLUG = "cursor"
+          CODER_MCP_AI_AGENTAPI_URL = "http://localhost:3284"
+        }
+      }
     }
   })
 }
