Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mcp_server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ MODEL_NAME=gpt-4.1-mini
# See README.md "Concurrency and LLM Provider 429 Rate Limit Errors" for details
SEMAPHORE_LIMIT=10

# MCP server logging level (default: INFO)
# Controls verbosity of Graphiti MCP server logs only
# Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL=INFO

# Optional: Path configuration for Docker
# PATH=/root/.local/bin:${PATH}

Expand Down
1 change: 1 addition & 0 deletions mcp_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ The `config.yaml` file supports environment variable expansion using `${VAR_NAME
- `AZURE_OPENAI_API_VERSION`: Optional Azure OpenAI API version
- `USE_AZURE_AD`: Optional use Azure Managed Identities for authentication
- `SEMAPHORE_LIMIT`: Episode processing concurrency. See [Concurrency and LLM Provider 429 Rate Limit Errors](#concurrency-and-llm-provider-429-rate-limit-errors)
- `LOG_LEVEL`: MCP server logging verbosity (default: `INFO`). Valid values: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`

You can set these variables in a `.env` file in the project directory.

Expand Down
6 changes: 5 additions & 1 deletion mcp_server/src/graphiti_mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'

# Log level from environment variable (default: INFO)
# Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO').upper()

logging.basicConfig(
level=logging.INFO,
level=getattr(logging, LOG_LEVEL, logging.INFO),
format=LOG_FORMAT,
datefmt=DATE_FORMAT,
stream=sys.stderr,
Expand Down
38 changes: 38 additions & 0 deletions mcp_server/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,41 @@ def test_config_loading():
return config


def test_log_level_environment_variable():
"""Test LOG_LEVEL environment variable configuration for MCP server."""
import logging

print('\nTesting LOG_LEVEL environment variable...')

# Test default (INFO)
if 'LOG_LEVEL' in os.environ:
del os.environ['LOG_LEVEL']
log_level = os.getenv('LOG_LEVEL', 'INFO').upper()
assert getattr(logging, log_level, logging.INFO) == logging.INFO
print('✓ Default LOG_LEVEL is INFO')

# Test DEBUG override
os.environ['LOG_LEVEL'] = 'DEBUG'
log_level = os.getenv('LOG_LEVEL', 'INFO').upper()
assert getattr(logging, log_level, logging.INFO) == logging.DEBUG
print('✓ LOG_LEVEL=DEBUG works correctly')
del os.environ['LOG_LEVEL']

# Test invalid value falls back to INFO
os.environ['LOG_LEVEL'] = 'INVALID'
log_level = os.getenv('LOG_LEVEL', 'INFO').upper()
assert getattr(logging, log_level, logging.INFO) == logging.INFO
print('✓ Invalid LOG_LEVEL falls back to INFO')
del os.environ['LOG_LEVEL']

# Test case insensitivity
os.environ['LOG_LEVEL'] = 'warning'
log_level = os.getenv('LOG_LEVEL', 'INFO').upper()
assert getattr(logging, log_level, logging.INFO) == logging.WARNING
print('✓ LOG_LEVEL is case-insensitive')
del os.environ['LOG_LEVEL']


def test_llm_factory(config: GraphitiConfig):
"""Test LLM client factory creation."""
print('\nTesting LLM client factory...')
Expand Down Expand Up @@ -186,6 +221,9 @@ async def main():
# Test configuration loading
config = test_config_loading()

# Test LOG_LEVEL environment variable
test_log_level_environment_variable()

# Test factories
test_llm_factory(config)
test_embedder_factory(config)
Expand Down