Skip to main content
Glama
mlsloynaz

mcp-sqlserver

by mlsloynaz

mcp-sqlserver

MCP server for Microsoft SQL Server with explicit port support. Works from Claude Code, Cursor, and CLI; default port is 9123 (override with MSSQL_PORT).

Why this exists

Generic mssql-mcp-server packages can fail when run from Claude Code with a custom port: connection works from the CLI but not when the client spawns the process. This server reads config from environment variables and passes port as a number into the driver so behavior is consistent everywhere.

Related MCP server: mssql-mcp

Requirements

  • Node.js 18+

  • SQL Server reachable via TCP (default port 9123, or set MSSQL_PORT)

  • For Windows Integrated Auth (current user, no password): npm install msnodesqlv8 (Windows native driver)

Setup

cd mcp-sqlserver
npm install
npm run build

Configuration

Option A: Connections map file (per environment / client)

Use a JSON file so each MCP server block only sets environment and client (and optionally the file path). One server (e.g. 192.168.100.65) can host multiple databases; each is a client with its own database name and credentials. You run one MCP server block per database (same server, different MSSQL_CLIENT).

File structure (e.g. connections.json): environment -> { server, port, encrypt?, trustServerCertificate?, windowsIntegrated?, clients: { clientName -> { database, user?, password?, domain?, windowsIntegrated? } } }. Server settings are shared; each client has database and either SQL credentials (user/password), NTLM (domain + user/password), or Windows Integrated (windowsIntegrated: true, no user/password).

Variable

Required

Description

MSSQL_ENVIRONMENT

When using file

Environment key (e.g. staging, prod)

MSSQL_CLIENT

When using file

Client key under clients (e.g. database name QASandbox8)

MSSQL_CONFIG_PATH

No

Path to the JSON file (default connections.json, resolved from current working directory)

If both MSSQL_ENVIRONMENT and MSSQL_CLIENT are set, the server loads the file, uses the environment’s server/port/encrypt/trustServerCertificate, and the client’s database and auth. Any of MSSQL_SERVER, MSSQL_PORT, MSSQL_DATABASE, MSSQL_USER, MSSQL_PASSWORD, MSSQL_DOMAIN, MSSQL_ENCRYPT, MSSQL_TRUST_CERT, MSSQL_WINDOWS_INTEGRATED in env override the file values.

Windows authentication

  • NTLM (domain user)
    In the client entry set domain with user and password (e.g. domain: "MYDOMAIN" for MYDOMAIN\myuser). Uses the default driver (tedious). Env override: MSSQL_DOMAIN.

  • Windows Integrated (current OS user)
    In the client entry set windowsIntegrated: true; omit user and password. Uses the msnodesqlv8 driver (Windows native). Install it with npm install msnodesqlv8. You can set windowsIntegrated: true at the environment level to apply to all clients, or per client. Env override: MSSQL_WINDOWS_INTEGRATED=true.

Example connections.example.json (copy to connections.json and fill in real values):

{
  "staging": {
    "server": "192.168.100.65",
    "port": 9123,
    "encrypt": true,
    "trustServerCertificate": true,
    "clients": {
      "QASandbox8": {
        "database": "QASandbox8",
        "user": "usrQASandbox8",
        "password": "your-password"
      },
      "OtherDatabase": {
        "database": "OtherDatabase",
        "user": "usrOtherDb",
        "password": "your-password"
      },
      "NTLM_Database": {
        "database": "MyDb",
        "domain": "MYDOMAIN",
        "user": "myuser",
        "password": "my-password"
      },
      "WindowsIntegratedDb": {
        "database": "TrustedDb",
        "windowsIntegrated": true
      }
    }
  }
}

Example MCP blocks: one per database on the same server (same staging server, different MSSQL_CLIENT):

"mssql-staging-qa": {
  "command": "node",
  "args": ["C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\dist\\index.js"],
  "env": {
    "MSSQL_ENVIRONMENT": "staging",
    "MSSQL_CLIENT": "QASandbox8",
    "MSSQL_CONFIG_PATH": "C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\connections.json"
  }
},
"mssql-staging-other": {
  "command": "node",
  "args": ["C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\dist\\index.js"],
  "env": {
    "MSSQL_ENVIRONMENT": "staging",
    "MSSQL_CLIENT": "OtherDatabase",
    "MSSQL_CONFIG_PATH": "C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\connections.json"
  }
}

Option B: Environment variables only

Variable

Required

Description

MSSQL_SERVER

Yes

Server host (e.g. 192.168.100.65)

MSSQL_PORT

No

Port (default 9123).

MSSQL_DATABASE

No

Database name (default master)

MSSQL_USER

Yes*

Login user (omit for Windows Integrated)

MSSQL_PASSWORD

Yes*

Login password (omit for Windows Integrated)

MSSQL_DOMAIN

No

NTLM domain (e.g. MYDOMAIN for domain\user)

MSSQL_WINDOWS_INTEGRATED

No

Set to true to use current Windows user (requires msnodesqlv8)

MSSQL_ENCRYPT

No

true or false (default false)

MSSQL_TRUST_CERT

No

Set to true for self-signed / dev (or use MSSQL_TRUST_SERVER_CERTIFICATE)

* Omit when using Windows Integrated auth (MSSQL_WINDOWS_INTEGRATED=true).

Claude Code / Cursor

Add your MCP server block under mcpServers in Claude Code or Cursor (e.g. SettingsMCP). Use one of these:

  • With a connections file (Option A) – Put connections.json next to the project (or set MSSQL_CONFIG_PATH). In the MCP config you only set environment, client, and path:

"mssql-staging-qa": {
  "command": "node",
  "args": ["C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\dist\\index.js"],
  "env": {
    "MSSQL_ENVIRONMENT": "staging",
    "MSSQL_CLIENT": "QASandbox8",
    "MSSQL_CONFIG_PATH": "C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\connections.json"
  }
}
  • Without a file (Option B) – Pass everything via env (server, port, database, user, password, etc.):

"mssql": {
  "command": "node",
  "args": ["C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\dist\\index.js"],
  "env": {
    "MSSQL_SERVER": "192.168.100.65",
    "MSSQL_PORT": "9123",
    "MSSQL_DATABASE": "QASandbox8",
    "MSSQL_USER": "usrQASandbox8",
    "MSSQL_PASSWORD": "your-password",
    "MSSQL_ENCRYPT": "true",
    "MSSQL_TRUST_CERT": "true"
  }
}

Replace args[0] with the absolute path to dist/index.js on your machine.

Tools

  • query – Run a read-only SQL query (e.g. SELECT ...). Returns results as a text table.

  • list_tables – List tables in the current database. Optional schema argument (e.g. dbo).

  • describe_table – Column names and types for a table. Arguments: table, optional schema (default dbo).

Run locally (stdio)

# Set env vars, then:
npm run start
# or without building:
npm run dev

The server speaks MCP over stdio; a client (Claude Code, Cursor, or another MCP client) must start it and connect to stdin/stdout.

License

MIT

Available Tools

3 tools
describe_tableB

Return column names and types for a table.

ParametersJSON Schema
NameRequiredDescriptionDefault
tableYesTable name (e.g. dbo.MyTable or MyTable)
schemaNoSchema name (e.g. dbo). Defaults to dbo if table has no schema prefix.

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool returns column names and types, which is helpful, but lacks details on error handling (e.g., if the table doesn't exist), performance characteristics, or output format. For a tool with no annotations, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero waste. It is front-loaded with the core purpose and efficiently conveys the essential information without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (metadata retrieval with 2 parameters) and no annotations or output schema, the description is minimally adequate. It covers the basic purpose but lacks details on behavior, error handling, and output structure, which are important for a tool without structured output documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, meaning the input schema fully documents the two parameters ('table' and 'schema') with descriptions. The description adds no additional parameter semantics beyond what the schema provides, such as examples or constraints. Baseline 3 is appropriate when the schema handles the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Return') and the resource ('column names and types for a table'), making the purpose unambiguous. However, it does not explicitly differentiate from sibling tools like 'list_tables' (which likely lists table names) or 'query' (which likely executes queries), though the distinction is somewhat implied by the specific focus on table metadata.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'list_tables' or 'query'. There is no mention of prerequisites, such as needing the table to exist, or any context for when this metadata retrieval is appropriate. Usage is implied only by the purpose statement.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_tablesA

List tables in the current database, optionally filtered by schema.

ParametersJSON Schema
NameRequiredDescriptionDefault
schemaNoSchema name (e.g. dbo). If omitted, all schemas are returned.

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It implies a read-only operation (listing) but does not disclose behavioral traits like pagination, rate limits, permissions required, or output format. The description adds basic context but lacks depth.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that is front-loaded with the core purpose and includes optional filtering. There is zero waste, and every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 optional parameter, no output schema, no annotations), the description is adequate but has clear gaps. It lacks details on output format, error handling, or behavioral context, which could be important for an agent to use it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the 'schema' parameter fully. The description adds no additional meaning beyond what the schema provides, such as examples or constraints. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('tables in the current database'), with specific scope ('optionally filtered by schema'). It distinguishes from sibling tools like 'describe_table' (detailed view) and 'query' (data retrieval).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides clear context for usage ('optionally filtered by schema'), but does not explicitly state when to use this tool versus alternatives like 'describe_table' or 'query'. No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

queryA

Execute a read-only SQL query (SELECT) against the configured SQL Server database.

ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYesSQL query to run (e.g. SELECT ...)

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively communicates the read-only nature and SQL Server context, but lacks details on error handling, performance implications, or result formatting. It adds value beyond basic purpose but does not fully cover behavioral traits like rate limits or authentication needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads key information (action, read-only nature, query type, and database). There is no wasted text, and every word contributes to understanding the tool's purpose and constraints.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (SQL query execution), no annotations, and no output schema, the description is adequate but has gaps. It covers the core purpose and read-only behavior, but lacks details on return values, error cases, or integration with sibling tools. It is complete enough for basic use but not fully comprehensive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the single parameter 'sql' well-documented in the schema. The description adds minimal semantic context by reinforcing the query type ('SELECT') and database target, but does not provide additional syntax or format details beyond what the schema already specifies. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Execute a read-only SQL query') and resource ('against the configured SQL Server database'), with explicit mention of 'SELECT' to distinguish it from potential write operations. It directly addresses what the tool does without being vague or tautological.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for usage by specifying 'read-only SQL query (SELECT)', which implies when to use this tool (for data retrieval) and when not to use it (for write operations like INSERT/UPDATE). However, it does not explicitly mention alternatives like sibling tools (describe_table, list_tables) or other query types, leaving some guidance implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

TDQS

A3.5/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose: describe_table provides metadata for a specific table, list_tables enumerates available tables, and query executes arbitrary SELECT queries. There is no overlap in functionality, and an agent can easily differentiate between them based on their descriptions.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (describe_table, list_tables, query). While 'query' is a single word, it functions as a verb in this context and maintains readability without deviating from the clear, descriptive naming style used throughout.

Tool Count3/5

With only 3 tools, the set feels thin for a SQL Server interface, which typically involves more operations like data manipulation (INSERT, UPDATE, DELETE) or schema modifications. However, the tools are well-scoped for read-only database interactions, making it borderline but not severely inadequate.

Completeness2/5

The tool surface is significantly incomplete for a SQL Server domain, as it only supports read operations (SELECT, metadata queries) without any write capabilities (INSERT, UPDATE, DELETE) or schema management tools. This creates notable gaps that could lead to agent failures when full database interactions are required.

Maintenance

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that enables connection to Microsoft SQL Server databases, providing tools for schema inspection and querying through standardized interfaces.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that enables interaction with Microsoft SQL Server instances using Windows or SQL Server authentication via native ODBC drivers. It allows users to execute SQL queries, list tables, and inspect schemas across multiple configured database environments through natural language.
    907
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Read-only SQL Server MCP server enabling safe database queries, table listing, and schema inspection with built-in security protections.
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    A read-only MCP server for exploring on-premises, multi-instance Microsoft SQL Server estates from AI clients, with read-only enforcement and Windows authentication support.
    Apache 2.0

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/mlsloynaz/mcp-sql-server'

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