Skip to content

feat(install): --env=KEY=VAL flag for the install CLI - #45

Merged
rrader26 merged 1 commit into
feat/memory-default-plugin-env-awarefrom
feat/install-env-support
May 15, 2026
Merged

feat(install): --env=KEY=VAL flag for the install CLI#45
rrader26 merged 1 commit into
feat/memory-default-plugin-env-awarefrom
feat/install-env-support

Conversation

@rrader26

Copy link
Copy Markdown
Contributor

Summary

PR β of the ThinkFleet Memory Bridge slice. Stacked on #44.

agentmark-mcp install now accepts --env=KEY=VALUE (repeatable) and writes those vars into the MCP server entry's env field. Combined with #44's env-aware memory backend, one install command wires every supported AI tool to talk to the ThinkFleet hierarchical memory:

```
agentmark-mcp install \
--client=claude-code,cursor,windsurf,codex-cli \
--env=THINKFLEET_BASE_URL=https://app.thinkfleet.ai \
--env=THINKFLEET_PROJECT_ID=proj_xxx \
--env=THINKFLEET_API_KEY=sk-xxx
```

Refactor

parseFlags / parseEnvFlag / buildEntryFromFlags moved from cli.tssrc/mcp/install/flags.ts. The extraction is needed because tests can't import cli.ts directly (it has top-level main() side effects).

Validation (all of these MUST throw)

Input Why it's rejected
--env=NOEQUALS Missing =
--env==value Empty key
--env=FOO;rm=anything Shell metacharacters in key
--env=FOO BAR=x Whitespace in key
--env=1FOO=bar Key starts with digit
--env=FOO=before\0after Null byte in value
--env=FOO=<4KB+ string> Value cap — prevents config bombs

Duplicate keys: stderr warning, last value wins. The warning contains the key name but never the values.

Security

Codified in HELP text:

  • --env values are written to the client's MCP config file on disk (e.g. ~/.cursor/mcp.json)
  • Prefer rotating from an OS keychain rather than passing long-lived keys on a shared machine
  • ThinkFleet Desktop (PR γ, upcoming) wires this from Electron safeStorage so secrets live in the OS keychain at rest

Error messages never echo the supplied value back, only the key name (or first 4 chars when the key shape is the problem).

Tests

  • test/mcp/install-flags.test.ts22 cases covering each validation branch + the duplicate-key warning semantics
  • test/mcp/install.test.ts2 new e2e cases proving the env block lands in the written JSON and that re-running with new values updates idempotently

564 tests pass. Typecheck clean. No new dependencies.

Next

  • γ — ThinkFleet Desktop installer reads creds from OS keychain (Electron safeStorage) and runs this CLI with --env flags. First fully end-to-end wiring of memory to all installed AI tools.
  • δ — Canonical thinkfleet-memory.skill.yaml + per-tool installer (Claude Code skills, Cursor rules, etc.).

🤖 Generated with Claude Code

The companion to PR #44 (env-aware memory backend). Now the install
CLI can write the env block into client MCP configs, so
`agentmark-mcp install --env=THINKFLEET_API_KEY=sk-…` makes the
memory plugin in PR #44 actually pick up SaaS creds at startup.

Surface:
  agentmark-mcp install \\
      --client=claude-code \\
      --env=THINKFLEET_BASE_URL=https://app.thinkfleet.ai \\
      --env=THINKFLEET_PROJECT_ID=proj_xxx \\
      --env=THINKFLEET_API_KEY=sk-xxx

The values land in the MCP server entry's `env` field — Claude Code,
Cursor, Windsurf, Codex CLI all already honor that.

Refactor:
  - parseFlags / parseEnvFlag / buildEntryFromFlags moved from
    cli.ts to src/mcp/install/flags.ts. cli.ts imports them. The
    extraction is needed because tests can't import cli.ts directly
    (it has top-level main() side effects that spawn the MCP server).

Validation (all of these MUST throw):
  - Missing or empty key:           --env=NOEQUALS, --env==value
  - Shell-relevant chars in key:    --env=FOO;rm=anything
  - Whitespace in key:              --env=FOO BAR=x
  - Key starting with a digit:      --env=1FOO=bar
  - Null byte in value:             --env=FOO=before\0after
  - Value over 4KB cap:             prevents config-bomb injection

Behavior:
  - Duplicate --env=KEY=… prints a stderr warning and uses last.
    Warning contains only the key name; values never echo.
  - `--env=FLAG=` (empty value) is legal — some env-driven flags
    expect that.
  - Mixed-case keys allowed (NodeEnv-style); strictly alphanumeric +
    underscore otherwise.

Security note (codified in HELP text):
  - --env values are written to the client's MCP config file on disk
    (e.g. ~/.cursor/mcp.json). Prefer rotating from an OS keychain
    rather than passing long-lived keys on a shared machine.
  - ThinkFleet Desktop (PR γ, upcoming) wires this from Electron
    safeStorage so secrets live in the OS keychain at rest and only
    surface as --env at install time.

Tests:
  - test/mcp/install-flags.test.ts — 22 cases covering each
    validation branch + the duplicate-key warning semantics.
  - test/mcp/install.test.ts — 2 new e2e cases proving the env
    block lands in the written JSON and that re-running with new
    values updates idempotently.

564 tests pass. Typecheck clean. No new dependencies.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants