Skip to main content
Glama
techybolek

MCP MS SQL Server

by techybolek

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

Related MCP server: MSSQL Database MCP Server

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

Available Tools

3 tools
describe_tableB

Get the schema information for a specific table

ParametersJSON Schema
NameRequiredDescriptionDefault
table_nameYesThe name of the table to describe

TDQS

B3/5.0
Behavior2/5

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

With no annotations, the description must fully convey behavior. It states 'Get schema information' but omits details on what that includes (e.g., columns, types, constraints), required permissions, or side effects. Read-only nature is implied but not explicit.

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

Conciseness3/5

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

The description is a single short sentence, which is concise but lacks structure. It could be considered under-specified, but it avoids verbosity.

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

Completeness2/5

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

No output schema is provided, and annotations are absent. The description does not explain the return value (e.g., schema format), leaving a gap in completeness for a tool with a single required parameter.

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 parameter 'table_name' is fully documented in the schema. The description adds no additional semantic depth, meeting the baseline.

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?

Describes the tool as retrieving schema information for a specific table, with a clear verb and resource. It distinguishes from siblings like list_tables (which likely only returns table names) and execute_sql_query (which runs arbitrary SQL).

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?

No guidance on when to use this tool versus alternatives. The description does not mention exclusions or context for typical usage, leaving the agent to infer.

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

execute_sql_queryC

Execute a SQL query against the MS SQL Server database

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query to execute
parametersNoOptional parameters for prepared statements

TDQS

C2.7/5.0
Behavior2/5

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

Without annotations, the description carries the full burden of disclosing behavioral traits. It only says 'execute', which implies both read and write operations, but does not mention side effects, transaction safety, error behavior, or permissions. This is insufficient for a powerful SQL execution tool.

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

Conciseness3/5

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

The description is a single sentence with no unnecessary words, but it is overly terse for a tool that executes arbitrary SQL. It could include essential context without being verbose, so it is acceptable but not excellent.

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

Completeness1/5

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

Given the complexity of SQL execution (potential for data modification, no output schema, no annotations), the description is woefully incomplete. It lacks information on return values, error handling, query types allowed, and safety considerations.

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 input schema provides descriptions for both parameters (query and parameters), achieving 100% schema description coverage. The description adds no further meaning beyond the schema, so a baseline score of 3 is appropriate.

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 verb 'Execute' and the resource 'SQL query against the MS SQL Server database', making the purpose clear. However, it does not distinguish itself from sibling tools like describe_table or list_tables, but the action is fundamentally different so no explicit differentiation is critical.

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?

No guidance is provided on when to use this tool versus alternatives, nor any caution about using SQL queries that modify data. The description lacks any contextual advice that would help an agent decide when this tool is appropriate.

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

list_tablesA

List all tables in the database

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.3/5.0
Behavior3/5

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

With no annotations, the description carries the full burden. It discloses that the tool is read-only ('list') but does not mention any performance considerations, permissions, or result format. However, for a simple list tool with no parameters, this is minimally adequate.

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 sentence that precisely states the action without any extraneous words. It is front-loaded and every word earns its place.

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

Completeness5/5

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

Given the tool has no parameters, no output schema, and no annotations, the description is complete. It fully describes the tool's function without missing critical aspects.

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

Parameters4/5

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

There are no parameters, so the schema coverage is 100%. The description does not need to add parameter meaning. A baseline of 4 is appropriate as it adds no extra param info but is not required.

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 it lists all tables in the database. It uses a specific verb ('list') and resource ('tables'), and implicitly distinguishes from siblings like describe_table (which describes a specific table) and execute_sql_query (which runs queries).

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 implies usage context (when you need a full list of tables) and sibling names provide additional context. While it doesn't explicitly state when not to use it, the use case is clear for a simple list operation.

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 clear, distinct purpose: listing tables, describing a table's schema, and executing arbitrary SQL queries. There is no overlap or ambiguity.

Naming Consistency5/5

All tool names follow a consistent snake_case verb_noun pattern: list_tables, describe_table, execute_sql_query. No deviations.

Tool Count5/5

Three tools is minimal but well-scoped for a simple database interface covering exploration and querying. It avoids unnecessary complexity.

Completeness3/5

The set lacks explicit tools for DDL (create/alter/drop), DML (insert/update/delete), or transaction control, but the execute_sql_query tool can compensate. Notable gaps exist but are workable.

Maintenance

ActivityInactive
ResponsivenessNo issues

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
    A
    quality
    C
    maintenance
    Enables AI assistants to interact with Microsoft SQL Server databases through query execution, schema discovery, CRUD operations, stored procedures, and data export with built-in safety controls.
    18
    Apache 2.0
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to securely interact with Microsoft SQL Server databases to query data, inspect schemas, and retrieve metadata with read-only operations by default and optional write capabilities.
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to interact with Microsoft SQL Server databases through a standardized interface. Supports executing SQL queries, browsing database schemas, and viewing table data with flexible authentication options for both local and Azure SQL databases.
    5
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides direct SQL query access to Microsoft SQL Server databases with full CRUD operations, enabling AI assistants to execute queries, modify data, and manage database objects through a simplified interface.

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/techybolek/mcp_sql_server2'

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