Skip to content

Commit 8b88d2c

Browse files
authored
fix: allow failed to initialize, make it can be inspected (#1)
Signed-off-by: Chojan Shang <[email protected]>
1 parent cec42de commit 8b88d2c

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/nebulagraph_mcp_server/server.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import logging
23
import os
34
from contextlib import asynccontextmanager
45
from dataclasses import dataclass
@@ -11,6 +12,12 @@
1112

1213
load_dotenv()
1314

15+
default_log_level = os.environ.get("LOG_LEVEL", "INFO").upper()
16+
log_level = getattr(logging, default_log_level, logging.INFO)
17+
18+
logging.basicConfig(level=log_level)
19+
logger = logging.getLogger("nebulagraph_mcp_server")
20+
1421

1522
@dataclass
1623
class NebulaContext:
@@ -36,15 +43,18 @@ async def nebula_lifespan(server: FastMCP) -> AsyncIterator[NebulaContext]:
3643
raise ValueError("NebulaGraph version must be v3")
3744

3845
# Initialize the connection
39-
global_pool.init(
40-
[
41-
(
42-
os.getenv("NEBULA_HOST", "127.0.0.1"),
43-
int(os.getenv("NEBULA_PORT", "9669")),
44-
)
45-
],
46-
config,
47-
)
46+
try:
47+
global_pool.init(
48+
[
49+
(
50+
os.getenv("NEBULA_HOST", "127.0.0.1"),
51+
int(os.getenv("NEBULA_PORT", "9669")),
52+
)
53+
],
54+
config,
55+
)
56+
except Exception as e:
57+
logger.error(f"Failed to initialize NebulaGraph connection: {e!s}")
4858

4959
yield NebulaContext(pool=global_pool)
5060
finally:
@@ -53,7 +63,9 @@ async def nebula_lifespan(server: FastMCP) -> AsyncIterator[NebulaContext]:
5363

5464

5565
# Create MCP server
56-
mcp = FastMCP("NebulaGraph MCP Server", lifespan=nebula_lifespan)
66+
mcp = FastMCP(
67+
"NebulaGraph MCP Server", lifespan=nebula_lifespan, log_level=default_log_level
68+
)
5769

5870

5971
@mcp.resource("schema://space/{space}")

0 commit comments

Comments
 (0)