Sync env from 1password

From markmhendrickson/neotoma · View interactive version

Sync env from 1password is an AI agent skill from the GitHub repository markmhendrickson/neotoma. Sync .env from 1Password using env_var_mappings.

How to use this skill

Skill file

Sync Environment Variables from 1Password

Sync environment variables from 1Password to local .env file using environment variable mappings stored in the truth layer (per neotoma_parquet_migration_rules.mdc).

Command

sync_env_from_1password

or

sync env from 1password

Purpose

This command syncs environment variables from 1Password to your local .env file based on mappings stored in the truth layer (per neotoma_parquet_migration_rules.mdc). Parquet path when used: $DATA_DIR/env_var_mappings/env_var_mappings.parquet.

Key features:

Prerequisites

Option 1: 1Password MCP Server (Recommended)

Benefits:

Setup:

  1. Ensure 1Password CLI is installed:

```bash

brew install 1password-cli

op signin

```

  1. Configure MCP server in ~/.cursor/mcp.json:

```json

{

"mcpServers": {

"onepassword": {

"command": "bash",

"args": [

"/Users/markmhendrickson/repos/ateles/mcp/onepassword/run-onepassword-mcp.sh"

],

"env": {}

}

}

}

```

  1. Verify MCP server is running:

For detailed setup instructions, see: mcp/onepassword/README.md

Option 2: 1Password CLI (Fallback)

When to use:

Setup:

  1. Install 1Password CLI:

```bash

brew install 1password-cli

```

  1. Sign in:

```bash

op signin

```

Note: CLI sessions expire periodically and require re-authentication.

Configuration

Environment Variable Mappings

Mappings are in the truth layer (per neotoma_parquet_migration_rules.mdc). Parquet path when used: $DATA_DIR/env_var_mappings/env_var_mappings.parquet.

Schema:

Adding/Updating Mappings

Via MCP parquet server:

# Add new mapping
mcp_parquet_add_record(
    data_type="env_var_mappings",
    record={
        "env_var": "MY_API_KEY",
        "op_reference": "op://Personal/API-Keys/my_api_key",
        "item_name": "API Keys",
        "field_label": "my_api_key"
    }
)

# Update existing mapping
mcp_parquet_update_records(
    data_type="env_var_mappings",
    filters={"env_var": "MY_API_KEY"},
    updates={"op_reference": "op://Personal/NewItem/field"}
)

Via direct parquet editing:

import pandas as pd
from scripts.config import DATA_DIR

# Read mappings
mappings_file = DATA_DIR / "env_var_mappings" / "env_var_mappings.parquet"
df = pd.read_parquet(mappings_file)

# Add or modify rows
# ...

# Write back
df.to_parquet(mappings_file)

Environment-Based Keys

For environment-specific keys (e.g., different API keys for dev/prod):

# Development key
{
    "env_var": "OPENAI_API_KEY",
    "op_reference": "op://Personal/API-Keys/openai_dev",
    "environment_based": True,
    "environment_key": "development"
}

# Production key
{
    "env_var": "OPENAI_API_KEY",
    "op_reference": "op://Personal/API-Keys/openai_prod",
    "environment_based": True,
    "environment_key": "production"
}

Set environment:

export ENVIRONMENT=production  # or "development"

Execution Instructions

Step 1: Verify Prerequisites

If using MCP server:

# Verify MCP server is configured (check ~/.cursor/mcp.json)
# Restart Cursor if you just added the configuration

If using CLI fallback:

# Verify 1Password CLI is installed and signed in
op whoami
# If not signed in: op signin

Step 2: Run Sync Command

From repository root:

python execution/scripts/op_sync_env_from_1password.py

Or with custom .env path:

python execution/scripts/op_sync_env_from_1password.py /path/to/.env

Step 3: Verify Results

Check output:

Check .env file:

# Verify variables were updated (don't print full file - contains secrets)
grep -c "=" .env  # Count of variables

Behavior

Backup

Automatic backup before modification:

Variable Updates

For each mapped variable:

  1. Resolve secret from 1Password (via MCP or CLI)
  2. Update existing variable or append new one
  3. Preserve other variables in .env (unmanaged variables untouched)

Variables with PLACEHOLDER_ prefix are skipped until configured with actual 1Password references.

Security

Security guarantees:

Error Handling

"1Password CLI is not authenticated"

Problem: Not signed in to 1Password CLI.

Solution:

op signin

"MCP failed, falling back to CLI"

Problem: MCP server unavailable or misconfigured.

Solution:

  1. Check MCP server configuration in ~/.cursor/mcp.json
  2. Restart Cursor after updating configuration
  3. Verify 1Password CLI is installed and signed in
  4. Script will automatically fall back to CLI

"Environment variable mappings file not found"

Problem: Mappings file doesn't exist.

Solution:

# Create mappings file structure
mkdir -p $DATA_DIR/env_var_mappings

# Add mappings via MCP parquet server or create parquet file
# See Configuration section above

"Empty value returned for 1Password ref"

Problem: Field exists but contains empty value.

Solution:

Related Documentation

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.