|
13 | 13 | def get_db_config():
|
14 | 14 | """Get database configuration from environment variables."""
|
15 | 15 | config = {
|
16 |
| - "hostname": os.getenv("IRIS_HOSTNAME", "localhost"), |
| 16 | + "hostname": os.getenv("IRIS_HOSTNAME"), |
17 | 17 | "port": int(os.getenv("IRIS_PORT", 1972)),
|
18 |
| - "namespace": os.getenv("IRIS_NAMESPACE", "USER"), |
19 |
| - "username": os.getenv("IRIS_USERNAME", "_SYSTEM"), |
20 |
| - "password": os.getenv("IRIS_PASSWORD", "SYS"), |
| 18 | + "namespace": os.getenv("IRIS_NAMESPACE"), |
| 19 | + "username": os.getenv("IRIS_USERNAME"), |
| 20 | + "password": os.getenv("IRIS_PASSWORD"), |
21 | 21 | }
|
22 | 22 |
|
23 |
| - logger.info("Server configuration: iris://" + config["hostname"] + ":" + str(config["port"]) + "/" + config["namespace"]) |
24 |
| - if not all([config["username"], config["password"], config["namespace"]]): |
| 23 | + if not all([config["hostname"], config["username"], config["password"], config["namespace"]]): |
25 | 24 | raise ValueError("Missing required database configuration")
|
| 25 | + logger.info(f"Server configuration: iris://{config["username"]}:{"x"*8}@{config["hostname"]}:{config["port"]}/{config["namespace"]}") |
26 | 26 |
|
27 | 27 | return config
|
28 | 28 |
|
29 | 29 |
|
30 | 30 | @asynccontextmanager
|
31 | 31 | async def server_lifespan(server: MCPServer) -> AsyncIterator[dict]:
|
32 | 32 | """Manage server startup and shutdown lifecycle."""
|
33 |
| - config = get_db_config() |
34 | 33 | try:
|
| 34 | + config = get_db_config() |
| 35 | + except ValueError: |
| 36 | + yield {"db": None, "iris": None} |
| 37 | + return |
| 38 | + try: |
| 39 | + |
35 | 40 | db = irisnative.connect(**config)
|
36 | 41 | iris = irisnative.createIRIS(db)
|
37 | 42 | yield {"db": db, "iris": iris}
|
|
0 commit comments