Skip to content

Commit f8c2463

Browse files
T-ravclaude
andcommitted
fix: Load .env before importing tools to ensure environment variables are available
- Move load_dotenv() to run before importing tools - Ensures SERPER_API_KEY and other env vars are set before tool modules initialize - Tools can now properly reference environment variables from .env file - Fixes issue where tools couldn't access .env variables at import time - Add noqa comments for necessary late imports 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9298117 commit f8c2463

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

docker/mcp_server.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ async def search_tool() -> dict:
4444
from dotenv import load_dotenv
4545
from fastmcp import FastMCP
4646

47-
from tools.health_check_tool import health_check_tool
48-
from tools.search_tool import search_tool
4947
from utils.logging_config import setup_logging
5048

49+
# Load environment variables FIRST before importing tools
50+
load_dotenv()
51+
5152
# Set up logging
5253
logger = setup_logging("webcat.log")
5354

54-
# Load environment variables
55-
load_dotenv()
56-
55+
# Import tools AFTER loading .env so they can access environment variables
56+
from tools.health_check_tool import health_check_tool # noqa: E402
57+
from tools.search_tool import search_tool # noqa: E402
5758

5859
# Log configuration status
5960
SERPER_API_KEY = os.environ.get("SERPER_API_KEY", "")

0 commit comments

Comments
 (0)