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:
cvrt-jh
2026-01-20 17:07:01 +01:00
parent 2b72c4508f
commit e98bb7115d
3 changed files with 63 additions and 10 deletions

16
main.py
View File

@@ -153,10 +153,26 @@ def main():
else "Invalid or too short"
)
# Determine credentials directory (same logic as credential_store.py)
workspace_creds_dir = os.getenv("WORKSPACE_MCP_CREDENTIALS_DIR")
google_creds_dir = os.getenv("GOOGLE_MCP_CREDENTIALS_DIR")
if workspace_creds_dir:
creds_dir_display = os.path.expanduser(workspace_creds_dir)
creds_dir_source = "WORKSPACE_MCP_CREDENTIALS_DIR"
elif google_creds_dir:
creds_dir_display = os.path.expanduser(google_creds_dir)
creds_dir_source = "GOOGLE_MCP_CREDENTIALS_DIR"
else:
creds_dir_display = os.path.join(
os.path.expanduser("~"), ".google_workspace_mcp", "credentials"
)
creds_dir_source = "default"
config_vars = {
"GOOGLE_OAUTH_CLIENT_ID": os.getenv("GOOGLE_OAUTH_CLIENT_ID", "Not Set"),
"GOOGLE_OAUTH_CLIENT_SECRET": redacted_secret,
"USER_GOOGLE_EMAIL": os.getenv("USER_GOOGLE_EMAIL", "Not Set"),
"CREDENTIALS_DIR": f"{creds_dir_display} ({creds_dir_source})",
"MCP_SINGLE_USER_MODE": os.getenv("MCP_SINGLE_USER_MODE", "false"),
"MCP_ENABLE_OAUTH21": os.getenv("MCP_ENABLE_OAUTH21", "false"),
"WORKSPACE_MCP_STATELESS_MODE": os.getenv(