Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-4203: Fix Cursor MCP auth source seeding (ZIC-52)
ZIcefe46dfdbf665
diff --git a/apps/docs/content/docs/install-agent-runtime.mdx b/apps/docs/content/docs/install-agent-runtime.mdxindex a77947c6e4..fe426b5c62 100644--- a/apps/docs/content/docs/install-agent-runtime.mdx+++ b/apps/docs/content/docs/install-agent-runtime.mdx@@ -66,6 +66,8 @@ The CLI counterpart to the Cursor editor. **Session resumption works** with curr| Install | Install the [Cursor editor](https://cursor.com/) and then the CLI per their docs at [docs.cursor.com](https://docs.cursor.com/). The binary name is `cursor-agent`, not `cursor`. || Authentication | Sign in through the Cursor editor; the CLI reuses that session. |+For authenticated MCP servers, Cursor stores OAuth state in the project data directory where the auth flow first ran. Multica isolates managed Cursor MCP runs with a per-task `CURSOR_DATA_DIR`, so it does not scan or copy every file under `~/.cursor/projects`. To opt in for one agent, set the agent custom env key `CURSOR_MCP_AUTH_SOURCE` to the absolute path of the trusted `mcp-auth.json` file, or to the Cursor project data directory containing that file. Multica links or seeds only that `mcp-auth.json` into the isolated task project data directory. When symlinks are supported, Cursor token refreshes may write back to the trusted source; environments that cannot create symlinks fall back to copying the file.+### GitHub CopilotModel routing goes through your GitHub account entitlement — the tool doesn't pick a model itself; GitHub decides which model you get.diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex dba822ebdc..0fdf12fa7a 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -3588,8 +3588,12 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, slot i// Squad-leader tasks also skip reuse so a pre-fix leader session recorded// against the user's local_directory cannot be re-entered without a lock.var agentMcpConfig json.RawMessage+ var cursorMcpAuthSource stringif task.Agent != nil {agentMcpConfig = task.Agent.McpConfig+ if provider == "cursor" {+ cursorMcpAuthSource = strings.TrimSpace(task.Agent.CustomEnv[execenv.CursorMcpAuthSourceEnv])+ }}// Decode openclaw-specific runtime_config knobs once so reuse / prepare /// ExecOptions all see the same mode + gateway pin (issue #3260). Parse@@ -3602,29 +3606,31 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, slot i}if task.PriorWorkDir != "" && localAssignment == nil && !task.IsLeaderTask {env = execenv.Reuse(execenv.ReuseParams{- WorkspacesRoot: d.cfg.WorkspacesRoot,- WorkDir: task.PriorWorkDir,- Provider: provider,- CodexVersion: codexVersion,- OpenclawBin: openclawBin,- McpConfig: agentMcpConfig,- OpenclawGateway: openclawGateway,- Task: taskCtx,+ WorkspacesRoot: d.cfg.WorkspacesRoot,+ WorkDir: task.PriorWorkDir,+ Provider: provider,+ CodexVersion: codexVersion,+ OpenclawBin: openclawBin,+ McpConfig: agentMcpConfig,+ CursorMcpAuthSource: cursorMcpAuthSource,+ OpenclawGateway: openclawGateway,+ Task: taskCtx,}, d.logger)}if env == nil {var err errorprepParams := execenv.PrepareParams{- WorkspacesRoot: d.cfg.WorkspacesRoot,- WorkspaceID: task.WorkspaceID,- TaskID: task.ID,- AgentName: agentName,- Provider: provider,- CodexVersion: codexVersion,- OpenclawBin: openclawBin,- McpConfig: agentMcpConfig,- OpenclawGateway: openclawGateway,- Task: taskCtx,+ WorkspacesRoot: d.cfg.WorkspacesRoot,+ WorkspaceID: task.WorkspaceID,+ TaskID: task.ID,+ AgentName: agentName,+ Provider: provider,+ CodexVersion: codexVersion,+ OpenclawBin: openclawBin,+ McpConfig: agentMcpConfig,+ CursorMcpAuthSource: cursorMcpAuthSource,+ OpenclawGateway: openclawGateway,+ Task: taskCtx,}if localAssignment != nil {prepParams.LocalWorkDir = localAssignment.AbsPath@@ -4700,7 +4706,7 @@ func isBlockedEnvKey(key string) bool {return true}switch upper {- case "HOME", "PATH", "USER", "SHELL", "TERM", "TMPDIR", "TMP", "TEMP", "CODEX_HOME", "CURSOR_DATA_DIR", "OPENCLAW_CONFIG_PATH", "OPENCLAW_INCLUDE_ROOTS":+ case "HOME", "PATH", "USER", "SHELL", "TERM", "TMPDIR", "TMP", "TEMP", "CODEX_HOME", "CURSOR_DATA_DIR", execenv.CursorMcpAuthSourceEnv, "OPENCLAW_CONFIG_PATH", "OPENCLAW_INCLUDE_ROOTS":return true}return falsediff --git a/server/internal/daemon/daemon_test.go b/server/internal/daemon/daemon_test.goindex 55124329b5..8687c10bec 100644--- a/server/internal/daemon/daemon_test.go+++ b/server/internal/daemon/daemon_test.go@@ -99,6 +99,7 @@ func TestIsBlockedEnvKey(t *testing.T) {{key: "CODEX_HOME", want: true},{key: "CURSOR_DATA_DIR", want: true},{key: "cursor_data_dir", want: true},+ {key: "CURSOR_MCP_AUTH_SOURCE", want: true},{key: "OPENCLAW_CONFIG_PATH", want: true},{key: "OPENCLAW_INCLUDE_ROOTS", want: true},{key: "ANTHROPIC_API_KEY", want: false},diff --git a/server/internal/daemon/execenv/cursor_mcp.go b/server/internal/daemon/execenv/cursor_mcp.goindex d6b581b15c..f8e6c2de7e 100644--- a/server/internal/daemon/execenv/cursor_mcp.go+++ b/server/internal/daemon/execenv/cursor_mcp.go@@ -7,13 +7,25 @@ import ("encoding/json""errors""fmt"+ "io"+ "io/fs""os""path/filepath""sort""strings")-const cursorWorkspaceTrustedFile = ".workspace-trusted"+const (+ // CursorMcpAuthSourceEnv is an agent custom_env key the daemon consumes+ // before launching cursor-agent. When set, it must point at an explicit+ // mcp-auth.json file, or at a Cursor project data directory containing one.+ // The key is intentionally not MULTICA_* because custom_env blocks those+ // from being set by users.+ CursorMcpAuthSourceEnv = "CURSOR_MCP_AUTH_SOURCE"++ cursorWorkspaceTrustedFile = ".workspace-trusted"+ cursorMcpAuthFile = "mcp-auth.json"+)type cursorMcpConfigFile struct {McpServers map[string]json.RawMessage `json:"mcpServers"`@@ -22,7 +34,7 @@ type cursorMcpConfigFile struct {// prepareCursorMcpConfig writes the Cursor-native MCP sidecars for agents that// have an explicit managed mcp_config saved. A nil/null mcp_config means "let// Cursor behave normally", so no .cursor/mcp.json or CURSOR_DATA_DIR is created.-func prepareCursorMcpConfig(envRoot, workDir string, mcpConfig json.RawMessage, manifest *sidecarManifest) (string, error) {+func prepareCursorMcpConfig(envRoot, workDir string, mcpConfig json.RawMessage, mcpAuthSource string, manifest *sidecarManifest) (string, error) {if !hasManagedCursorMcpConfig(mcpConfig) {return "", nil}@@ -56,6 +68,9 @@ func prepareCursorMcpConfig(envRoot, workDir string, mcpConfig json.RawMessage,if err := os.MkdirAll(projectDataDir, 0o700); err != nil {return "", fmt.Errorf("create cursor project data dir: %w", err)}+ if err := removeCursorMcpAuthFile(projectDataDir); err != nil {+ return "", err+ }approvals, err := cursorMcpApprovalKeys(projectRoot, servers)if err != nil {return "", err@@ -78,10 +93,102 @@ func prepareCursorMcpConfig(envRoot, workDir string, mcpConfig json.RawMessage,if err := os.WriteFile(filepath.Join(projectDataDir, cursorWorkspaceTrustedFile), trustData, 0o600); err != nil {return "", fmt.Errorf("write cursor workspace trust: %w", err)}+ if strings.TrimSpace(mcpAuthSource) != "" {+ if err := seedCursorMcpAuthFile(projectDataDir, mcpAuthSource); err != nil {+ return "", err+ }+ }return cursorDataDir, nil}+func seedCursorMcpAuthFile(projectDataDir, source string) error {+ sourcePath, err := resolveCursorMcpAuthSource(source)+ if err != nil {+ return err+ }+ target := filepath.Join(projectDataDir, cursorMcpAuthFile)+ if err := os.Symlink(sourcePath, target); err == nil {+ return nil+ }+ if err := copyCursorMcpAuthFile(target, sourcePath); err != nil {+ return fmt.Errorf("seed cursor mcp auth file: %w", err)+ }+ return nil+}++func removeCursorMcpAuthFile(projectDataDir string) error {+ target := filepath.Join(projectDataDir, cursorMcpAuthFile)+ if err := os.Remove(target); err != nil && !errors.Is(err, fs.ErrNotExist) {+ return fmt.Errorf("remove prior cursor mcp auth file: %w", err)+ }+ return nil+}++func resolveCursorMcpAuthSource(source string) (string, error) {+ source = strings.TrimSpace(source)+ if source == "" {+ return "", fmt.Errorf("%s is empty", CursorMcpAuthSourceEnv)+ }+ if source == "~" || strings.HasPrefix(source, "~/") {+ home, err := os.UserHomeDir()+ if err != nil {+ return "", fmt.Errorf("resolve %s home directory: %w", CursorMcpAuthSourceEnv, err)+ }+ if source == "~" {+ source = home+ } else {+ source = filepath.Join(home, source[2:])+ }+ }+ if !filepath.IsAbs(source) {+ return "", fmt.Errorf("%s must be an absolute path to %s or its containing Cursor project directory", CursorMcpAuthSourceEnv, cursorMcpAuthFile)+ }+ source = filepath.Clean(source)+ info, err := os.Stat(source)+ if err != nil {+ return "", fmt.Errorf("stat %s: %w", CursorMcpAuthSourceEnv, err)+ }+ if info.IsDir() {+ source = filepath.Join(source, cursorMcpAuthFile)+ info, err = os.Stat(source)+ if err != nil {+ return "", fmt.Errorf("stat %s %s: %w", CursorMcpAuthSourceEnv, cursorMcpAuthFile, err)+ }+ }+ if info.IsDir() {+ return "", fmt.Errorf("%s must resolve to a file, got directory %s", CursorMcpAuthSourceEnv, source)+ }+ if filepath.Base(source) != cursorMcpAuthFile {+ return "", fmt.Errorf("%s must point at %s, got %s", CursorMcpAuthSourceEnv, cursorMcpAuthFile, filepath.Base(source))+ }+ return source, nil+}++func copyCursorMcpAuthFile(target, source string) error {+ in, err := os.Open(source)+ if err != nil {+ return err+ }+ defer in.Close()++ out, err := os.OpenFile(target, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600)+ if err != nil {+ return err+ }+ _, copyErr := io.Copy(out, in)+ closeErr := out.Close()+ if copyErr != nil {+ _ = os.Remove(target)+ return copyErr+ }+ if closeErr != nil {+ _ = os.Remove(target)+ return closeErr+ }+ return nil+}+func hasManagedCursorMcpConfig(raw json.RawMessage) bool {trimmed := bytes.TrimSpace(raw)return len(trimmed) > 0 && !bytes.Equal(trimmed, []byte("null"))diff --git a/server/internal/daemon/execenv/cursor_mcp_test.go b/server/internal/daemon/execenv/cursor_mcp_test.goindex ad48774de3..337969dd29 100644--- a/server/internal/daemon/execenv/cursor_mcp_test.go+++ b/server/internal/daemon/execenv/cursor_mcp_test.go@@ -39,7 +39,7 @@ func TestPrepareCursorMcpConfigWritesProjectConfigAndApprovals(t *testing.T) {}}`)- cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, mcpConfig, manifest)+ cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, mcpConfig, "", manifest)if err != nil {t.Fatalf("prepareCursorMcpConfig: %v", err)}@@ -98,7 +98,7 @@ func TestPrepareCursorMcpConfigManagedEmptySet(t *testing.T) {if err := os.MkdirAll(workDir, 0o755); err != nil {t.Fatalf("mkdir workDir: %v", err)}- cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, json.RawMessage(`{"mcpServers":{}}`), &sidecarManifest{})+ cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, json.RawMessage(`{"mcpServers":{}}`), "", &sidecarManifest{})if err != nil {t.Fatalf("prepareCursorMcpConfig: %v", err)}@@ -119,6 +119,95 @@ func TestPrepareCursorMcpConfigManagedEmptySet(t *testing.T) {}}+func TestPrepareCursorMcpConfigSeedsExplicitAuthSource(t *testing.T) {+ t.Parallel()++ envRoot := t.TempDir()+ workDir := filepath.Join(envRoot, "workdir")+ if err := os.MkdirAll(workDir, 0o755); err != nil {+ t.Fatalf("mkdir workDir: %v", err)+ }+ sourceProjectDir := filepath.Join(envRoot, "source-project")+ if err := os.MkdirAll(sourceProjectDir, 0o700); err != nil {+ t.Fatalf("mkdir source project: %v", err)+ }+ sourceAuth := filepath.Join(sourceProjectDir, cursorMcpAuthFile)+ if err := os.WriteFile(sourceAuth, []byte(`{"tokens":{"fetch":"secret"}}`), 0o600); err != nil {+ t.Fatalf("write source auth: %v", err)+ }++ cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, json.RawMessage(`{"mcpServers":{"fetch":{"command":"uvx","args":["mcp-server-fetch"]}}}`), sourceProjectDir, &sidecarManifest{})+ if err != nil {+ t.Fatalf("prepareCursorMcpConfig: %v", err)+ }+ projectRoot := cursorProjectRoot(workDir)+ targetAuth := filepath.Join(cursorDataDir, "projects", cursorSlugifyPath(projectRoot), cursorMcpAuthFile)+ data, err := os.ReadFile(targetAuth)+ if err != nil {+ t.Fatalf("read seeded auth: %v", err)+ }+ if string(data) != `{"tokens":{"fetch":"secret"}}` {+ t.Fatalf("seeded auth = %s", data)+ }+}++func TestPrepareCursorMcpConfigRemovesPriorAuthOnOptOut(t *testing.T) {+ t.Parallel()++ envRoot := t.TempDir()+ workDir := filepath.Join(envRoot, "workdir")+ if err := os.MkdirAll(workDir, 0o755); err != nil {+ t.Fatalf("mkdir workDir: %v", err)+ }+ sourceProjectDir := filepath.Join(envRoot, "source-project")+ if err := os.MkdirAll(sourceProjectDir, 0o700); err != nil {+ t.Fatalf("mkdir source project: %v", err)+ }+ sourceAuth := filepath.Join(sourceProjectDir, cursorMcpAuthFile)+ if err := os.WriteFile(sourceAuth, []byte(`{"tokens":{"fetch":"secret"}}`), 0o600); err != nil {+ t.Fatalf("write source auth: %v", err)+ }+ mcpConfig := json.RawMessage(`{"mcpServers":{"fetch":{"command":"uvx","args":["mcp-server-fetch"]}}}`)++ cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, mcpConfig, sourceProjectDir, nil)+ if err != nil {+ t.Fatalf("prepareCursorMcpConfig with auth source: %v", err)+ }+ projectRoot := cursorProjectRoot(workDir)+ targetAuth := filepath.Join(cursorDataDir, "projects", cursorSlugifyPath(projectRoot), cursorMcpAuthFile)+ if _, err := os.Stat(targetAuth); err != nil {+ t.Fatalf("seeded auth missing: %v", err)+ }++ cursorDataDir, err = prepareCursorMcpConfig(envRoot, workDir, mcpConfig, "", nil)+ if err != nil {+ t.Fatalf("prepareCursorMcpConfig without auth source: %v", err)+ }+ targetAuth = filepath.Join(cursorDataDir, "projects", cursorSlugifyPath(projectRoot), cursorMcpAuthFile)+ if _, err := os.Stat(targetAuth); !os.IsNotExist(err) {+ t.Fatalf("auth file should be removed after opt-out, stat err=%v", err)+ }+}++func TestPrepareCursorMcpConfigRejectsArbitraryAuthSourceFile(t *testing.T) {+ t.Parallel()++ envRoot := t.TempDir()+ workDir := filepath.Join(envRoot, "workdir")+ if err := os.MkdirAll(workDir, 0o755); err != nil {+ t.Fatalf("mkdir workDir: %v", err)+ }+ source := filepath.Join(envRoot, "other.json")+ if err := os.WriteFile(source, []byte(`{"secret":true}`), 0o600); err != nil {+ t.Fatalf("write source: %v", err)+ }++ _, err := prepareCursorMcpConfig(envRoot, workDir, json.RawMessage(`{"mcpServers":{}}`), source, &sidecarManifest{})+ if err == nil {+ t.Fatal("expected non-mcp-auth source file to fail")+ }+}+func TestPrepareCursorMcpConfigNilDoesNotTakeOwnership(t *testing.T) {t.Parallel()@@ -127,7 +216,7 @@ func TestPrepareCursorMcpConfigNilDoesNotTakeOwnership(t *testing.T) {if err := os.MkdirAll(workDir, 0o755); err != nil {t.Fatalf("mkdir workDir: %v", err)}- cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, nil, &sidecarManifest{})+ cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, nil, "", &sidecarManifest{})if err != nil {t.Fatalf("prepareCursorMcpConfig: %v", err)}@@ -147,7 +236,7 @@ func TestPrepareCursorMcpConfigRejectsMalformedConfig(t *testing.T) {if err := os.MkdirAll(workDir, 0o755); err != nil {t.Fatalf("mkdir workDir: %v", err)}- _, err := prepareCursorMcpConfig(envRoot, workDir, json.RawMessage(`{"mcpServers":{"bad":42}}`), &sidecarManifest{})+ _, err := prepareCursorMcpConfig(envRoot, workDir, json.RawMessage(`{"mcpServers":{"bad":42}}`), "", &sidecarManifest{})if err == nil {t.Fatal("expected malformed server config to fail")}diff --git a/server/internal/daemon/execenv/execenv.go b/server/internal/daemon/execenv/execenv.goindex db2225e740..2c4aeda477 100644--- a/server/internal/daemon/execenv/execenv.go+++ b/server/internal/daemon/execenv/execenv.go@@ -47,6 +47,10 @@ type PrepareParams struct {// via a per-task config file. Cursor and OpenClaw consume it here; other// providers wire MCP via ExecOptions.McpConfig in the agent backend.McpConfig json.RawMessage+ // CursorMcpAuthSource is an explicit opt-in path to a Cursor mcp-auth.json+ // file, or the Cursor project data directory containing it. Only Cursor's+ // managed MCP path consumes it.+ CursorMcpAuthSource string// OpenclawGateway pins the OpenClaw Gateway endpoint inside the per-task// wrapper. Only consulted when Provider == "openclaw" and the agent's// runtime_config selected gateway mode (issue #3260). Zero means "inherit@@ -267,7 +271,7 @@ func Prepare(params PrepareParams, logger *slog.Logger) (*Environment, error) {// this per-task data dir can load, so user-global MCP servers do not leak// into managed-MCP runs.if params.Provider == "cursor" {- cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, params.McpConfig, manifest)+ cursorDataDir, err := prepareCursorMcpConfig(envRoot, workDir, params.McpConfig, params.CursorMcpAuthSource, manifest)if err != nil {return nil, fmt.Errorf("execenv: prepare cursor mcp config: %w", err)}@@ -319,6 +323,8 @@ type ReuseParams struct {// task starts — without this a stale wrapper from a prior run would keep// the old MCP set in play.McpConfig json.RawMessage+ // CursorMcpAuthSource mirrors PrepareParams.CursorMcpAuthSource on reuse.+ CursorMcpAuthSource string// OpenclawGateway is the per-task Gateway pin re-applied on reuse so the// agent picks up any runtime_config changes saved since the prior run.OpenclawGateway OpenclawGatewayPin@@ -437,7 +443,7 @@ func Reuse(params ReuseParams, logger *slog.Logger) *Environment {// mcp_config must replace the prior run's .cursor/mcp.json and isolated// approvals before the next cursor-agent process starts.if params.Provider == "cursor" && env.RootDir != "" {- cursorDataDir, err := prepareCursorMcpConfig(env.RootDir, params.WorkDir, params.McpConfig, manifest)+ cursorDataDir, err := prepareCursorMcpConfig(env.RootDir, params.WorkDir, params.McpConfig, params.CursorMcpAuthSource, manifest)if err != nil {logger.Warn("execenv: refresh cursor mcp config failed", "error", err)return nil