Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions registry/coder/modules/zed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,29 @@ module "zed" {
agent_name = coder_agent.example.name
}
```

### Configure Zed settings including MCP servers

Zed stores settings at `~/.config/zed/settings.json` by default. If `XDG_CONFIG_HOME` is set on Linux, settings will be at `$XDG_CONFIG_HOME/zed/settings.json`.

You can declaratively set/merge settings with the `settings` input. For example, to configure MCP servers:

```tf
module "zed" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/zed/coder"
version = "1.0.1"
agent_id = coder_agent.example.id

settings = {
context_servers = {
your-mcp-server = {
source = "custom"
command = "some-command"
args = ["arg-1", "arg-2"]
env = {}
}
}
}
}
```
31 changes: 31 additions & 0 deletions registry/coder/modules/zed/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ variable "display_name" {
default = "Zed"
}

variable "settings" {
type = any
description = "Optional object of Zed settings to write to settings.json (merged if jq is available)."
default = {}
}

data "coder_workspace" "me" {}

data "coder_workspace_owner" "me" {}

locals {
Expand All @@ -60,6 +67,30 @@ locals {
hostname = var.agent_name != "" ? "${local.agent_name}.${local.workspace_name}.${local.owner_name}.coder" : "${local.workspace_name}.coder"
}

resource "coder_script" "zed_settings" {
agent_id = var.agent_id
display_name = "Configure Zed settings"
icon = "/icon/zed.svg"
run_on_start = true
script = <<-EOT
set -eu
SETTINGS_JSON='${replace(jsonencode(var.settings), "\"", "\\\"")}'
if [ "$${SETTINGS_JSON}" = "{}" ] || [ -z "$${SETTINGS_JSON}" ]; then
exit 0
fi
CONFIG_HOME="$${XDG_CONFIG_HOME:-$HOME/.config}"
ZED_DIR="$${CONFIG_HOME}/zed"
mkdir -p "$${ZED_DIR}"
SETTINGS_FILE="$${ZED_DIR}/settings.json"
if command -v jq >/dev/null 2>&1 && [ -s "$${SETTINGS_FILE}" ]; then
tmpfile="$(mktemp)"
jq -s '.[0] * .[1]' "$${SETTINGS_FILE}" <(printf '%s\n' "$${SETTINGS_JSON}") > "$${tmpfile}" && mv "$${tmpfile}" "$${SETTINGS_FILE}"
else
printf '%s\n' "$${SETTINGS_JSON}" > "$${SETTINGS_FILE}"
fi
EOT
}

resource "coder_app" "zed" {
agent_id = var.agent_id
display_name = var.display_name
Expand Down