UNPKG

@bluspace/mssql-mcp-server

Version:

Microsoft SQL Server MCP (Model Context Protocol) Server - AI-powered database interaction tool

30 lines (29 loc) 1.03 kB
import sql from 'mssql'; export async function initDb(cfg) { try { // Create connection configuration const config = { user: cfg.user, password: cfg.password, server: cfg.server, port: cfg.port, database: cfg.database, options: { trustServerCertificate: true, // For development only encrypt: true, }, }; // Connect using the pool const pool = new sql.ConnectionPool(config); await pool.connect(); // Test the connection await pool.request().query('SELECT 1 as test'); // SQL Server doesn't support setting read-only at the connection level as easily as PostgreSQL // For read-only permissions, we'll enforce this in the query functions return pool; } catch (error) { console.error("Database connection error:", error); throw new Error(`Failed to connect to SQL Server: ${error.message}`); } }