Skip to main content
Glama
nesirat

MCP Vulnerability Management System

by nesirat
session.py1.33 kB
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, Session from sqlalchemy.pool import QueuePool from app.core.config import settings from contextlib import contextmanager from typing import Generator # Create engine with connection pooling engine = create_engine( settings.DATABASE_URL, poolclass=QueuePool, pool_size=settings.DB_POOL_SIZE, max_overflow=settings.DB_MAX_OVERFLOW, pool_recycle=settings.DB_POOL_RECYCLE, pool_timeout=settings.DB_POOL_TIMEOUT, pool_pre_ping=True, # Enable connection health checks echo=False # Set to True for SQL query logging ) # Create session factory SessionLocal = sessionmaker( autocommit=False, autoflush=False, bind=engine ) @contextmanager def get_db() -> Generator[Session, None, None]: """ Context manager for database sessions. Ensures proper session cleanup and connection return to pool. """ db = SessionLocal() try: yield db db.commit() except Exception: db.rollback() raise finally: db.close() def get_db_session() -> Session: """ Dependency for FastAPI route handlers. Returns a database session that will be automatically closed. """ db = SessionLocal() try: yield db finally: db.close()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nesirat/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server