Skip to content

Conversation

@tickernelz
Copy link

Problem

When running uvx mcp-server-odoo from a workspace directory containing a .env file, the application would fail with the error:

Configuration error: No .env file found and ODOO_URL not set in environment.
Please create a .env file based on .env.example or set environment variables.

This occurred even when a valid .env file existed in the current working directory.

Root Cause

The issue was caused by redundant load_dotenv() calls:

1. First call in `__main__.py` without proper path handling
2. Second call in `config.py` with incomplete .env file detection logic

Solution

* **Removed redundant `load_dotenv()` call** from `__main__.py` to eliminate conflicts
* **Improved .env file detection logic** in `config.py` to properly handle current working directory
* **Enhanced error handling** to provide clearer feedback when .env files are not found

Changes Made

1. **`mcp_server_odoo/__main__.py`**: Removed the premature `load_dotenv()` call that was interfering with proper configuration loading
2. **`mcp_server_odoo/config.py`**:
    * Improved `load_config()` function to better handle .env file detection

    * Added proper tracking of whether .env file was successfully loaded

    * Maintained backward compatibility with existing environment variable workflows

Testing

* ✅ Verified `.env` file loading from current working directory
* ✅ Confirmed `uvx mcp-server-odoo --version` works correctly
* ✅ Validated configuration parsing with real workspace `.env` files
* ✅ Ensured no regression in environment variable fallback behavior

Impact

* Fixes the primary use case where users run the MCP server from their Odoo workspace directories
* Maintains all existing functionality for environment variable-based configuration
* No breaking changes to existing workflows

This fix ensures that mcp-server-odoo can be reliably executed from any directory containing a properly formatted .env file, resolving the configuration loading issue reported by users.

- Remove redundant dotenv loading in main module
- Add explicit .env file path handling in config module
- Implement env_loaded flag to track environment loading status
- Raise clear error when no .env file found and ODOO_URL missing
- Update server version to match project version
- Bump project version from 0.3.0 to 0.3.1
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.

1 participant