mystack-rig 1.2.1__tar.gz → 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/GLOSSARY.md +16 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/PKG-INFO +44 -5
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/README.md +43 -4
- mystack_rig-1.3.0/docs/adr/0003-mcp-servers-declared-once-rendered-at-authorize.md +18 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/agents.py +12 -51
- mystack_rig-1.3.0/src/cli/ansible_filters/__init__.py +0 -0
- mystack_rig-1.3.0/src/cli/ansible_filters/rig_mcp.py +318 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/main.py +78 -1
- mystack_rig-1.3.0/src/cli/mcp.py +267 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/remote_dev.py +221 -118
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/snapshots.py +10 -28
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/vault_keys.py +9 -1
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/mystack_rig.egg-info/PKG-INFO +44 -5
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/mystack_rig.egg-info/SOURCES.txt +6 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/mystack_rig.egg-info/scm_file_list.json +6 -0
- mystack_rig-1.3.0/src/mystack_rig.egg-info/scm_version.json +8 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_agents.py +3 -3
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_ansible_galaxy.py +12 -32
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_init_command.py +4 -4
- mystack_rig-1.3.0/tests/test_mcp_command.py +293 -0
- mystack_rig-1.3.0/tests/test_mcp_render.py +199 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_remote_dev_coverage_extensions.py +90 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_setup_provision.py +306 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_snapshots.py +34 -3
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_vault_keys.py +21 -0
- mystack_rig-1.2.1/src/mystack_rig.egg-info/scm_version.json +0 -8
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/.coveragerc +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/.flake8 +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/.github/workflows/release.yml +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/.github/workflows/tests.yml +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/.gitignore +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/.rig/playbooks/README.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/.rig/playbooks/vpn-gateway.yml +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/CLI_STORAGE_SUMMARY.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/Dockerfile +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/GIT_CLONE_FEATURE.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/HETZNER_STORAGE_GUIDE.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/HETZNER_STORAGE_SECURITY_GUIDE.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/LICENSE +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/Makefile +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/README_REAL_E2E.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/STORAGE_CLI_GUIDE.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/docs/adr/0001-per-profile-generated-state-bucket.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/docs/adr/0002-outputs-as-separate-object-via-file-handoff.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/docs/architecture.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/docs/architecture.png +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/docs/architecture.svg +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/forged-idea.md +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/pyproject.toml +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/pytest.ini +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/requirements.txt +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/sample.env +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/scripts/coverage_badge.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/scripts/pypi_version.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/setup.cfg +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/__init__.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/__init__.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/__main__.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/config.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/encrypt.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/git.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/last_env.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/last_session.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/log.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/outputs.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/requirements.txt +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/state_bucket.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/storage.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/cli/vpn.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/mystack_rig.egg-info/dependency_links.txt +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/mystack_rig.egg-info/entry_points.txt +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/mystack_rig.egg-info/requires.txt +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/src/mystack_rig.egg-info/top_level.txt +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/test_hetzner_integration.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/conftest.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_attach_command.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_credential_security.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_destroy_command.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_dev_command.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_encrypt_command.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_encrypt_coverage.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_firewall_client_ip.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_git_clone_unit.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_git_manager.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_gitignore_init.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_hetzner_storage.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_inspect_describe.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_last_env.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_last_session.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_log.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_main_coverage.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_outputs.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_outputs_storage.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_pypi_version.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_real_e2e_integration.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_real_e2e_storage.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_real_e2e_vpn.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_real_e2e_vpn_tunnel.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_remote_dev.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_rig_ansible_vars.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_rig_config.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_simulation_storage.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_small_module_coverage.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_state_bucket.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_storage_basic.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_vpn_optional.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_vpn_unit.py +0 -0
- {mystack_rig-1.2.1 → mystack_rig-1.3.0}/tests/test_workspace_git_clone.py +0 -0
|
@@ -27,3 +27,19 @@ _Avoid_: Facts, results
|
|
|
27
27
|
**Test bucket**:
|
|
28
28
|
A throwaway state bucket used only by automated test runs.
|
|
29
29
|
_Avoid_: Dev bucket
|
|
30
|
+
|
|
31
|
+
**Agent**:
|
|
32
|
+
A coding CLI that rig installs on an Environment: OpenCode, Claude Code or Cursor CLI.
|
|
33
|
+
_Avoid_: Coding agent type, CLI, assistant
|
|
34
|
+
|
|
35
|
+
**Stage**:
|
|
36
|
+
One of the playbook steps rig runs in order when creating an Environment: provision, configure, authorize, materialize, finalize. Only provision and configure are cached in a snapshot.
|
|
37
|
+
_Avoid_: Phase, step
|
|
38
|
+
|
|
39
|
+
**MCP server**:
|
|
40
|
+
A tool server declared once in the Workspace and installed into every Agent on its Environments.
|
|
41
|
+
_Avoid_: Plugin, tool, integration
|
|
42
|
+
|
|
43
|
+
**MCP variable**:
|
|
44
|
+
A named value an MCP server needs at runtime, resolved from the vaulted variable whose name matches it ignoring case.
|
|
45
|
+
_Avoid_: MCP secret, MCP env
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mystack-rig
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Ephemeral remotes with full local parity for coding agents
|
|
5
5
|
Author: mystack-cloud
|
|
6
6
|
License-Expression: MIT
|
|
@@ -61,7 +61,45 @@ Chosen at `rig init` (`agent.enabled` in `rig.yml`, same multi-select as git pro
|
|
|
61
61
|
| [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | `claude` | One agent: `coding_agent_api_key` (Anthropic). Several agents: `claude_api_key` |
|
|
62
62
|
| [Cursor CLI](https://cursor.com/docs/cli/overview) | `cursor` | One agent: `coding_agent_api_key` (`CURSOR_API_KEY`). Several agents: `cursor_api_key` |
|
|
63
63
|
|
|
64
|
-
Each selected agent is asked for its own key. Scaffolds land under `.rig/.opencode/`, `.rig/.claude/`, and `.rig/.cursor/` (plus shared `AGENTS.md`). Independent of `editor` (local IDE for `rig dev`).
|
|
64
|
+
Each selected agent is asked for its own key. Scaffolds land under `.rig/.opencode/`, `.rig/.claude/`, and `.rig/.cursor/` (plus shared `AGENTS.md`). MCP servers are declared once in `.rig/mcp.json` ([below](#mcp-servers)). Independent of `editor` (local IDE for `rig dev`).
|
|
65
|
+
|
|
66
|
+
## MCP servers
|
|
67
|
+
|
|
68
|
+
Declare an MCP server once in `.rig/mcp.json` and every enabled agent gets it. The file uses Claude's `.mcp.json` schema, and values may reference **MCP variables** as `${NAME}` or `${NAME:-default}`:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"mcpServers": {
|
|
73
|
+
"awx": {
|
|
74
|
+
"command": "python3",
|
|
75
|
+
"args": ["-u", "/root/awx-mcp-stdio.py"],
|
|
76
|
+
"env": { "AWX_MCP_API_KEY": "${AWX_MCP_API_KEY}" }
|
|
77
|
+
},
|
|
78
|
+
"context7": {
|
|
79
|
+
"url": "https://mcp.context7.com/mcp",
|
|
80
|
+
"headers": { "CONTEXT7_API_KEY": "${CONTEXT7_API_KEY}" }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
rig mcp add awx --env AWX_MCP_API_KEY -- python3 -u /root/awx-mcp-stdio.py
|
|
88
|
+
rig mcp add context7 --url https://mcp.context7.com/mcp --header 'CONTEXT7_API_KEY=${CONTEXT7_API_KEY}'
|
|
89
|
+
rig mcp list # servers, and whether each variable resolves
|
|
90
|
+
rig mcp check # same, exit 1 on any problem (also lists ignored legacy files)
|
|
91
|
+
rig mcp remove awx
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- Bare `--env KEY` means `KEY=${KEY}`; `--env KEY=value` stores a literal. `add` prompts for each `${NAME}` that has no default and no value yet, and vaults it (shared `vars.yml`; `--personal` for `vars.<identity>.yml`).
|
|
95
|
+
- A variable resolves to the vaulted variable with the same name, **ignoring case**: `AWX_MCP_API_KEY` finds `awx_mcp_api_key`. Two variables that differ only by case are an error. Values come from the vars files, inventory and extra vars, not from play-level `vars:`.
|
|
96
|
+
- The authorize Stage renders each enabled agent's own format and writes it into `~/.claude.json` (`mcpServers`), `~/.cursor/mcp.json` and `opencode.json` (`mcp`) on the Environment. A server with the same name is replaced; servers you added by hand there are kept. Secrets are written into those files (mode 0600).
|
|
97
|
+
- A server whose variable has no value is **skipped with a warning**; the create still succeeds. An invalid `.rig/mcp.json` fails the Stage.
|
|
98
|
+
- Fields rig does not translate (anything other than `type`, `command`, `args`, `env`, `url`, `headers`) are dropped with a warning.
|
|
99
|
+
- `rig mcp add/remove` only edit local files. Push to a running Environment with `rig apply --authorize`; `remove` leaves the old entry on Environments that already have it until they are recreated.
|
|
100
|
+
- Cursor's launcher passes `--approve-mcps`, so servers rig installs never prompt.
|
|
101
|
+
- Support files for a server (for example a stdio wrapper script) are not managed by rig: install them from your own playbook (provision, configure or authorize) and point `command` at that path.
|
|
102
|
+
- The per-agent `.rig/.claude|.cursor|.opencode/mcp.json` files from earlier versions are no longer deployed. If one still declares servers, `rig apply`/`create` and `rig mcp check` warn; move them to `.rig/mcp.json`.
|
|
65
103
|
|
|
66
104
|
## IDEs
|
|
67
105
|
|
|
@@ -93,12 +131,13 @@ rig.yml # workspace manifest (vm, agent, playbooks, repos)
|
|
|
93
131
|
requirements.yml # Galaxy collections/roles
|
|
94
132
|
local_roles/ # committed Ansible roles (searched first)
|
|
95
133
|
AGENTS.md # agent instructions
|
|
96
|
-
.opencode/ | .claude/ | .cursor/ # agent config
|
|
134
|
+
.opencode/ | .claude/ | .cursor/ # agent config
|
|
135
|
+
mcp.json # user; MCP servers for every agent (see `rig mcp`)
|
|
97
136
|
inventory.yml # generated at create/apply (gitignored)
|
|
98
137
|
collections/ roles/ # Galaxy installs (gitignored)
|
|
99
138
|
```
|
|
100
139
|
|
|
101
|
-
Put a committed role at `.rig/local_roles/<name>/` (`tasks/main.yml` and the usual role layout). `rig init` creates the directory. Galaxy roles install into `.rig/roles/` and stay gitignored.
|
|
140
|
+
Put a committed role at `.rig/local_roles/<name>/` (`tasks/main.yml` and the usual role layout). `rig init` creates the directory. Galaxy roles install into `.rig/roles/` and stay gitignored. `.rig/local_roles` comes first in the roles path. Give a committed role a name that no Galaxy role uses: if both exist, Ansible's own lookup finds the one in `.rig/roles` first. An older `.rig/galaxy_roles/` directory is moved into `roles` on the next init or apply.
|
|
102
141
|
|
|
103
142
|
`rig.yml` defaults (edit to configure):
|
|
104
143
|
|
|
@@ -198,7 +237,7 @@ After you leave an agent TTY, rig captures the printed session / resume id (when
|
|
|
198
237
|
| `rig-{version}-{hash}` | provision + configure (`authorize` + `materialize` still run) |
|
|
199
238
|
| base image | nothing |
|
|
200
239
|
|
|
201
|
-
**System hash** = var map (`coding_agent_type`, `coding_agent_types`, `git_providers`, `code_server_*`, `workspace_root`) + `provision.yml` + `configure.yml
|
|
240
|
+
**System hash** = var map (`coding_agent_type`, `coding_agent_types`, `git_providers`, `code_server_*`, `workspace_root`) + `provision.yml` + `configure.yml` + `requirements.yml` (pins Galaxy role versions). Secrets, `authorize.yml`, `materialize.yml` and the role directories (`.rig/local_roles`, `.rig/roles`) are not included, so editing a role used from `materialize.yml` does not discard the cached image. If `configure.yml` uses a local role, run `rig cache clear` after changing it.
|
|
202
241
|
|
|
203
242
|
Override with `--force-playbooks` / `--force-system` (force provision+configure) / `--force-workspace` (force materialize).
|
|
204
243
|
|
|
@@ -38,7 +38,45 @@ Chosen at `rig init` (`agent.enabled` in `rig.yml`, same multi-select as git pro
|
|
|
38
38
|
| [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | `claude` | One agent: `coding_agent_api_key` (Anthropic). Several agents: `claude_api_key` |
|
|
39
39
|
| [Cursor CLI](https://cursor.com/docs/cli/overview) | `cursor` | One agent: `coding_agent_api_key` (`CURSOR_API_KEY`). Several agents: `cursor_api_key` |
|
|
40
40
|
|
|
41
|
-
Each selected agent is asked for its own key. Scaffolds land under `.rig/.opencode/`, `.rig/.claude/`, and `.rig/.cursor/` (plus shared `AGENTS.md`). Independent of `editor` (local IDE for `rig dev`).
|
|
41
|
+
Each selected agent is asked for its own key. Scaffolds land under `.rig/.opencode/`, `.rig/.claude/`, and `.rig/.cursor/` (plus shared `AGENTS.md`). MCP servers are declared once in `.rig/mcp.json` ([below](#mcp-servers)). Independent of `editor` (local IDE for `rig dev`).
|
|
42
|
+
|
|
43
|
+
## MCP servers
|
|
44
|
+
|
|
45
|
+
Declare an MCP server once in `.rig/mcp.json` and every enabled agent gets it. The file uses Claude's `.mcp.json` schema, and values may reference **MCP variables** as `${NAME}` or `${NAME:-default}`:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"mcpServers": {
|
|
50
|
+
"awx": {
|
|
51
|
+
"command": "python3",
|
|
52
|
+
"args": ["-u", "/root/awx-mcp-stdio.py"],
|
|
53
|
+
"env": { "AWX_MCP_API_KEY": "${AWX_MCP_API_KEY}" }
|
|
54
|
+
},
|
|
55
|
+
"context7": {
|
|
56
|
+
"url": "https://mcp.context7.com/mcp",
|
|
57
|
+
"headers": { "CONTEXT7_API_KEY": "${CONTEXT7_API_KEY}" }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
rig mcp add awx --env AWX_MCP_API_KEY -- python3 -u /root/awx-mcp-stdio.py
|
|
65
|
+
rig mcp add context7 --url https://mcp.context7.com/mcp --header 'CONTEXT7_API_KEY=${CONTEXT7_API_KEY}'
|
|
66
|
+
rig mcp list # servers, and whether each variable resolves
|
|
67
|
+
rig mcp check # same, exit 1 on any problem (also lists ignored legacy files)
|
|
68
|
+
rig mcp remove awx
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- Bare `--env KEY` means `KEY=${KEY}`; `--env KEY=value` stores a literal. `add` prompts for each `${NAME}` that has no default and no value yet, and vaults it (shared `vars.yml`; `--personal` for `vars.<identity>.yml`).
|
|
72
|
+
- A variable resolves to the vaulted variable with the same name, **ignoring case**: `AWX_MCP_API_KEY` finds `awx_mcp_api_key`. Two variables that differ only by case are an error. Values come from the vars files, inventory and extra vars, not from play-level `vars:`.
|
|
73
|
+
- The authorize Stage renders each enabled agent's own format and writes it into `~/.claude.json` (`mcpServers`), `~/.cursor/mcp.json` and `opencode.json` (`mcp`) on the Environment. A server with the same name is replaced; servers you added by hand there are kept. Secrets are written into those files (mode 0600).
|
|
74
|
+
- A server whose variable has no value is **skipped with a warning**; the create still succeeds. An invalid `.rig/mcp.json` fails the Stage.
|
|
75
|
+
- Fields rig does not translate (anything other than `type`, `command`, `args`, `env`, `url`, `headers`) are dropped with a warning.
|
|
76
|
+
- `rig mcp add/remove` only edit local files. Push to a running Environment with `rig apply --authorize`; `remove` leaves the old entry on Environments that already have it until they are recreated.
|
|
77
|
+
- Cursor's launcher passes `--approve-mcps`, so servers rig installs never prompt.
|
|
78
|
+
- Support files for a server (for example a stdio wrapper script) are not managed by rig: install them from your own playbook (provision, configure or authorize) and point `command` at that path.
|
|
79
|
+
- The per-agent `.rig/.claude|.cursor|.opencode/mcp.json` files from earlier versions are no longer deployed. If one still declares servers, `rig apply`/`create` and `rig mcp check` warn; move them to `.rig/mcp.json`.
|
|
42
80
|
|
|
43
81
|
## IDEs
|
|
44
82
|
|
|
@@ -70,12 +108,13 @@ rig.yml # workspace manifest (vm, agent, playbooks, repos)
|
|
|
70
108
|
requirements.yml # Galaxy collections/roles
|
|
71
109
|
local_roles/ # committed Ansible roles (searched first)
|
|
72
110
|
AGENTS.md # agent instructions
|
|
73
|
-
.opencode/ | .claude/ | .cursor/ # agent config
|
|
111
|
+
.opencode/ | .claude/ | .cursor/ # agent config
|
|
112
|
+
mcp.json # user; MCP servers for every agent (see `rig mcp`)
|
|
74
113
|
inventory.yml # generated at create/apply (gitignored)
|
|
75
114
|
collections/ roles/ # Galaxy installs (gitignored)
|
|
76
115
|
```
|
|
77
116
|
|
|
78
|
-
Put a committed role at `.rig/local_roles/<name>/` (`tasks/main.yml` and the usual role layout). `rig init` creates the directory. Galaxy roles install into `.rig/roles/` and stay gitignored.
|
|
117
|
+
Put a committed role at `.rig/local_roles/<name>/` (`tasks/main.yml` and the usual role layout). `rig init` creates the directory. Galaxy roles install into `.rig/roles/` and stay gitignored. `.rig/local_roles` comes first in the roles path. Give a committed role a name that no Galaxy role uses: if both exist, Ansible's own lookup finds the one in `.rig/roles` first. An older `.rig/galaxy_roles/` directory is moved into `roles` on the next init or apply.
|
|
79
118
|
|
|
80
119
|
`rig.yml` defaults (edit to configure):
|
|
81
120
|
|
|
@@ -175,7 +214,7 @@ After you leave an agent TTY, rig captures the printed session / resume id (when
|
|
|
175
214
|
| `rig-{version}-{hash}` | provision + configure (`authorize` + `materialize` still run) |
|
|
176
215
|
| base image | nothing |
|
|
177
216
|
|
|
178
|
-
**System hash** = var map (`coding_agent_type`, `coding_agent_types`, `git_providers`, `code_server_*`, `workspace_root`) + `provision.yml` + `configure.yml
|
|
217
|
+
**System hash** = var map (`coding_agent_type`, `coding_agent_types`, `git_providers`, `code_server_*`, `workspace_root`) + `provision.yml` + `configure.yml` + `requirements.yml` (pins Galaxy role versions). Secrets, `authorize.yml`, `materialize.yml` and the role directories (`.rig/local_roles`, `.rig/roles`) are not included, so editing a role used from `materialize.yml` does not discard the cached image. If `configure.yml` uses a local role, run `rig cache clear` after changing it.
|
|
179
218
|
|
|
180
219
|
Override with `--force-playbooks` / `--force-system` (force provision+configure) / `--force-workspace` (force materialize).
|
|
181
220
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# MCP servers are declared once and rendered per Agent at authorize
|
|
2
|
+
|
|
3
|
+
A Workspace declares MCP servers once in `.rig/mcp.json`, in Claude's `.mcp.json` schema with `${NAME}` MCP variables. The authorize Stage renders each enabled Agent's own config from it and writes the resolved values into the Environment. Each MCP variable resolves to the vaulted variable with the same name, ignoring case, using an Ansible filter plugin that ships with rig.
|
|
4
|
+
|
|
5
|
+
## Considered Options
|
|
6
|
+
|
|
7
|
+
- **Per-agent files** (`.rig/.claude/mcp.json`, `.cursor/`, `.opencode/`): rejected. One server had to be written three times in three syntaxes, and an Agent enabled later silently lacked servers added earlier. They are retired; rig warns when one still declares servers.
|
|
8
|
+
- **Deploy MCP config in provision**: rejected. Provision is cached in a snapshot and `mcp.json` is not part of the snapshot hash, so edits would not reach new Environments. It also cannot hold secrets.
|
|
9
|
+
- **Leave placeholders in the Agent configs and write the values to an env file**: rejected. It only works if every launch path sources the file and each Agent expands its own syntax. OpenCode turns an unset variable into an empty string without a warning, and Cursor leaves it as literal text.
|
|
10
|
+
- **Resolve secrets in rig and pass them to Ansible as extra vars**: rejected. It would put secrets on the `ansible-playbook` command line.
|
|
11
|
+
|
|
12
|
+
## Consequences
|
|
13
|
+
|
|
14
|
+
- Secrets are written into the Agents' config files on the Environment (mode 0600), as well as sitting in the vault.
|
|
15
|
+
- A server whose variable has no value is skipped with a warning and does not fail the create. An invalid `.rig/mcp.json` does fail it.
|
|
16
|
+
- A same-name server is replaced whole; servers added by hand on the Environment are kept.
|
|
17
|
+
- Removing a server from `.rig/mcp.json` does not remove it from Environments that already have it.
|
|
18
|
+
- rig does not install a server's support files (for example a stdio wrapper script). The Workspace's own playbooks do.
|
|
@@ -7,11 +7,9 @@ Layout under the project (committed, user-editable):
|
|
|
7
7
|
|
|
8
8
|
.rig/AGENTS.md # shared workspace rules
|
|
9
9
|
.rig/.opencode/opencode.json # OpenCode config (API key via env)
|
|
10
|
-
.rig/.opencode/mcp.json # OpenCode MCP servers
|
|
11
10
|
.rig/.claude/settings.json # Claude Code settings
|
|
12
|
-
.rig/.claude/mcp.json # Claude Code MCP servers (.mcp.json on remote)
|
|
13
11
|
.rig/.cursor/cli-config.json # Cursor CLI config
|
|
14
|
-
.rig
|
|
12
|
+
.rig/mcp.json # MCP servers for every Agent (see `rig mcp`)
|
|
15
13
|
"""
|
|
16
14
|
|
|
17
15
|
from __future__ import annotations
|
|
@@ -122,43 +120,24 @@ def sync_opencode_config(
|
|
|
122
120
|
_write_json(config_path, opencode_config(has_api_key=has_api_key))
|
|
123
121
|
return ".rig/.opencode/opencode.json"
|
|
124
122
|
|
|
125
|
-
OPENCODE_MCP: Dict[str, Any] = {
|
|
126
|
-
"mcp": {
|
|
127
|
-
# Example (disabled). Uncomment / extend as needed:
|
|
128
|
-
# "context7": {
|
|
129
|
-
# "type": "remote",
|
|
130
|
-
# "url": "https://mcp.context7.com/mcp",
|
|
131
|
-
# "enabled": false,
|
|
132
|
-
# "headers": {"CONTEXT7_API_KEY": "{env:CONTEXT7_API_KEY}"},
|
|
133
|
-
# },
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
123
|
CLAUDE_SETTINGS = {
|
|
124
|
+
# Bare tool names allow every path; "Tool(*)" warns on recent Claude Code.
|
|
138
125
|
"permissions": {
|
|
139
126
|
"allow": [
|
|
140
|
-
"Bash
|
|
141
|
-
"Edit
|
|
142
|
-
"Read
|
|
143
|
-
"Write
|
|
144
|
-
"Glob
|
|
145
|
-
"Grep
|
|
127
|
+
"Bash",
|
|
128
|
+
"Edit",
|
|
129
|
+
"Read",
|
|
130
|
+
"Write",
|
|
131
|
+
"Glob",
|
|
132
|
+
"Grep",
|
|
146
133
|
]
|
|
147
134
|
},
|
|
135
|
+
# Skips the first-run theme picker.
|
|
136
|
+
"theme": "dark",
|
|
148
137
|
# API key is injected via /etc/profile.d/rig-coding-agent.sh and
|
|
149
138
|
# ~/.claude/credentials.env (CODING_AGENT_API_KEY / ANTHROPIC_API_KEY).
|
|
150
139
|
}
|
|
151
140
|
|
|
152
|
-
CLAUDE_MCP: Dict[str, Any] = {
|
|
153
|
-
"mcpServers": {
|
|
154
|
-
# Example (disabled). Add servers as needed for Claude Code:
|
|
155
|
-
# "filesystem": {
|
|
156
|
-
# "command": "npx",
|
|
157
|
-
# "args": ["-y", "@modelcontextprotocol/server-filesystem", "/root"],
|
|
158
|
-
# },
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
141
|
# Cursor CLI (~/.cursor/cli-config.json). API key via CURSOR_API_KEY on the VM.
|
|
163
142
|
CURSOR_CLI_CONFIG: Dict[str, Any] = {
|
|
164
143
|
"permissions": {
|
|
@@ -170,11 +149,6 @@ CURSOR_CLI_CONFIG: Dict[str, Any] = {
|
|
|
170
149
|
},
|
|
171
150
|
}
|
|
172
151
|
|
|
173
|
-
CURSOR_MCP: Dict[str, Any] = {
|
|
174
|
-
"mcpServers": {},
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
152
|
def normalize_agent_type(value: Optional[str]) -> str:
|
|
179
153
|
raw = (value or "").strip().lower().replace(" ", "-").replace("_", "-")
|
|
180
154
|
aliases = {
|
|
@@ -212,7 +186,7 @@ def agent_remote_paths(agent_type: str) -> Dict[str, str]:
|
|
|
212
186
|
return {
|
|
213
187
|
"config_dir": "/root/.config/opencode",
|
|
214
188
|
"config_file": "/root/.config/opencode/opencode.json",
|
|
215
|
-
"mcp_file": "/root/.config/opencode/
|
|
189
|
+
"mcp_file": "/root/.config/opencode/opencode.json", # `mcp` key, merged at authorize
|
|
216
190
|
"rules_file": "/root/.config/opencode/AGENTS.md",
|
|
217
191
|
"env_file": "/root/.config/opencode/credentials.env",
|
|
218
192
|
}
|
|
@@ -227,7 +201,7 @@ def agent_remote_paths(agent_type: str) -> Dict[str, str]:
|
|
|
227
201
|
return {
|
|
228
202
|
"config_dir": "/root/.claude",
|
|
229
203
|
"config_file": "/root/.claude/settings.json",
|
|
230
|
-
"mcp_file": "/root/.
|
|
204
|
+
"mcp_file": "/root/.claude.json", # `mcpServers` key, merged at authorize
|
|
231
205
|
"rules_file": "/root/.claude/CLAUDE.md",
|
|
232
206
|
"env_file": "/root/.claude/credentials.env",
|
|
233
207
|
}
|
|
@@ -274,31 +248,18 @@ def ensure_agent_scaffold(
|
|
|
274
248
|
)
|
|
275
249
|
if written:
|
|
276
250
|
created.append(written)
|
|
277
|
-
cfg_dir = os.path.join(rig_dir, ".opencode")
|
|
278
|
-
mcp_path = os.path.join(cfg_dir, "mcp.json")
|
|
279
|
-
if force or not os.path.exists(mcp_path):
|
|
280
|
-
_write_json(mcp_path, OPENCODE_MCP)
|
|
281
|
-
created.append(".rig/.opencode/mcp.json")
|
|
282
251
|
elif agent == "cursor":
|
|
283
252
|
cfg_dir = os.path.join(rig_dir, ".cursor")
|
|
284
253
|
config_path = os.path.join(cfg_dir, "cli-config.json")
|
|
285
|
-
mcp_path = os.path.join(cfg_dir, "mcp.json")
|
|
286
254
|
if force or not os.path.exists(config_path):
|
|
287
255
|
_write_json(config_path, CURSOR_CLI_CONFIG)
|
|
288
256
|
created.append(".rig/.cursor/cli-config.json")
|
|
289
|
-
if force or not os.path.exists(mcp_path):
|
|
290
|
-
_write_json(mcp_path, CURSOR_MCP)
|
|
291
|
-
created.append(".rig/.cursor/mcp.json")
|
|
292
257
|
else:
|
|
293
258
|
cfg_dir = os.path.join(rig_dir, ".claude")
|
|
294
259
|
config_path = os.path.join(cfg_dir, "settings.json")
|
|
295
|
-
mcp_path = os.path.join(cfg_dir, "mcp.json")
|
|
296
260
|
if force or not os.path.exists(config_path):
|
|
297
261
|
_write_json(config_path, CLAUDE_SETTINGS)
|
|
298
262
|
created.append(".rig/.claude/settings.json")
|
|
299
|
-
if force or not os.path.exists(mcp_path):
|
|
300
|
-
_write_json(mcp_path, CLAUDE_MCP)
|
|
301
|
-
created.append(".rig/.claude/mcp.json")
|
|
302
263
|
|
|
303
264
|
return created
|
|
304
265
|
|
|
File without changes
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"""MCP server declaration, resolution and rendering for rig.
|
|
2
|
+
|
|
3
|
+
This file is both an Ansible filter plugin (loaded by path, so it must stay
|
|
4
|
+
standard-library only and import nothing from ``cli``) and a normal module used
|
|
5
|
+
by the ``rig mcp`` commands.
|
|
6
|
+
|
|
7
|
+
A Workspace declares MCP servers once in ``.rig/mcp.json`` using Claude's
|
|
8
|
+
``.mcp.json`` schema. Values may reference MCP variables as ``${NAME}`` or
|
|
9
|
+
``${NAME:-default}``. At the authorize Stage each Agent's config is rendered
|
|
10
|
+
from that file, resolving each variable against the play variables (vaulted
|
|
11
|
+
values included) by name, ignoring case.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple
|
|
19
|
+
|
|
20
|
+
try: # pragma: no cover - exercised only under Ansible
|
|
21
|
+
from ansible.errors import AnsibleFilterError
|
|
22
|
+
except Exception: # pragma: no cover
|
|
23
|
+
|
|
24
|
+
class AnsibleFilterError(Exception): # type: ignore[no-redef]
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
AGENTS = ("claude", "cursor", "opencode")
|
|
29
|
+
KNOWN_KEYS = ("type", "command", "args", "env", "url", "headers")
|
|
30
|
+
REMOTE_TYPES = ("http", "sse")
|
|
31
|
+
VAR_RE = re.compile(r"\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}")
|
|
32
|
+
SERVER_NAME_RE = re.compile(r"^[A-Za-z0-9_][A-Za-z0-9_.-]*$")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class McpConfigError(ValueError):
|
|
36
|
+
"""The neutral MCP config is invalid."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _warn(message: str) -> None:
|
|
40
|
+
try: # pragma: no cover - exercised only under Ansible
|
|
41
|
+
from ansible.utils.display import Display
|
|
42
|
+
|
|
43
|
+
Display().warning(message)
|
|
44
|
+
except Exception:
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# ---------------------------------------------------------------- parsing
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def parse_config(raw: Any) -> Dict[str, Any]:
|
|
52
|
+
"""Return a validated ``{"mcpServers": {...}}`` from text, a dict or nothing."""
|
|
53
|
+
if raw is None or (isinstance(raw, str) and not raw.strip()):
|
|
54
|
+
return {"mcpServers": {}}
|
|
55
|
+
if isinstance(raw, str):
|
|
56
|
+
try:
|
|
57
|
+
raw = json.loads(raw)
|
|
58
|
+
except ValueError as exc:
|
|
59
|
+
raise McpConfigError(f"mcp.json is not valid JSON: {exc}") from exc
|
|
60
|
+
if not isinstance(raw, dict):
|
|
61
|
+
raise McpConfigError("mcp.json must be a JSON object")
|
|
62
|
+
servers = raw.get("mcpServers", {})
|
|
63
|
+
if not isinstance(servers, dict):
|
|
64
|
+
raise McpConfigError("mcp.json: 'mcpServers' must be an object")
|
|
65
|
+
for name, server in servers.items():
|
|
66
|
+
validate_server(name, server)
|
|
67
|
+
return {"mcpServers": servers}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def validate_server(name: str, server: Any) -> None:
|
|
71
|
+
where = f"mcp.json: server '{name}'"
|
|
72
|
+
if not SERVER_NAME_RE.match(str(name)):
|
|
73
|
+
raise McpConfigError(f"{where}: invalid name (use letters, digits, _ . -)")
|
|
74
|
+
if not isinstance(server, dict):
|
|
75
|
+
raise McpConfigError(f"{where} must be an object")
|
|
76
|
+
has_command = "command" in server
|
|
77
|
+
has_url = "url" in server
|
|
78
|
+
if has_command == has_url:
|
|
79
|
+
raise McpConfigError(f"{where} needs exactly one of 'command' or 'url'")
|
|
80
|
+
if has_command:
|
|
81
|
+
if not isinstance(server["command"], str) or not server["command"]:
|
|
82
|
+
raise McpConfigError(f"{where}: 'command' must be a non-empty string")
|
|
83
|
+
args = server.get("args", [])
|
|
84
|
+
if not isinstance(args, list) or not all(isinstance(a, str) for a in args):
|
|
85
|
+
raise McpConfigError(f"{where}: 'args' must be a list of strings")
|
|
86
|
+
_check_str_map(where, "env", server.get("env", {}))
|
|
87
|
+
if server.get("type", "stdio") != "stdio":
|
|
88
|
+
raise McpConfigError(f"{where}: a 'command' server must have type 'stdio'")
|
|
89
|
+
else:
|
|
90
|
+
if not isinstance(server["url"], str) or not server["url"]:
|
|
91
|
+
raise McpConfigError(f"{where}: 'url' must be a non-empty string")
|
|
92
|
+
_check_str_map(where, "headers", server.get("headers", {}))
|
|
93
|
+
if server.get("type", "http") not in REMOTE_TYPES:
|
|
94
|
+
raise McpConfigError(
|
|
95
|
+
f"{where}: a 'url' server must have type 'http' or 'sse'"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _check_str_map(where: str, key: str, value: Any) -> None:
|
|
100
|
+
if not isinstance(value, dict) or not all(
|
|
101
|
+
isinstance(k, str) and isinstance(v, str) for k, v in value.items()
|
|
102
|
+
):
|
|
103
|
+
raise McpConfigError(f"{where}: '{key}' must be an object of strings")
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def unknown_keys(server: Mapping[str, Any]) -> List[str]:
|
|
107
|
+
return sorted(k for k in server if k not in KNOWN_KEYS)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
# -------------------------------------------------------------- variables
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def variables_in(obj: Any) -> Dict[str, bool]:
|
|
114
|
+
"""Map each referenced variable name to whether it is required (no default)."""
|
|
115
|
+
found: Dict[str, bool] = {}
|
|
116
|
+
|
|
117
|
+
def walk(x: Any) -> None:
|
|
118
|
+
if isinstance(x, str):
|
|
119
|
+
for m in VAR_RE.finditer(x):
|
|
120
|
+
required = m.group(2) is None
|
|
121
|
+
found[m.group(1)] = found.get(m.group(1), False) or required
|
|
122
|
+
elif isinstance(x, list):
|
|
123
|
+
for i in x:
|
|
124
|
+
walk(i)
|
|
125
|
+
elif isinstance(x, dict):
|
|
126
|
+
for v in x.values():
|
|
127
|
+
walk(v)
|
|
128
|
+
|
|
129
|
+
walk(obj)
|
|
130
|
+
return found
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def required_variables(obj: Any) -> List[str]:
|
|
134
|
+
return sorted(n for n, req in variables_in(obj).items() if req)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class VariableLookup:
|
|
138
|
+
"""Case-insensitive lookup of variables by name."""
|
|
139
|
+
|
|
140
|
+
def __init__(self, variables: Optional[Mapping[str, Any]] = None,
|
|
141
|
+
names: Optional[Iterable[str]] = None) -> None:
|
|
142
|
+
self._variables = variables
|
|
143
|
+
self._by_lower: Dict[str, List[str]] = {}
|
|
144
|
+
keys = names if names is not None else (variables or {}).keys()
|
|
145
|
+
for key in keys:
|
|
146
|
+
self._by_lower.setdefault(str(key).lower(), []).append(str(key))
|
|
147
|
+
|
|
148
|
+
def has(self, name: str) -> bool:
|
|
149
|
+
return name.lower() in self._by_lower
|
|
150
|
+
|
|
151
|
+
def get(self, name: str) -> Optional[str]:
|
|
152
|
+
"""Value as text, or None when absent or empty."""
|
|
153
|
+
keys = self._by_lower.get(name.lower(), [])
|
|
154
|
+
if len(keys) > 1:
|
|
155
|
+
raise McpConfigError(
|
|
156
|
+
f"MCP variable {name} is ambiguous: variables {', '.join(sorted(keys))} "
|
|
157
|
+
"differ only by case"
|
|
158
|
+
)
|
|
159
|
+
if not keys or self._variables is None:
|
|
160
|
+
return None
|
|
161
|
+
value = self._variables[keys[0]]
|
|
162
|
+
if value is None:
|
|
163
|
+
return None
|
|
164
|
+
text = str(value)
|
|
165
|
+
return text if text != "" else None
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def missing_variables(server: Any, lookup: VariableLookup) -> List[str]:
|
|
169
|
+
"""Required variables of one server with no (non-empty) value."""
|
|
170
|
+
out = []
|
|
171
|
+
for name in required_variables(server):
|
|
172
|
+
if lookup._variables is None:
|
|
173
|
+
ok = lookup.has(name)
|
|
174
|
+
if ok and len(lookup._by_lower[name.lower()]) > 1:
|
|
175
|
+
lookup.get(name) # raises: ambiguous
|
|
176
|
+
else:
|
|
177
|
+
ok = lookup.get(name) is not None
|
|
178
|
+
if not ok:
|
|
179
|
+
out.append(name)
|
|
180
|
+
return out
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def resolve_value(obj: Any, lookup: VariableLookup) -> Any:
|
|
184
|
+
"""Substitute ``${NAME}`` / ``${NAME:-default}`` in every string, in one pass."""
|
|
185
|
+
|
|
186
|
+
def sub(m: "re.Match[str]") -> str:
|
|
187
|
+
value = lookup.get(m.group(1))
|
|
188
|
+
if value is not None:
|
|
189
|
+
return value
|
|
190
|
+
if m.group(2) is not None:
|
|
191
|
+
return m.group(2)
|
|
192
|
+
raise McpConfigError(f"MCP variable {m.group(1)} has no value")
|
|
193
|
+
|
|
194
|
+
if isinstance(obj, str):
|
|
195
|
+
return VAR_RE.sub(sub, obj)
|
|
196
|
+
if isinstance(obj, list):
|
|
197
|
+
return [resolve_value(i, lookup) for i in obj]
|
|
198
|
+
if isinstance(obj, dict):
|
|
199
|
+
return {k: resolve_value(v, lookup) for k, v in obj.items()}
|
|
200
|
+
return obj
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
# -------------------------------------------------------------- rendering
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def render_server(agent: str, server: Mapping[str, Any]) -> Dict[str, Any]:
|
|
207
|
+
"""Translate one resolved neutral server into an Agent's native shape."""
|
|
208
|
+
if agent not in AGENTS:
|
|
209
|
+
raise McpConfigError(f"unknown agent '{agent}'")
|
|
210
|
+
if "command" in server:
|
|
211
|
+
args = list(server.get("args") or [])
|
|
212
|
+
env = dict(server.get("env") or {})
|
|
213
|
+
if agent == "opencode":
|
|
214
|
+
out: Dict[str, Any] = {"type": "local", "command": [server["command"], *args]}
|
|
215
|
+
if env:
|
|
216
|
+
out["environment"] = env
|
|
217
|
+
return out
|
|
218
|
+
out = {}
|
|
219
|
+
if agent == "claude":
|
|
220
|
+
out["type"] = "stdio"
|
|
221
|
+
out["command"] = server["command"]
|
|
222
|
+
if args:
|
|
223
|
+
out["args"] = args
|
|
224
|
+
if env:
|
|
225
|
+
out["env"] = env
|
|
226
|
+
return out
|
|
227
|
+
headers = dict(server.get("headers") or {})
|
|
228
|
+
kind = server.get("type", "http")
|
|
229
|
+
if agent == "opencode":
|
|
230
|
+
out = {"type": "remote", "url": server["url"]}
|
|
231
|
+
if headers:
|
|
232
|
+
out["headers"] = headers
|
|
233
|
+
out["oauth"] = False # header credentials; don't start an OAuth flow
|
|
234
|
+
return out
|
|
235
|
+
out = {}
|
|
236
|
+
if agent == "claude":
|
|
237
|
+
out["type"] = kind
|
|
238
|
+
out["url"] = server["url"]
|
|
239
|
+
if headers:
|
|
240
|
+
out["headers"] = headers
|
|
241
|
+
return out
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def render(config: Any, agents: Iterable[str], variables: Mapping[str, Any]
|
|
245
|
+
) -> Tuple[Dict[str, Dict[str, Any]], Dict[str, List[str]], List[str]]:
|
|
246
|
+
"""Render ``config`` for each agent.
|
|
247
|
+
|
|
248
|
+
Returns ``(servers_by_agent, skipped, warnings)``. A server with an
|
|
249
|
+
unresolved required variable is skipped (everywhere) and listed in
|
|
250
|
+
``skipped``; it never fails the render.
|
|
251
|
+
"""
|
|
252
|
+
servers = parse_config(config)["mcpServers"]
|
|
253
|
+
lookup = VariableLookup(variables)
|
|
254
|
+
warnings: List[str] = []
|
|
255
|
+
skipped: Dict[str, List[str]] = {}
|
|
256
|
+
resolved: Dict[str, Dict[str, Any]] = {}
|
|
257
|
+
for name, server in servers.items():
|
|
258
|
+
extra = unknown_keys(server)
|
|
259
|
+
if extra:
|
|
260
|
+
warnings.append(
|
|
261
|
+
f"MCP server '{name}': ignoring unsupported field(s) {', '.join(extra)}"
|
|
262
|
+
)
|
|
263
|
+
missing = missing_variables(server, lookup)
|
|
264
|
+
if missing:
|
|
265
|
+
skipped[name] = missing
|
|
266
|
+
warnings.append(
|
|
267
|
+
f"MCP server '{name}' skipped: no value for {', '.join(missing)} "
|
|
268
|
+
"(store it with `rig vars encrypt`)"
|
|
269
|
+
)
|
|
270
|
+
continue
|
|
271
|
+
resolved[name] = resolve_value(
|
|
272
|
+
{k: v for k, v in server.items() if k in KNOWN_KEYS}, lookup
|
|
273
|
+
)
|
|
274
|
+
by_agent = {
|
|
275
|
+
agent: {name: render_server(agent, s) for name, s in resolved.items()}
|
|
276
|
+
for agent in agents
|
|
277
|
+
if agent in AGENTS
|
|
278
|
+
}
|
|
279
|
+
return by_agent, skipped, warnings
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def merge_servers(existing: Any, key: str, servers: Mapping[str, Any]) -> Dict[str, Any]:
|
|
283
|
+
"""Overlay rig-managed servers onto ``existing[key]`` by name.
|
|
284
|
+
|
|
285
|
+
A same-name entry is replaced whole, not deep-merged; every other server
|
|
286
|
+
already in the file (for example one added with ``claude mcp add``) is kept.
|
|
287
|
+
"""
|
|
288
|
+
out = dict(existing or {})
|
|
289
|
+
current = out.get(key)
|
|
290
|
+
merged = dict(current) if isinstance(current, dict) else {}
|
|
291
|
+
merged.update(servers)
|
|
292
|
+
out[key] = merged
|
|
293
|
+
return out
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
# ------------------------------------------------------- Ansible filters
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def rig_mcp_render(raw_config: Any, agents: Any, variables: Mapping[str, Any]
|
|
300
|
+
) -> Dict[str, Dict[str, Any]]:
|
|
301
|
+
"""``{{ raw | rig_mcp_render(agents, vars) }}`` -> ``{agent: {server: cfg}}``."""
|
|
302
|
+
try:
|
|
303
|
+
by_agent, _skipped, warnings = render(raw_config, list(agents or []), variables)
|
|
304
|
+
except McpConfigError as exc:
|
|
305
|
+
raise AnsibleFilterError(str(exc)) from exc
|
|
306
|
+
for message in warnings:
|
|
307
|
+
_warn(message)
|
|
308
|
+
return by_agent
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def rig_mcp_merge(existing: Any, key: str, servers: Mapping[str, Any]) -> Dict[str, Any]:
|
|
312
|
+
"""``{{ existing | rig_mcp_merge('mcpServers', servers) }}``."""
|
|
313
|
+
return merge_servers(existing, key, servers)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
class FilterModule(object):
|
|
317
|
+
def filters(self) -> Dict[str, Any]:
|
|
318
|
+
return {"rig_mcp_render": rig_mcp_render, "rig_mcp_merge": rig_mcp_merge}
|