Skip to content

Commit 7701745

Browse files
authored
Merge pull request #61 from jgwill/60-fck
that was the ssl=True that was not passed
2 parents bb241e3 + f479d73 commit 7701745

File tree

11 files changed

+123
-38
lines changed

11 files changed

+123
-38
lines changed

_env.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
3+
#---START MIGRATD from .env
4+
session_id=598a16b1-6ada-429d-a587-9bf2d7b9646e
5+
issue_87_session_id=8dde9377-b261-4399-9048-0dbbe65d7b2e
6+
7+
8+
9+
session_id_250930143427=314f51c5-36d6-44e3-bf0b-e0a78a58d5e4
10+
MCP_CONFIGS_FILES="/src/.mcp.STC-IAIP.storytelling-314f51c5-36d6-44e3-bf0b-e0a78a58d5e4.json"
11+
ADD_DIRS_PATHS="/w/orpheus_ART/ /src/IAIP/ /cesaret/book/_/tcc/ /w/CSV/kb2508"
12+
session_id_2509301518=f9739d98-7b3e-4eaf-a3e8-1257f8d91d38
13+
session_id_2509301518_SOUTH=8001afb5-27ac-42f5-956e-31282de665d2
14+
15+
session_id_251006_issue_129_IAIP_AUTOETHNOGRAPHY_AND_CEREMONIAL_DIARIES=7910843e-57bf-4aee-8996-3cae458f6fef
16+
session_id_251006_issue_129_IAIP_AUTOETHNOGRAPHY_AND_CEREMONIAL_DIARIES_MCP_CONFIG_FILES="/src/.mcp.STC-IAIP.storytelling-314f51c5-36d6-44e3-bf0b-e0a78a58d5e4.json /src/.mcp.github.miadisabelle.json"
17+
session_id_251006_issue_130_mia_agents_5631e86759004d65865aff8b08e3bc3a="5631e867-5900-4d65-865a-ff8b08e3bc3a"
18+
19+
#251008
20+
session_id_251008_issue_xyz_arena_DIR_ADDS="/b/Dropbox/jgt/edu/llm_mastery/arenas_250706 /cesaret/book/_/tcc/ /w/CSV/kb2508 /w/orpheus_ART/"
21+
session_id_251008_issue_xyz_arena_STCGOAL="Fragmented thinking made these directories /b/Dropbox/jgt/edu/llm_mastery/arenas_250706 /cesaret/book/_/tcc/ /w/CSV/kb2508 /w/orpheus_ART/ to occurs, the goal is explore them and we would unify the platform creation for a career I love and something I can present to the community. They could be considered as implementing the same feature sets or being different packages that we would work on like in @jgwill/ python package."
22+
session_id_251008_issue_xyz_arena_UUID="0f5aaa1e-faea-4ec3-af79-a594fb3a271d"
23+
session_id_251008_issue_xyz_arena_TLID="2510081204"
24+
25+
26+
27+
28+
session_id_LAUNCH_IAIP_CLAUDE_4_DIRECTIONS_PROPOSAL_250926=5cf366c5-efb0-4212-8430-71cecd7d190e
29+
session_id_2510082009_follow_storytelling_session=3c8933e4-791b-42ef-85a6-98b4ab3e68dd
30+
session_id_jgwill_storytelling_251014=ddd138bd-28ce-4967-97b6-e83113efefde
31+
session_id_2510161024=df424a00-7514-4332-a240-63275d4ed831
32+
#---END MIGRATD from .env
33+
34+
35+
36+
session_id__coaiapy_mcp_2510191020=08636648-9d35-490f-896d-70a2d52d5164
37+
38+
39+
session_id__issue_60__UUID=2ab5df9e-447e-467a-ad92-d136f6b8d018
40+
41+

coaiapy-mcp/coaiapy_mcp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
instead of subprocess wrappers for better performance and error handling.
1313
"""
1414

15-
__version__ = "0.1.13"
15+
__version__ = "0.1.18"
1616
__author__ = "Guillaume Isabelle"
1717
__email__ = "jgi@jgwill.com"
1818

coaiapy-mcp/coaiapy_mcp/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
77
The server uses direct library imports from coaiapy instead of subprocess
88
wrappers for better performance and error handling.
9+
10+
Configuration:
11+
COAIAPY_ENV_PATH: Custom path to .env file (default: .env in current directory)
12+
Set via MCP server environment configuration.
13+
Example: COAIAPY_ENV_PATH=/path/to/custom/.env
914
"""
1015

1116
import asyncio

coaiapy-mcp/coaiapy_mcp/tools.py

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,50 @@
3838
print("Some tools may not be available.")
3939

4040
# Load configuration once on module import
41+
# Support custom .env path via COAIAPY_ENV_PATH environment variable
4142
try:
42-
config = coaiamodule.read_config()
43+
env_path = os.getenv('COAIAPY_ENV_PATH')
44+
config = coaiamodule.read_config(env_path=env_path)
4345
except Exception as e:
4446
print(f"Warning: Could not load config: {e}")
4547
config = {}
4648

4749
# Initialize Redis client
48-
redis_config = config.get("jtaleconf", {})
49-
try:
50-
redis_client = redis.Redis(
51-
host=redis_config.get("host", "localhost"),
52-
port=redis_config.get("port", 6379),
53-
db=redis_config.get("db", 0),
54-
password=redis_config.get("password") if redis_config.get("password") else None,
55-
decode_responses=True,
56-
)
57-
# Test connection
58-
redis_client.ping()
59-
REDIS_AVAILABLE = True
60-
except (redis.RedisError, redis.ConnectionError) as e:
61-
print(f"Warning: Redis not available: {e}")
62-
redis_client = None
63-
REDIS_AVAILABLE = False
50+
# Try direct URL first (handles SSL automatically), fall back to component config
51+
redis_client = None
52+
REDIS_AVAILABLE = False
53+
54+
# Check for direct Redis URL from environment
55+
redis_url = os.getenv('REDIS_URL') or os.getenv('KV_URL')
56+
if redis_url:
57+
try:
58+
redis_client = redis.from_url(redis_url, decode_responses=True)
59+
redis_client.ping()
60+
REDIS_AVAILABLE = True
61+
except Exception as e:
62+
print(f"Warning: Redis connection failed with URL: {e}")
63+
redis_client = None
64+
65+
# Fall back to component-based config if URL didn't work
66+
if not REDIS_AVAILABLE:
67+
redis_config = config.get("jtaleconf", {})
68+
try:
69+
redis_client = redis.Redis(
70+
host=redis_config.get("host", "localhost"),
71+
port=redis_config.get("port", 6379),
72+
db=redis_config.get("db", 0),
73+
password=redis_config.get("password") if redis_config.get("password") else None,
74+
ssl=redis_config.get("ssl", False),
75+
ssl_cert_reqs="none" if redis_config.get("ssl") else "required",
76+
decode_responses=True,
77+
)
78+
# Test connection
79+
redis_client.ping()
80+
REDIS_AVAILABLE = True
81+
except (redis.RedisError, redis.ConnectionError) as e:
82+
print(f"Warning: Redis not available: {e}")
83+
redis_client = None
84+
REDIS_AVAILABLE = False
6485

6586
# Initialize Langfuse client
6687
try:

coaiapy-mcp/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "coaiapy-mcp"
7-
version = "0.1.13"
7+
version = "0.1.18"
88
description = "MCP (Model Context Protocol) wrapper for coaiapy observability toolkit"
99
readme = "README.md"
1010
requires-python = ">=3.10"
@@ -24,7 +24,7 @@ classifiers = [
2424
]
2525

2626
dependencies = [
27-
"coaiapy>=0.2.87",
27+
"coaiapy>=0.2.95",
2828
"mcp>=1.0.0",
2929
"pydantic>=2.0",
3030
"langfuse>=2.0",
@@ -62,4 +62,4 @@ target-version = ['py310']
6262

6363
[tool.ruff]
6464
line-length = 100
65-
target-version = "0.1.13"
65+
target-version = "0.1.18"

coaiapy-mcp/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
2+
conda activate coaiapy
33
# coaiapy-mcp Release Script
44
# Prepares distribution and publishes to PyPI
55

coaiapy-mcp/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Core dependencies
2-
coaiapy>=0.2.87
2+
coaiapy>=0.2.95
33
mcp>=1.0.0
44
pydantic>=2.0
55
langfuse>=2.0

coaiapy/coaiamodule.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# version in pyrec prod
1212
config=None
13+
_loaded_env_path=None # Track which env_path was used to load config
1314

1415

1516
def find_existing_config():
@@ -54,14 +55,15 @@ def find_existing_config():
5455

5556
def load_env_file(env_path='.env'):
5657
"""Simple .env file loader compatible with Python 3.6
57-
58-
Loads environment variables from .env file and sets them in os.environ
59-
ONLY if they don't already exist in os.environ (respecting OS env priority).
58+
59+
Loads environment variables from .env file and sets them in os.environ.
60+
Local .env file takes precedence over pre-existing environment variables.
6061
"""
6162
env_vars = {}
6263
if os.path.exists(env_path):
6364
try:
6465
with open(env_path, 'r') as f:
66+
lines_read = 0
6567
for line in f:
6668
line = line.strip()
6769
if line and not line.startswith('#') and '=' in line:
@@ -73,11 +75,15 @@ def load_env_file(env_path='.env'):
7375
(value.startswith("'") and value.endswith("'")):
7476
value = value[1:-1]
7577
env_vars[key] = value
76-
# Set in os.environ ONLY if not already set (respects OS env priority)
77-
if key not in os.environ:
78-
os.environ[key] = value
78+
# Always set in os.environ - local .env takes precedence
79+
os.environ[key] = value
80+
lines_read += 1
7981
except Exception as e:
80-
print(f"Warning: Error loading .env file: {e}")
82+
print(f"Warning: Error loading .env file from '{env_path}': {e}")
83+
else:
84+
# Only warn about missing custom .env paths, not the default .env
85+
if env_path != '.env':
86+
print(f"Warning: Custom .env file not found: {env_path}")
8187
return env_vars
8288

8389
def merge_configs(base_config, override_config):
@@ -90,12 +96,21 @@ def merge_configs(base_config, override_config):
9096
merged[key] = value
9197
return merged
9298

93-
def read_config():
99+
def read_config(env_path=None):
94100
global config
95-
96-
if config is None:
101+
global _loaded_env_path
102+
103+
# Determine .env path: explicit param > COAIAPY_ENV_PATH env var > default .env
104+
if env_path is None:
105+
env_path = os.getenv('COAIAPY_ENV_PATH', '.env')
106+
107+
# Reload config if env_path changed or config not loaded yet
108+
if config is None or _loaded_env_path != env_path:
97109
# Load .env file first if it exists
98-
env_vars = load_env_file()
110+
env_vars = load_env_file(env_path)
111+
if not env_vars and env_path != '.env':
112+
# Warn if custom env_path was specified but file not found
113+
print(f"Warning: COAIAPY_ENV_PATH={env_path} was specified but file not found or empty")
99114

100115
# Default configuration
101116
config = {
@@ -222,6 +237,9 @@ def get_env_value(env_key, config_value, env_vars_dict=None):
222237
config["langfuse_base_url"] = get_env_value("LANGFUSE_HOST", config.get("langfuse_base_url", "https://us.cloud.langfuse.com"))
223238
config["langfuse_auth3"] = get_env_value("LANGFUSE_AUTH3", config.get("langfuse_auth3", ""))
224239

240+
# Track which env_path was used to load this config
241+
_loaded_env_path = env_path
242+
225243
return config
226244

227245

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "coaiapy"
10-
version = "0.2.87"
10+
version = "0.2.95"
1111
description = "A Python package for audio transcription, synthesis, and tagging using Boto3."
1212
readme = "README.md"
1313
requires-python = ">=3.6"

release.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
2+
conda activate coaiapy
33
# CoaiaPy Release Script
44
# Prepares distribution and publishes to PyPI
55

@@ -36,4 +36,4 @@ echo "📋 Next steps:"
3636
echo " - Push changes: git push origin main"
3737
echo " - Push tag: git push origin v${VERSION}"
3838
echo " - Verify package on PyPI: https://pypi.org/project/coaiapy/"
39-
echo " - Test installation: pip install coaiapy"
39+
echo " - Test installation: pip install coaiapy"

0 commit comments

Comments
 (0)