mcp: add postgres transport session store

This commit is contained in:
a.tolmachev
2026-05-01 23:10:38 +00:00
parent 6c8be5c5d8
commit 77f83a1dc1
4 changed files with 331 additions and 33 deletions
+11 -3
View File
@@ -13,7 +13,7 @@ use sqlx::postgres::PgConnectOptions;
use tokio::net::TcpListener;
use tracing::info;
use crate::app::build_app;
use crate::{app::build_app, session::PostgresTransportSessionStore};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -35,8 +35,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pool_config = PostgresPoolConfig::from_env()?;
let runtime_limits = RuntimeLimits::from_env()?;
let api_rate_limit = mcp_api_rate_limit_config_from_env()?;
let database_options = database_options_from_env()?;
let registry = PostgresRegistry::connect_with_options_and_pool_config(
database_options_from_env()?,
database_options.clone(),
pool_config,
)
.await?;
let session_store = PostgresTransportSessionStore::connect_with_options_and_pool_config(
database_options,
pool_config,
)
.await?;
@@ -49,6 +55,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
secret_crypto,
runtime,
RequestRateLimiter::new(api_rate_limit),
std::sync::Arc::new(session_store),
);
let listener = TcpListener::bind(socket_addr).await?;
@@ -151,7 +158,7 @@ mod tests {
use tokio::time::sleep;
use tracing_subscriber::{filter::LevelFilter, fmt::MakeWriter, prelude::*};
use crate::app::build_app;
use crate::{app::build_app, session::InMemorySessionStore};
fn test_workspace_id() -> WorkspaceId {
WorkspaceId::new("ws_default")
@@ -223,6 +230,7 @@ mod tests {
SecretCrypto::new("test-master-key").unwrap(),
RuntimeExecutor::new(),
RequestRateLimiter::new(rate_limit_config),
std::sync::Arc::new(InMemorySessionStore::default()),
)
}