Skip to content

[BUG] Basic Memory failed in Claude Code #278

Closed

Description

@SWSAmor

Bug Description

Basic Memory fails to start with a Pydantic validation error for log_level. The FastMCP Settings class expects uppercase log level values ('INFO') but receives lowercase ('info'), causing the MCP server to fail during initialization.

Steps To Reproduce

  1. Install Basic Memory version '0.14.3' using uv
  2. Configure project with default settings (log_level: "INFO" in config)
  3. Run Claude Code with Basic Memory MCP server configured
  4. See validation error and connection failure

Expected Behavior

Basic Memory should start successfully and connect to Claude Code without validation errors, regardless of log level case sensitivity.

Actual Behavior

MCP server fails to start with the following error:

pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
log_level
  Input should be 'DEBUG', 'INFO', 'WARNING', 'ERROR' or 'CRITICAL' [type=literal_error, input_value='info', input_type=str]

The server connection closes immediately after this validation error.

Environment

  • OS: macOS 15.6.1 Sequoia
  • Python version: Managed by uv (Python 3.13 based on error traceback)
  • Basic Memory version: 0.14.3
  • Installation method: uv
  • Claude Desktop version: Claude Code 1.0.93

Additional Context

  • Configuration file shows uppercase "log_level": "INFO"
  • Works perfectly with Claude Desktop and CLI
  • Only fails in Claude Code environment
  • Error occurs in FastMCP Settings initialization, suggesting the lowercase 'info' comes from somewhere other than the Basic Memory config

Configuration file:

{
  "env": "dev",
  "projects": {
    7 projects
  },
  "default_project": "someproject",
  "log_level": "INFO",
  "sync_delay": 1000,
  "update_permalinks_on_move": false,
  "sync_changes": true,
  "api_url": null
}

Possible Solution

The issue appears to be in the FastMCP dependency where Settings() initialization receives a lowercase 'info' value from somewhere (possibly environment variables or Claude Code's MCP server configuration).

Potential fixes:

  1. Case-insensitive validation: Modify FastMCP Settings to accept both cases and normalize to uppercase
  2. Environment variable check: Ensure Claude Code doesn't set a lowercase LOG_LEVEL environment variable
  3. Basic Memory normalization: Add input normalization in Basic Memory before passing to FastMCP
  4. Dependency version pinning: Check if a recent FastMCP update introduced stricter validation

The root cause seems to be that while the Basic Memory config correctly uses uppercase "INFO", the FastMCP Settings class receives lowercase "info" from another source during Claude Code execution.

Activity

  1. phernandez commented on Aug 27, 2025

    @phernandez
    Member

    @SWSAmor this is annoying. I think what is going on may be that basic memory is picking up a .env file locally with a value for log_level and causing problems. Try running it from a directory that doesn't contain a .env file. This is certainly a bug and we are fixing it. But try that as a work around.

    relates to: #227

  2. added this to the v0.15.0 milestone on Sep 18, 2025
  3. phernandez commented on Sep 26, 2025

    @phernandez
    Member

    @claude what is the issue here?

  4. claude commented on Sep 26, 2025

    @claude
    Contributor

    Claude finished @phernandez's task —— View job


    Analysis Complete ✅

    Todo List

    • Read MCP server implementation to understand Settings initialization
    • Check environment variable handling
    • Look for .env file processing
    • Analyze FastMCP integration and Settings class
    • Provide explanation of the issue

    The Issue Explained

    The problem is a case-sensitivity mismatch in log level configuration between what FastMCP expects and what it receives in the Claude Code environment. Here's what's happening:

    1. Basic Memory Configuration (src/basic_memory/config.py):

      • Uses Pydantic BaseSettings with env_prefix "BASIC_MEMORY_"
      • Automatically loads .env files via Pydantic's env_file=".env" setting
      • Default log_level is "INFO" (uppercase)
    2. The Root Cause:

      • FastMCP's internal Settings class has strict validation requiring uppercase log levels: 'DEBUG', 'INFO', 'WARNING', 'ERROR', or 'CRITICAL'
      • Claude Code appears to be setting an environment variable (likely LOG_LEVEL without the BASIC_MEMORY_ prefix) with lowercase value 'info'
      • FastMCP is picking up this lowercase value, possibly from:
        • A generic LOG_LEVEL environment variable set by Claude Code
        • A local .env file in the working directory with LOG_LEVEL=info
        • FastMCP's own environment variable handling
    3. Why it works elsewhere:

      • Claude Desktop and CLI don't set a conflicting LOG_LEVEL environment variable
      • Basic Memory's own configuration correctly uses uppercase "INFO"

    The Solution

    As @phernandez mentioned, this is indeed a bug. The immediate workaround is to:

    • Run Basic Memory from a directory without a .env file containing lowercase log levels
    • Or ensure any .env file uses uppercase log levels (LOG_LEVEL=INFO not LOG_LEVEL=info)

    The proper fix would be to:

    1. Have FastMCP normalize log level values to uppercase before validation
    2. Or have Basic Memory intercept and normalize the log_level before passing to FastMCP
    3. Or ensure Claude Code doesn't set lowercase log level environment variables

    This issue is related to #227 as mentioned, where environment variable handling needs to be more robust.

    Job Run: View Run
    Branch: claude/issue-278-20250926-1441

  5. phernandez commented on Oct 4, 2025

    @phernandez
    Member

    Duplicate of #227 - Fixed by PR #330

    This issue has the same root cause as #227. Basic Memory was automatically loading .env files from the current working directory via Pydantic's env_file=".env" setting.

    When you run Basic Memory from a directory containing a .env file with LOG_LEVEL=info (lowercase), it overrides the configuration and causes the validation error.

    Fix: PR #330 removes automatic .env file loading, which will resolve this issue.

    Workaround until the fix is released:
    Run Basic Memory from a directory that doesn't contain a .env file, or ensure your .env file uses uppercase: LOG_LEVEL=INFO

    Closing as duplicate of #227.

  6. phernandez commented on Oct 4, 2025

    @phernandez
    Member

    Fixed by PR #330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions