fix: respect WORKSPACE_MCP_CREDENTIALS_DIR for multi-account support
- Add WORKSPACE_MCP_CREDENTIALS_DIR as primary env var (preferred) - Keep GOOGLE_MCP_CREDENTIALS_DIR for backward compatibility - Add os.path.expanduser() to handle ~ in paths - Add logging to show which credentials directory is being used - Display credentials directory in startup configuration This enables running multiple MCP instances with different Google accounts by configuring separate credential directories. Fixes #373
This commit is contained in:
@@ -79,13 +79,27 @@ class LocalDirectoryCredentialStore(CredentialStore):
|
||||
|
||||
Args:
|
||||
base_dir: Base directory for credential files. If None, uses the directory
|
||||
configured by the GOOGLE_MCP_CREDENTIALS_DIR environment variable,
|
||||
or defaults to ~/.google_workspace_mcp/credentials if the environment
|
||||
variable is not set.
|
||||
configured by environment variables in this order:
|
||||
1. WORKSPACE_MCP_CREDENTIALS_DIR (preferred)
|
||||
2. GOOGLE_MCP_CREDENTIALS_DIR (backward compatibility)
|
||||
3. ~/.google_workspace_mcp/credentials (default)
|
||||
"""
|
||||
if base_dir is None:
|
||||
if os.getenv("GOOGLE_MCP_CREDENTIALS_DIR"):
|
||||
base_dir = os.getenv("GOOGLE_MCP_CREDENTIALS_DIR")
|
||||
# Check WORKSPACE_MCP_CREDENTIALS_DIR first (preferred)
|
||||
workspace_creds_dir = os.getenv("WORKSPACE_MCP_CREDENTIALS_DIR")
|
||||
google_creds_dir = os.getenv("GOOGLE_MCP_CREDENTIALS_DIR")
|
||||
|
||||
if workspace_creds_dir:
|
||||
base_dir = os.path.expanduser(workspace_creds_dir)
|
||||
logger.info(
|
||||
f"Using credentials directory from WORKSPACE_MCP_CREDENTIALS_DIR: {base_dir}"
|
||||
)
|
||||
# Fall back to GOOGLE_MCP_CREDENTIALS_DIR for backward compatibility
|
||||
elif google_creds_dir:
|
||||
base_dir = os.path.expanduser(google_creds_dir)
|
||||
logger.info(
|
||||
f"Using credentials directory from GOOGLE_MCP_CREDENTIALS_DIR: {base_dir}"
|
||||
)
|
||||
else:
|
||||
home_dir = os.path.expanduser("~")
|
||||
if home_dir and home_dir != "~":
|
||||
@@ -94,9 +108,12 @@ class LocalDirectoryCredentialStore(CredentialStore):
|
||||
)
|
||||
else:
|
||||
base_dir = os.path.join(os.getcwd(), ".credentials")
|
||||
logger.info(f"Using default credentials directory: {base_dir}")
|
||||
|
||||
self.base_dir = base_dir
|
||||
logger.info(f"LocalJsonCredentialStore initialized with base_dir: {base_dir}")
|
||||
logger.info(
|
||||
f"LocalDirectoryCredentialStore initialized with base_dir: {base_dir}"
|
||||
)
|
||||
|
||||
def _get_credential_path(self, user_email: str) -> str:
|
||||
"""Get the file path for a user's credentials."""
|
||||
|
||||
Reference in New Issue
Block a user