From f83c49c0f340d1a3accba1fe1317994b492755c0 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Tue, 11 Mar 2025 11:39:21 -0600 Subject: [PATCH] feat(keys): pass local keys to the session by default --- README.md | 5 +++++ mcontainer/container.py | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bb90f71..9c24581 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,11 @@ mc session create -e VAR1=value1 -e VAR2=value2 # Shorthand for creating a session with a project repository mc github.com/username/repo + +# Local development with API keys +# OPENAI_API_KEY, ANTHROPIC_API_KEY, and OPENROUTER_API_KEY from your +# local environment are automatically passed to the container +mc session create ``` ## Driver Management diff --git a/mcontainer/container.py b/mcontainer/container.py index 36d1e22..a728b19 100644 --- a/mcontainer/container.py +++ b/mcontainer/container.py @@ -123,6 +123,12 @@ class ContainerManager: if project: env_vars["MC_PROJECT_URL"] = project + # Pass API keys from host environment to container for local development + api_keys = ["OPENAI_API_KEY", "ANTHROPIC_API_KEY", "OPENROUTER_API_KEY"] + for key in api_keys: + if key in os.environ and key not in env_vars: + env_vars[key] = os.environ[key] + # Pull image if needed try: self.client.images.get(driver.image) @@ -136,8 +142,6 @@ class ContainerManager: # If no project URL and mount_local is True, mount local directory to /app if not project and mount_local: # Mount current directory to /app in the container - import os - current_dir = os.getcwd() volumes[current_dir] = {"bind": "/app", "mode": "rw"} print(f"Mounting local directory {current_dir} to /app")