MCP SQL Server

MCP SQL Server

A Model Context Protocol server that allows Large Language Models like Claude to execute SQL queries, explore database schemas, and maintain persistent connections to SQL Server databases.

Category
访问服务器

README

MCP SQL Server

This is a Model Context Protocol (MCP) server for SQL Server interactions. It allows Large Language Models (LLMs) like Claude to execute SQL queries, explore database schema, and maintain persistent connections across multiple requests.

Features

  • SQL Query Execution: Run SELECT queries against SQL Server databases
  • Stored Procedure Support: Execute stored procedures with parameters
  • Schema Exploration: View database table and column definitions
  • Session Persistence: Maintains SQL connections between queries for temporary tables and multi-query operations
  • Docker Ready: Simple deployment with Docker

Quick Start

Using Docker (Recommended)

# Clone the repository
git clone https://github.com/JubinSaniei/mcp-mssql
cd mcp-mssql

# Start the container with your SQL Server connection details
./docker-run.sh 192.168.1.100 YourSecurePassword

# Test the connection and session persistence
./test-mcp.sh
./test-session-persistence.sh

For complete Docker setup instructions, see the Docker README.

Configuration

The server supports the following environment variables:

Category Variable Description Default
Connection SQL_SERVER SQL Server hostname or IP 172.31.64.1
SQL_PORT SQL Server port 1433
SQL_USER SQL Server username sa
SQL_PASSWORD SQL Server password Required
SQL_DATABASE Database name ''
Security SQL_ENCRYPT Enable encryption true
SQL_TRUST_SERVER_CERT Trust server certificate true
Timeouts SQL_CONNECTION_TIMEOUT Connection timeout (ms) 30000
SQL_REQUEST_TIMEOUT Request timeout (ms) 30000
Connection Pool SQL_POOL_MAX Max connections in pool 10
SQL_POOL_MIN Min connections in pool 0
SQL_POOL_IDLE_TIMEOUT Idle timeout for pool (ms) 30000

Using with Claude

To add this MCP server to Claude CLI:

# Add the MCP server using the config file
claude mcp add-json mssql-mcp "$(cat claude-mcp-config.json)"

# To add it globally
claude mcp add-json -s user mssql-mcp "$(cat claude-mcp-config.json)"

# Start a conversation with Claude using this MCP
claude mcp mssql-mcp

In the Claude conversation, you can:

  1. Execute queries:

    <mcp:execute_query>
    SELECT TOP 10 * FROM YourTable
    </mcp:execute_query>
    
  2. Execute stored procedures:

    <mcp:execute_StoredProcedure>
    {
      "procedure": "sp_tables",
      "parameters": []
    }
    </mcp:execute_StoredProcedure>
    
  3. Explore database schema:

    <mcp:schema>
    YourDatabaseName
    </mcp:schema>
    

Session Persistence

This MCP server implements session persistence for SQL connections, which allows:

  • Creating and using temporary tables across multiple queries
  • Maintaining variables and session state
  • Persistent transactions (though exercise caution with long-running transactions)
  • Better performance without reconnecting

The session persistence is handled automatically - Claude will maintain the same database connection throughout a single conversation.

Development

Local Development Setup

# Install dependencies
npm install

# Run the server directly (requires environment variables to be set)
npm start

# Run with TypeScript compiler watching for changes
npm run dev

Testing

# Test basic query functionality
./test-query.sh

# Test session persistence (requires Docker)
./test-session-persistence.sh

Security Notes

  • The server only allows SELECT queries (no INSERT, UPDATE, DELETE, etc.)
  • System and extended stored procedures (sp_, xp_) are blocked
  • SQL injection protection is implemented for database names and parameters

Troubleshooting

If you encounter issues:

  1. Check container logs: docker logs mssql-mcp
  2. Verify SQL Server connection: ./test-mcp.sh
  3. Test session persistence: ./test-session-persistence.sh
  4. Ensure the SQL_PASSWORD environment variable is correctly set

For detailed troubleshooting steps, see the Docker README.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选