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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ggball/mcp-sqlserver

v1.0.0

Published

SQL Server MCP Server - Connect and query Microsoft SQL Server databases via MCP

Readme

SQL Server MCP Server (Node.js/TypeScript)

A Model Context Protocol (MCP) server for connecting to and querying Microsoft SQL Server databases, built with TypeScript and Node.js.

What is MCP?

MCP (Model Context Protocol) is an open protocol that allows AI assistants to securely and standardly interact with external data sources and tools. Through MCP servers, AI assistants can:

  • Directly connect to databases to execute queries
  • Call external APIs to get real-time data
  • Access file systems and cloud storage
  • Execute custom business logic

MCP architecture contains two core components:

  • MCP Client: Built into AI assistants (like Claude Desktop), responsible for communicating with servers
  • MCP Server: Independent processes that provide specific tools and data access capabilities

Features

  • List all available databases
  • List all tables in a specific database
  • Get table structure information (columns, data types, primary keys, etc.)
  • Execute safe SELECT queries (limited to 1000 rows)
  • Get table index information
  • Get table statistics (row count, size, etc.)
  • Connection pool management for improved performance

Installation

Via npm (Global Installation)

npm install -g @ggball/mcp-sqlserver

After global installation, the mcp-sqlserver command will be available system-wide.

Via npx (Without Installation)

npx @ggball/mcp-sqlserver

From Source

1. System Requirements

  • Node.js 18.0.0 or higher
  • npm 9.0.0 or higher
  • SQL Server (any version)

2. Install Dependencies

npm install

3. Build the Project

npm run build

Configuration

Environment Variables

Create a .env file or set the following environment variables:

| Environment Variable | Description | Default Value | |---------------------|-------------|---------------| | SQLSERVER_HOST | Server address | localhost | | SQLSERVER_PORT | Port number | 1433 | | SQLSERVER_USER | Username | sa | | SQLSERVER_PASSWORD | Password | (empty) | | SQLSERVER_DATABASE | Default database | master | | SQLSERVER_ENCRYPT | Enable encryption | true | | SQLSERVER_TRUST_SERVER_CERTIFICATE | Trust server certificate | true |

Example .env File

SQLSERVER_HOST=localhost
SQLSERVER_PORT=1433
SQLSERVER_USER=sa
SQLSERVER_PASSWORD=YourPassword123
SQLSERVER_DATABASE=MyDatabase

Usage

Running the Server

npm start

Or for development with auto-rebuild:

npm run dev

Configuration in Claude Desktop

Config File Location

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

Option 1: Using Global Installation (Recommended)

If you installed the package globally:

{
  "mcpServers": {
    "sqlserver": {
      "command": "mcp-sqlserver",
      "env": {
        "SQLSERVER_HOST": "localhost",
        "SQLSERVER_PORT": "1433",
        "SQLSERVER_USER": "sa",
        "SQLSERVER_PASSWORD": "YourPassword123",
        "SQLSERVER_DATABASE": "MyDatabase"
      }
    }
  }
}

Option 2: Using npx

{
  "mcpServers": {
    "sqlserver": {
      "command": "npx",
      "args": ["@ggball/mcp-sqlserver"],
      "env": {
        "SQLSERVER_HOST": "localhost",
        "SQLSERVER_PORT": "1433",
        "SQLSERVER_USER": "sa",
        "SQLSERVER_PASSWORD": "YourPassword123",
        "SQLSERVER_DATABASE": "MyDatabase"
      }
    }
  }
}

Option 3: From Source

{
  "mcpServers": {
    "sqlserver": {
      "command": "node",
      "args": ["/path/to/mcp-sqlserver-npm/dist/index.js"],
      "env": {
        "SQLSERVER_HOST": "localhost",
        "SQLSERVER_PORT": "1433",
        "SQLSERVER_USER": "sa",
        "SQLSERVER_PASSWORD": "YourPassword123",
        "SQLSERVER_DATABASE": "MyDatabase"
      }
    }
  }
}

Restart Claude Desktop after configuration.

Configuration in Claude Code

Config File Location

  • macOS/Linux: ~/.config/claude-code/config.json
  • Windows: %APPDATA%\claude-code\config.json

Option 1: Using Global Installation (Recommended)

{
  "mcpServers": {
    "sqlserver": {
      "command": "mcp-sqlserver",
      "env": {
        "SQLSERVER_HOST": "localhost",
        "SQLSERVER_PORT": "1433",
        "SQLSERVER_USER": "sa",
        "SQLSERVER_PASSWORD": "YourPassword123",
        "SQLSERVER_DATABASE": "MyDatabase"
      }
    }
  }
}

Option 2: Using npx

{
  "mcpServers": {
    "sqlserver": {
      "command": "npx",
      "args": ["@ggball/mcp-sqlserver"],
      "env": {
        "SQLSERVER_HOST": "localhost",
        "SQLSERVER_PORT": "1433",
        "SQLSERVER_USER": "sa",
        "SQLSERVER_PASSWORD": "YourPassword123",
        "SQLSERVER_DATABASE": "MyDatabase"
      }
    }
  }
}

Option 3: From Source

{
  "mcpServers": {
    "sqlserver": {
      "command": "node",
      "args": ["/path/to/mcp-sqlserver-npm/dist/index.js"],
      "env": {
        "SQLSERVER_HOST": "localhost",
        "SQLSERVER_PORT": "1433",
        "SQLSERVER_USER": "sa",
        "SQLSERVER_PASSWORD": "YourPassword123",
        "SQLSERVER_DATABASE": "MyDatabase"
      }
    }
  }
}

Restart Claude Code after configuration.

Available Tools

1. list_databases

Lists all SQL Server databases (excluding system databases).

Tool name: list_databases
Parameters: None

Example:

List all available databases

2. list_tables

Lists all tables in a specific database.

Tool name: list_tables
Parameters:
  - database (required): Database name
  - schema (optional): Schema name, defaults to "dbo"

Example:

List all tables in MyDatabase

3. describe_table

Gets table structure information including columns, data types, nullable, primary keys, etc.

Tool name: describe_table
Parameters:
  - database (required): Database name
  - table (required): Table name
  - schema (optional): Schema name, defaults to "dbo"

Example:

Show the structure of the Users table in MyDatabase

4. execute_query

Executes SQL SELECT queries (only SELECT and WITH allowed, limited to 1000 rows).

Tool name: execute_query
Parameters:
  - query (required): SQL query statement
  - database (optional): Database name, defaults to configured database

Example:

Query users older than 18 from the Users table

5. get_table_indexes

Gets index information for a table.

Tool name: get_table_indexes
Parameters:
  - database (required): Database name
  - table (required): Table name
  - schema (optional): Schema name, defaults to "dbo"

Example:

Get index information for the Users table

6. get_table_stats

Gets table statistics including row count and storage size.

Tool name: get_table_stats
Parameters:
  - database (required): Database name
  - table (required): Table name
  - schema (optional): Schema name, defaults to "dbo"

Example:

Get statistics for the Users table

Usage Examples

Scenario 1: Explore Database

You: List all available databases
Claude: [calls list_databases] ...

You: Show what tables are in MyDatabase
Claude: [calls list_tables] ...

Scenario 2: Query Data

You: Query the last 10 orders from Orders table
Claude: [calls describe_table to understand table structure]
      [calls execute_query to perform query] ...

Scenario 3: Analyze Table Structure

You: Analyze the structure and indexes of Users table
Claude: [calls describe_table]
      [calls get_table_indexes]
      [calls get_table_stats] ...

Security Notes

  • execute_query tool only allows SELECT and WITH queries
  • Automatically blocks statements containing dangerous keywords (DROP, DELETE, UPDATE, etc.)
  • Query results are limited to 1000 rows

Development

Project Structure

mcp-sqlserver-npm/
├── src/
│   ├── index.ts       # Main server entry point
│   ├── config.ts      # Configuration management
│   └── connection.ts  # Connection pool implementation
├── dist/              # Compiled output
├── package.json
├── tsconfig.json
└── README.md

Scripts

  • npm run build - Compile TypeScript
  • npm run dev - Compile and run in development mode
  • npm start - Run the compiled server
  • npm run watch - Watch mode for TypeScript compilation

Dependencies

  • @modelcontextprotocol/sdk - Official MCP SDK for TypeScript
  • tedious - SQL Server connector for Node.js
  • zod - Schema validation
  • dotenv - Environment variable management

License

MIT License

Sources