npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mcp-mssql-server

v1.0.2

Published

MCP server for MS SQL Server database queries

Downloads

60

Readme

mcp-mssql-server

A Model Context Protocol (MCP) server that provides a standardized interface for AI models to interact with MS SQL Server databases. This server implements the MCP specification to enable seamless database operations through a consistent API.

Features

  • Execute SQL queries with parameter support
  • List all tables in the database
  • Describe table schemas
  • Support for both stdio and HTTP transport modes
  • Comprehensive logging system
  • Environment-based configuration
  • Error handling and graceful shutdown

Prerequisites

  • Node.js (version that supports ES modules)
  • MS SQL Server instance
  • Access credentials for the database

Installation

  1. Clone the repository
  2. Install dependencies:
npm install

You can also install the package globally:

npm install -g mcp-mssql-server
  1. Create a .env file in the project root with the following required variables:
DB_SERVER=your_server_address
DB_USER=your_username
DB_PASSWORD=your_password
DB_DATABASE_NAME=your_database_name

Usage

The server can be started in two different transport modes:

stdio Mode (Default)

npm start
# or
npm run start:stdio

HTTP Mode

npm run start:http

Development Mode

npm run dev

JSON-RPC Protocol

The server implements the JSON-RPC 2.0 protocol with the following key methods:

  1. initialize - Initialize the server connection:
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2024-11-05",
    "capabilities": {
      "tools": {}
    },
    "clientInfo": {
      "name": "your-client",
      "version": "1.0.0"
    }
  }
}
  1. tools/list - List available tools
  2. tools/call - Call a specific tool

Testing

The package includes a test client (test.package.js) that demonstrates how to interact with the MCP server:

node test.package.js

The test client implements an MCPTestClient class that:

  • Spawns a server process using npx mcp-mssql-server
  • Initializes the connection with protocol version '2024-11-05'
  • Lists available tools
  • Executes sample queries including:
    • Listing all tables
    • Running a specific SQL query to count documents
  • Handles server responses and errors through stdio streams
  • Includes proper error handling and process cleanup

Example test query from the client:

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "execute_sql_query",
    "arguments": {
      "query": "SELECT COUNT(*) as document_count FROM document_new"
    }
  }
}

The test client provides a simple way to verify the server's functionality and can serve as a reference for implementing your own client.

Available Tools

The server provides the following MCP tools:

1. execute_sql_query

Execute SQL queries against the database with optional parameterization.

{
  "query": "SELECT * FROM Users WHERE id = @userId",
  "parameters": [
    {
      "name": "userId",
      "type": "int",
      "value": 1
    }
  ]
}

2. list_tables

List all available tables in the connected database.

3. describe_table

Get detailed schema information for a specific table.

{
  "table_name": "Users"
}

Logging

Logs are stored in the logs directory:

  • error.log: Error-level logs
  • combined.log: All logs

In HTTP mode, logs are also output to the console.

Dependencies

Main dependencies:

  • @modelcontextprotocol/sdk: ^1.13.0
  • dotenv: ^16.4.5
  • express: ^5.1.0
  • mssql: ^11.0.1
  • winston: ^3.11.0

Development dependencies:

  • axios: ^1.10.0

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request