Skip to content

Commit e935ffd

Browse files
committed
updated init logic
1 parent b19997d commit e935ffd

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

example.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ def __init__(self):
2020
async def connect_to_server(self):
2121
"""Connect to an MCP server"""
2222
server_params = StdioServerParameters(
23-
command=sys.executable, args=["-m", "mcp_server_iris"], env=None
23+
command=sys.executable, args=["-m", "mcp_server_iris"], env={
24+
"IRIS_HOSTNAME": "localhost",
25+
"IRIS_PORT": "1972",
26+
"IRIS_NAMESPACE": "USER",
27+
"IRIS_USERNAME": "_SYSTEM",
28+
"IRIS_PASSWORD": "SYS",
29+
}
2430
)
2531
# server_params = StdioServerParameters(
26-
# command="uvx", args=["mcp-server-iris"], env=None
32+
# command="uvx", args=["."],
2733
# )
2834

2935
stdio_transport = await self.exit_stack.enter_async_context(

src/mcp_server_iris/server.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,30 @@
1313
def get_db_config():
1414
"""Get database configuration from environment variables."""
1515
config = {
16-
"hostname": os.getenv("IRIS_HOSTNAME", "localhost"),
16+
"hostname": os.getenv("IRIS_HOSTNAME"),
1717
"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"),
2121
}
2222

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"]]):
2524
raise ValueError("Missing required database configuration")
25+
logger.info(f"Server configuration: iris://{config["username"]}:{"x"*8}@{config["hostname"]}:{config["port"]}/{config["namespace"]}")
2626

2727
return config
2828

2929

3030
@asynccontextmanager
3131
async def server_lifespan(server: MCPServer) -> AsyncIterator[dict]:
3232
"""Manage server startup and shutdown lifecycle."""
33-
config = get_db_config()
3433
try:
34+
config = get_db_config()
35+
except ValueError:
36+
yield {"db": None, "iris": None}
37+
return
38+
try:
39+
3540
db = irisnative.connect(**config)
3641
iris = irisnative.createIRIS(db)
3742
yield {"db": db, "iris": iris}

0 commit comments

Comments
 (0)