SPIP SQL MCP Server
Provides read-only Microsoft SQL Server database access to AI agents with row-level security, enabling SELECT queries, table metadata, and schema introspection through MCP.
README
๐๏ธ SPIP System - SQL Server Model Context Protocol (MCP) Server
Part of the SPIP (Smart Procurement & Invoice Processing) Ecosystem.
A production-ready Model Context Protocol (MCP) Server for Microsoft SQL Server built with Node.js and TypeScript. This server exposes 5 read-only database tools to AI Agents (execute_select, list_tables, describe_table, get_relationships, get_database_info) while enforcing database kernel-level Row-Level Security (RLS) using atomic SQL batch execution.
โจ Key Features
- Model Context Protocol (MCP) Compliance: Standard SSE transport and direct HTTP tool execution APIs using
@modelcontextprotocol/sdk. - Atomic Session Context & Row-Level Security (RLS): Combines
sp_set_session_contextwithSELECTqueries in a single atomic SQL batch execution, guaranteeing same-connection RLS isolation for multi-tenant users. - AST SQL Query Validation: Restricts query execution strictly to read-only
SELECTstatements, blockingINSERT,UPDATE,DELETE,DROP, or DDL operations. - 5 Built-In Tools:
execute_select: Runs validated SELECT queries with dynamic RLS user context (userId).list_tables: Returns all database table names and schemas.describe_table: Returns column names, data types, primary keys, and nullability for a table.get_relationships: Returns foreign key relationships between database tables.get_database_info: Returns database version and metadata overview.
๐ ๏ธ Tech Stack
- Runtime: Node.js v20+ / v22+
- Language: TypeScript
- Framework: Express.js
- SDK:
@modelcontextprotocol/sdk - Database Driver:
node-mssql(Microsoft SQL Server 2019/2022)
๐ Quick Start (Without Docker)
1. Installation
git clone https://github.com/MahmoudNour2003/spip-sql-mcp-server.git
cd spip-sql-mcp-server
npm install
2. Environment Setup (.env)
Create a .env file in the project root:
MCP_PORT=3001
DB_HOST=127.0.0.1
DB_PORT=1433
DB_NAME=SPIP_DB
DB_USER=AI_CHAT
DB_PASSWORD=AI@123
DB_ENCRYPT=false
DB_TRUST_SERVER_CERT=true
3. Build & Run
# Build TypeScript to JavaScript
npm run build
# Start the MCP Server
node dist/server.js
๐งช Testing & Verification
Run the built-in standalone test suite:
node dist/standalone-test.js
Expected Output:
โ
Successfully connected to SQL Server (SPIP_DB)!
Tables count: 41
๐ Row-Level Security (RLS) Execution Details
When execute_select is called with a userId parameter (e.g. userId = 5), the MCP Server executes the following atomic batch query:
EXEC sp_set_session_context @key = N'UserId', @value = 5;
SELECT TOP 1000 Id, InvoiceNumber, TotalAmount, Status FROM dbo.Invoices ORDER BY InvoiceDate DESC;
SQL Server Security Policies (Security.InvoiceSecurityPolicy) intercept the query and return only the rows belonging to User 5.
๐ License
MIT License
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.