DB Analyzer MCP Server

DB Analyzer MCP Server

Enables AI assistants to analyze and query SQL Server databases, including schema discovery, health checks, and data retrieval.

Category
访问服务器

README

DB Analyzer MCP Server

A Model Context Protocol (MCP) server that provides comprehensive SQL Server database analysis and query capabilities for AI assistants like Claude.

Features

This MCP server exposes 10 powerful tools for database analysis and management:

Connection & Testing

  • ping_db - Test database connectivity and retrieve server information

Query Execution

  • execute_query - Execute SELECT queries with optional row limits
  • execute_non_query - Execute DDL/DML statements (CREATE, UPDATE, DELETE, etc.)
  • execute_stored_procedure - Call stored procedures with typed parameters

Schema Discovery

  • list_databases - List all databases with optional name filtering
  • list_schemas - List schemas in a specific database
  • list_tables - List tables with optional schema/name filtering
  • get_table_columns - Get detailed column information including types, constraints, and primary keys
  • get_indexes - Retrieve index information for specific tables

Health Analysis

  • analyze_schema_health - Comprehensive database health check including:
    • Tables without clustered indexes (heaps)
    • Tables missing primary keys
    • Usage of deprecated data types (text, ntext, image, sql_variant)
    • Wide tables (configurable column threshold)
    • Unused indexes based on usage statistics
    • Missing index suggestions from SQL Server DMVs
    • Fragmented indexes (>30% fragmentation, >1000 pages)

Installation

Prerequisites

  • Node.js (v18 or higher recommended)
  • Access to a SQL Server instance
  • npm or yarn package manager

Setup

  1. Clone the repository:

    git clone https://dev.azure.com/goplanet-west/West%20AI/_git/mcp-db-analyzer
    cd mcp-db-analyzer
    
  2. Install dependencies:

    npm install
    
  3. Build the project:

    npm run build
    

Configuration

Environment Variables

The server supports the following environment variables for database connection:

Variable Description Default
DB_HOST SQL Server hostname <database-hostname>
DB_USER Database username <database-user>
DB_PASSWORD Database password <database-password>
DB_DATABASE Default database (optional) None
DB_PORT SQL Server port 1433
DB_ENCRYPT Enable connection encryption true
DB_TRUST_SERVER_CERT Trust server certificate true
DB_POOL_MAX Maximum connection pool size 10

MCP Client Configuration

Claude Desktop

Add the following to your Claude Desktop configuration file:

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

{
  "mcpServers": {
    "db-analyzer": {
      "command": "node",
      "args": ["C:\\MCP-Servers\\db-analyzer\\build\\index.js"],
      "env": {
        "DB_HOST": "your-server.database.windows.net",
        "DB_USER": "your-username",
        "DB_PASSWORD": "your-password",
        "DB_PORT": "1433",
        "DB_ENCRYPT": "true",
        "DB_TRUST_SERVER_CERT": "false"
      }
    }
  }
}

Cline (VS Code Extension)

Add to your Cline MCP settings:

{
  "mcpServers": {
    "db-analyzer": {
      "command": "node",
      "args": ["C:\\MCP-Servers\\db-analyzer\\build\\index.js"],
      "env": {
        "DB_HOST": "your-server.database.windows.net",
        "DB_USER": "your-username",
        "DB_PASSWORD": "your-password"
      }
    }
  }
}

Visual Studio Code (GitHub Copilot)

VS Code supports MCP servers natively through GitHub Copilot's Agent mode (VS Code 1.99+).

Option 1 — Workspace configuration (checked into source control, applies to everyone opening this project):

Create or edit .vscode/mcp.json in your project root:

{
  "servers": {
    "db-analyzer": {
      "command": "node",
      "args": ["C:\\MCP-Servers\\db-analyzer\\build\\index.js"],
      "env": {
        "DB_HOST": "your-server.database.windows.net",
        "DB_USER": "your-username",
        "DB_PASSWORD": "your-password",
        "DB_PORT": "1433",
        "DB_ENCRYPT": "true",
        "DB_TRUST_SERVER_CERT": "false"
      }
    }
  }
}

Option 2 — User settings (applies to all your VS Code projects):

Open your user settings.json (<kbd>Ctrl/Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> → Preferences: Open User Settings (JSON)) and add:

{
  "mcp": {
    "servers": {
      "db-analyzer": {
        "command": "node",
        "args": ["C:\\MCP-Servers\\db-analyzer\\build\\index.js"],
        "env": {
          "DB_HOST": "your-server.database.windows.net",
          "DB_USER": "your-username",
          "DB_PASSWORD": "your-password",
          "DB_PORT": "1433",
          "DB_ENCRYPT": "true",
          "DB_TRUST_SERVER_CERT": "false"
        }
      }
    }
  }
}

Activating the server:

  1. Open the Copilot Chat panel (<kbd>Ctrl/Cmd</kbd>+<kbd>Alt</kbd>+<kbd>I</kbd>)
  2. Switch to Agent mode using the mode selector at the bottom of the chat input
  3. Click the Tools button (⚙) to verify db-analyzer appears in the tool list
  4. Start chatting — Copilot will automatically invoke the MCP tools as needed

Note: If the server doesn't appear, run MCP: List Servers from the Command Palette to refresh, and check the output panel for errors.

Other MCP Clients

For other MCP-compatible clients (Cursor, Continue, etc.), refer to their documentation for adding custom MCP servers. The general pattern is:

  • Command: node (or full path to Node.js)
  • Arguments: Path to build/index.js
  • Environment: Database connection variables

Usage Examples

Once connected to an MCP client, you can use natural language to interact with your database:

Example Prompts

Connection Testing:

"Test the database connection and show me the server version"

Schema Discovery:

"Show me all databases on this server"
"List all tables in the dbo schema"
"What are the columns in the Users table?"

Data Querying:

"Get the first 10 rows from the Orders table"
"Show me all customers from California"

Health Analysis:

"Analyze the database for potential issues"
"Find all tables without primary keys"
"Show me any fragmented indexes"

Development

Project Structure

db-analyzer/
├── src/
│   └── index.ts           # Main server implementation
├── build/                 # Compiled JavaScript (generated)
├── node_modules/          # Dependencies (generated)
├── package.json           # Project metadata and dependencies
├── tsconfig.json          # TypeScript configuration
├── .gitignore            # Git ignore rules
└── README.md             # This file

Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm start - Run the compiled server

Making Changes

  1. Edit src/index.ts
  2. Run npm run build to compile
  3. Restart your MCP client to load changes

Security Considerations

⚠️ Important Security Notes:

  1. Credentials: Never commit database credentials to version control. Use environment variables or secure credential storage.
  2. Connection Encryption: For production databases, set DB_ENCRYPT=true and DB_TRUST_SERVER_CERT=false.
  3. Permissions: Use a database account with minimal required permissions. Consider read-only access if write operations aren't needed.
  4. Network Security: Ensure your SQL Server is not exposed to the public internet. Use VPNs or private networks when possible.
  5. SQL Injection: The server uses parameterized queries where possible, but be cautious with dynamic SQL in custom queries.

Connection Pool Management

The server maintains connection pools per database to optimize performance. Pools are automatically created on first use and cleaned up on server shutdown. Connection parameters:

  • Max connections: 10 (configurable via DB_POOL_MAX)
  • Idle timeout: 30 seconds
  • Automatic reconnection on connection loss

Troubleshooting

Common Issues

Connection Refused:

  • Verify SQL Server is running and accessible
  • Check firewall rules allow connections on port 1433
  • Ensure SQL Server authentication is enabled if using username/password

Login Failed:

  • Verify credentials are correct
  • Check user has appropriate database permissions
  • For Windows Authentication, use appropriate connection string format

Certificate Errors:

  • For self-signed certificates, set DB_TRUST_SERVER_CERT=true
  • For production, obtain proper SSL certificates

MCP Server Not Appearing:

  • Verify the path to build/index.js is correct
  • Check Node.js is installed and accessible
  • Review MCP client logs for error messages

License

[Specify your license here]

Contributing

[Specify contribution guidelines here]

Support

For issues and questions:

  • Create an issue in the Azure DevOps repository
  • Contact your development team

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选