Skip to main content
Glama
c0h1b4
by c0h1b4
README.md
# MSSQL MCP Server

[![smithery badge](https://smithery.ai/badge/@c0h1b4/mssql-mcp-server)](https://smithery.ai/server/@c0h1b4/mssql-mcp-server)

A Model Context Protocol (MCP) server for connecting to Microsoft SQL Server databases. This server provides tools for executing SQL queries and managing database connections.

**Version Notice:** This project has been upgraded to use Model Context Protocol SDK 1.9.0. See [UPGRADE.md](UPGRADE.md) for details.

## Installation

### Installing via Smithery

To install MSSQL MCP Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@c0h1b4/mssql-mcp-server):

```bash
npx -y @smithery/cli install @c0h1b4/mssql-mcp-server --client claude
```

### Manual Installation
```bash
npm install mssql-mcp-server
```

## Usage

Add the server to your MCP settings configuration file:

```json
{
  "mcpServers": {
    "mssql": {
      "command": "mssql-mcp-server",
      "env": {
        "MSSQL_CONNECTION_STRING": "Server=localhost;Database=master;User Id=sa;Password=yourpassword;",
        // Or individual connection parameters:
        "MSSQL_HOST": "localhost",
        "MSSQL_PORT": "1433",
        "MSSQL_DATABASE": "master",
        "MSSQL_USER": "sa",
        "MSSQL_PASSWORD": "yourpassword",
        "MSSQL_ENCRYPT": "false",
        "MSSQL_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}
```

## Tools

### query

Execute a SQL query on a MSSQL database.

#### Parameters

- `connectionString` (string, optional): Full connection string (alternative to individual parameters)
- `host` (string, optional): Database server hostname
- `port` (number, optional): Database server port (default: 1433)
- `database` (string, optional): Database name (default: master)
- `username` (string, optional): Database username
- `password` (string, optional): Database password
- `query` (string, required): SQL query to execute
- `encrypt` (boolean, optional): Enable encryption (default: false)
- `trustServerCertificate` (boolean, optional): Trust server certificate (default: true)

Either `connectionString` OR (`host` + `username` + `password`) must be provided.

#### Example

```typescript
const result = await use_mcp_tool({
  server_name: 'mssql',
  tool_name: 'query',
  arguments: {
    host: 'localhost',
    username: 'sa',
    password: 'yourpassword',
    query: 'SELECT * FROM Users',
  },
});
```

## Running the Server

### Local Development

```bash
# Install dependencies
npm install

# Run in development mode
npm run dev

# Build
npm run build

# Run the built server
npm start
```

### Using Docker

```bash
# Build and start services (SQL Server + MCP server)
docker-compose up

# Or just build the Docker image
docker build -t mssql-mcp-server .
```

## Testing

```bash
# Run tests
npm test

# Run tests with coverage
npm run test:coverage
```

## Running evals

The evals package loads an mcp client that then runs the index.ts file, so there is no need to rebuild between tests. You can load environment variables by prefixing the npx command. Full documentation can be found [here](https://www.mcpevals.io/docs).

```bash
OPENAI_API_KEY=your-key  npx mcp-eval src/evals/evals.ts examples/simple-server.ts
```

## Security

The server includes safeguards against dangerous SQL operations:

- Blocks potentially harmful commands like DROP, TRUNCATE, ALTER, CREATE, EXEC, etc.
- Validates all input parameters and database names
- Sets reasonable limits on query length and timeout
- Uses connection pooling for better performance and security

## License

MIT

[![MSSQL MCP Server on AI Agents Listing](https://aiagentslisting.com/mssql-mcp-server-3/badge.svg?claim=3c337448993248a3b4a769767a87d692)](https://aiagentslisting.com/mcp/mssql-mcp-server-3)

TDQS

B3.4/5.0

Scored across 33 tools

Disambiguation4/5

Most tools have distinct purposes targeting specific database objects or analysis tasks, with clear boundaries. However, some overlap exists: get_stored_procedure_definition, get_multiple_stored_procedure_definitions, and get_all_stored_procedure_definitions could be confused as they all retrieve stored procedure definitions, differing only in scope. Similarly, describe_stored_procedure overlaps with these but focuses on metadata rather than full definitions.

Naming Consistency5/5

Tool names follow a highly consistent verb_noun pattern throughout, using snake_case uniformly. Verbs like analyze_, describe_, find_, get_, list_, and sample_ are applied predictably across related tools, making the set easy to navigate and understand. There are no deviations in naming conventions.

Tool Count3/5

With 33 tools, the count is borderline high for a database analysis server, potentially overwhelming for agents. While the tools cover many aspects of SQL Server analysis, some could be consolidated (e.g., multiple stored procedure definition tools) to reduce complexity. It feels heavy but not extreme, given the broad scope of database introspection.

Completeness5/5

The tool set provides comprehensive coverage for database analysis and introspection, including listing objects, describing schemas, analyzing performance and data patterns, and executing queries. There are no obvious gaps; it supports full lifecycle tasks from connection testing to detailed metadata exploration, ensuring agents can perform thorough database investigations without dead ends.

Maintenance

ActivityMaintained
ResponsivenessNo issues