Skip to main content
Glama

SQL Server MCP Service

by vini-cius
database.tsโ€ข1.68 kB
import sql from 'mssql' import { env } from './env' export class DatabaseConnection { private pool: sql.ConnectionPool | null = null private config: sql.config constructor(config: sql.config) { this.config = config } async connect(): Promise<void> { if (this.pool && this.pool.connected) return this.pool = new sql.ConnectionPool(this.config) await this.pool.connect() } async disconnect(): Promise<void> { if (this.pool) { await this.pool.close() this.pool = null } } getPool(): sql.ConnectionPool { if (!this.pool) { throw new Error('Database connection not initialized') } return this.pool } isConnected(): boolean { return this.pool?.connected ?? false } async healthCheck() { if (!this.pool) { throw new Error('Pool not initialized') } const request = this.pool.request() const result = await request.query('SELECT 1 as health') return { status: 'healthy', database: this.config.database, timestamp: new Date().toISOString(), connections: this.pool.size, result: result.recordset, } } } export function createDatabaseConfig(): sql.config { return { server: env.SQL_SERVER || 'localhost', database: env.SQL_DATABASE || 'master', user: env.SQL_USER, password: env.SQL_PASSWORD, port: env.SQL_PORT, pool: { min: 5, max: 50, idleTimeoutMillis: 1000 * 60 * 5, acquireTimeoutMillis: 1000 * 10, }, options: { enableArithAbort: true, trustServerCertificate: env.SQL_TRUST_CERT, encrypt: env.SQL_ENCRYPT, appName: 'sqlserver-mcp', }, } }

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/vini-cius/mcp-sqlserver'

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