validate_mongo_config (memory/mongodb.py)

agent-service-toolkit · src/memory/mongodb.py · python · MIT
database

Builds MongoDB connection strings and provides async context manager for LangGraph checkpoint persistence.

# Source: https://github.com/JoshuaC215/agent-service-toolkit | License: MIT | Copyright 2024 Joshua Carroll
# Provided via justclaw.it.com; keep this notice with the code.
import asyncio
import logging
import urllib.parse
from contextlib import AbstractAsyncContextManager

from langgraph.checkpoint.mongodb import MongoDBSaver
from pymongo import MongoClient

from core.settings import settings

logger = logging.getLogger(__name__)


def _has_auth_credentials() -> bool:
    required_auth = ["MONGO_USER", "MONGO_PASSWORD", "MONGO_AUTH_SOURCE"]
    set_auth = [var for var in required_auth if getattr(settings, var, None)]
    if len(set_auth) > 0 and len(set_auth) != len(required_auth):
        raise ValueError(
            f"If any of the following environment variables are set, all must be s

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key