Skip to content

Conversation

@rahul188
Copy link
Contributor

@rahul188 rahul188 commented Dec 19, 2025

Fixes #11

Problem:
The tools.py module was reading the MAPS_API_KEY environment variable before the .env file was loaded, causing it to always default to 'no_api_found'.

Root Cause:
MAPS_API_KEY was being read at module import time, before any code called dotenv.load_dotenv().

Solution:
Moved dotenv.load_dotenv() and API key retrieval inside the get_maps_mcp_toolset() function. This ensures the .env file is loaded before reading the environment variable.

Why this approach:

  • ✅ Follows Python best practices (imports at top)
  • ✅ Uses lazy evaluation for environment variables
  • ✅ Avoids code execution at module import time
  • ✅ Clean, minimal change

Testing:
Verified with dummy .env file that MAPS_API_KEY now correctly loads from the environment.

Files Changed:

  • examples/launchmybakery/adk_agent/mcp_bakery_app/tools.py

@google-cla
Copy link

google-cla bot commented Dec 19, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@rahul188 rahul188 force-pushed the fix/load-dotenv-in-tools branch 2 times, most recently from 435ccfa to 9fced19 Compare December 19, 2025 05:40
…Y is available

Moved dotenv.load_dotenv() and API key retrieval inside get_maps_mcp_toolset()
function. This ensures the .env file is loaded before reading MAPS_API_KEY,
fixing the issue where it would default to 'no_api_found'.

This follows Python best practices by:
- Keeping all imports at the top of the file
- Using lazy evaluation for environment variables
- Avoiding code execution at module import time
@rahul188 rahul188 force-pushed the fix/load-dotenv-in-tools branch from 9fced19 to 27f3e4d Compare December 19, 2025 05:41
@askmeegs
Copy link
Collaborator

Thanks Rahul, tested and approved.

@askmeegs askmeegs merged commit 61213f9 into google:main Dec 19, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools.py doesn't load environment variables from .env file

2 participants