Logo MS SQL Server MCP Server

MS SQL Server MCP Server

Cộng đồng
bymcs

MCP server for Microsoft SQL Server — query, schema, and stored-procedure access for Claude Desktop, Cursor, Windsurf, and VS Code.

Nhà phát hànhbymcs
Kho mãmssql-mcp
Ngôn ngữTypeScript
Bản fork
2
Sao
13
Công cụ có sẵn
14
Phương thức truyền tảistdio, streamable-http
Danh mục
Giấy phépMIT
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    MS SQL Server MCP Server cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 14 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    13 sao và 2 bản fork từ kho mã được liên kết.

MS SQL Server MCP Server v3.0.0

🚀 Model Context Protocol (MCP) server for Microsoft SQL Server - compatible with Claude Desktop, Cursor, Windsurf and VS Code.

CI npm version License: MIT

Standards Alignment

🚀 Quick Start

1. Install

bash
npm install -g mssql-mcp

2. Configure IDE

Claude Desktop (claude_desktop_config.json):

json
{
  "mcpServers": {
    "mssql": {
      "command": "npx",
      "args": ["-y", "mssql-mcp@latest"],
      "env": {
        "DB_SERVER": "your-server.com",
        "DB_DATABASE": "your-database",
        "DB_USER": "your-username",
        "DB_PASSWORD": "your-password",
        "DB_ENCRYPT": "true",
        "DB_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}

Cursor/Windsurf/VS Code (.vscode/mcp.json):

json
{
  "servers": {
    "mssql": {
      "command": "npx",
      "args": ["-y", "mssql-mcp@latest"],
      "env": {
        "DB_SERVER": "your-server.com",
        "DB_DATABASE": "your-database",
        "DB_USER": "your-username",
        "DB_PASSWORD": "your-password",
        "DB_ENCRYPT": "true",
        "DB_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}

HTTP transport (remote/hosted scenarios):

json
{
  "servers": {
    "mssql": {
      "type": "http",
      "url": "http://127.0.0.1:3001",
      "env": {}
    }
  }
}

Replace with your actual database credentials. Credentials are read from the server environment only — never passed as tool parameters.

��️ Tool Catalog

Primary tools (use these)

ToolRead-onlyDescription
mssql_connect_databaseNoConnect using env variables. Idempotent.
mssql_disconnect_databaseNoClose connection. Idempotent.
mssql_connection_status✅Connection state and pool metrics
mssql_run_sql_query⚠️ NoExecute arbitrary SQL. May mutate data.
mssql_list_schema_objects✅List tables/views/procedures/functions with pagination
mssql_describe_table_columns✅Column definitions for a table
mssql_read_table_rows✅Paginated rows with projection and safe WHERE
mssql_execute_stored_procedure⚠️ NoExecute a stored procedure
mssql_list_databases✅List all databases on the instance

All data tools accept a response_format parameter ("json" | "markdown", default "json"). Use "markdown" to get human-readable table output.

Deprecated aliases (still registered for backward compatibility)

These are the only alias tool names the server actually registers (in src/tools/*.ts). They behave the same as their replacement but are not documented in new integrations — use the primary tool names above instead.

Old nameUse instead
mssql_execute_querymssql_run_sql_query
mssql_get_schemamssql_list_schema_objects
mssql_describe_tablemssql_describe_table_columns
mssql_get_table_datamssql_read_table_rows
mssql_execute_proceduremssql_execute_stored_procedure

🚌 Transport Modes

ModeUse when
stdio (default)Local IDE integration (Claude Desktop, Cursor, VS Code)
httpRemote/hosted deployment, testing with MCP Inspector
bash
# stdio (default)
node dist/src/index.js

# HTTP on 127.0.0.1:3001
MCP_TRANSPORT=http node dist/src/index.js

# Custom HTTP host/port
MCP_TRANSPORT=http MCP_HOST=0.0.0.0 MCP_PORT=8080 node dist/src/index.js

🔧 Environment Variables

Database connection

VariableRequiredDefaultDescription
DB_SERVER✅—SQL Server hostname or IP
DB_DATABASE❌—Database name
DB_USER❌—Login username
DB_PASSWORD❌—Login password
DB_PORT❌1433TCP port
DB_ENCRYPT❌trueEnable TLS (required for Azure SQL)
DB_TRUST_SERVER_CERTIFICATE❌falseTrust self-signed certs
DB_CONNECTION_TIMEOUT❌30000Connection timeout ms
DB_REQUEST_TIMEOUT❌30000Query timeout ms

Transport

VariableDefaultDescription
MCP_TRANSPORTstdiostdio or http
MCP_HOST127.0.0.1HTTP bind address
MCP_PORT3001HTTP port

🔒 Security Model

  • No credential parameters: All connection settings come from environment variables only. Tool inputs cannot override connection config.
  • Identifier validation: Schema, table, and procedure names are validated against a safe identifier pattern before interpolation into SQL.
  • Parameterized queries: All user-supplied values (WHERE clause values, column values) must be passed as named parameters via @paramName — never embedded in query strings.
  • Origin and Host validation: HTTP transport validates both the Origin and Host headers against an allowlist (localhost, [::1], and the configured bind host by default), guarding against DNS rebinding.
  • SQL risk labeling: run_sql_query and execute_stored_procedure are explicitly labeled as non-read-only and open-world.

⚠️ SQL Risk Notes

run_sql_query accepts arbitrary SQL including DDL and DML. To minimize risk:

  • Use a least-privilege SQL login (SELECT-only where possible)
  • Never run the server with a sysadmin or sa account
  • Consider network firewall rules to limit what the server can reach

📄 Pagination

All list tools return a pagination object:

json
{
  "count": 20,
  "limit": 20,
  "offset": 0,
  "has_more": true,
  "next_offset": 20,
  "total_count": 150
}

Default page size: 20 rows. Maximum: 200 rows.

Results are also truncated if the serialized payload exceeds 100KB, with a truncation_message explaining how many rows were dropped.

🏗️ Architecture

src/
  index.ts          ← bootstrap (env, transport selection)
  server.ts         ← createServer() factory
  constants.ts      ← limits, defaults, protocol strings
  config.ts         ← env parsing
  types.ts          ← shared TypeScript interfaces
  db/
    connection.ts   ← connection pool singleton
    validators.ts   ← SQL identifier validation
    query-builders.ts ← safe parameterized query construction
  tools/            ← one file per tool group
  resources/        ← MCP resource handlers
  transports/       ← stdio and HTTP transports
  utils/
    errors.ts       ← error normalization helpers
    format.ts       ← JSON formatting, payload truncation
    markdown.ts     ← markdown table/list rendering helpers
    pagination.ts   ← pagination metadata helpers

🧪 Inspector Smoke Test

bash
npx @modelcontextprotocol/inspector

Expected:

  • stdio server connects
  • Tool list renders with all tools
  • mssql_connection_status returns JSON without a connection
  • mssql_connect_database works when env variables are set

🔨 Development

bash
npm install
cp .env.example .env  # fill in your test DB credentials
npm run typecheck     # type check only
npm run build         # compile TypeScript
npm test              # run unit tests
npm run ci            # typecheck + build + test

License

MIT © BYMCS

Cài đặt

TypingMind
{
  "mcpServers": {
    "mssql-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "mssql-mcp@latest"
      ],
      "env": {
        "DB_SERVER": "<DB_SERVER>"
      }
    }
  }
}

Công cụ có sẵn

  • mssql_connect_database

    Connects to MS SQL Server using environment variables (DB_SERVER, DB_DATABASE, DB_USER, DB_PASSWORD, DB_PORT, DB_ENCRYPT, DB_TRUST_SERVER_CERTIFICATE). No credentials accepted as parameters — all connection settings come from the server environment only. Idempotent: calling again reconnects.

  • mssql_disconnect_database

    Closes the current database connection and releases the connection pool. Safe to call even if not connected. Idempotent.

  • mssql_connection_status

    Returns the current connection status, server address, database name, and connection pool metrics. Read-only. Safe to call at any time.

  • mssql_run_sql_query

    Executes an arbitrary SQL statement against the connected database. ⚠️ WARNING: This tool can read AND modify data (INSERT, UPDATE, DELETE, DDL). Always prefer parameterized inputs via the 'parameters' field — never embed user-supplied values directly in the query string. Example: query='SELECT * FROM dbo.Users WHERE Id = @id', parameters={id: 42}

  • mssql_execute_query

    Deprecated alias for mssql_run_sql_query. Use mssql_run_sql_query instead. ⚠️ This tool can read AND modify data.

  • mssql_list_schema_objects

    Lists tables, views, stored procedures, or functions in the connected database. Read-only. Supports filtering by schema name and pagination. Example: objectType='tables', schemaName='dbo', limit=20

  • mssql_get_schema

    Deprecated alias for mssql_list_schema_objects. Use mssql_list_schema_objects instead.

  • mssql_describe_table_columns

    Returns column definitions for a table: name, data type, length, nullability, default, and ordinal position. Read-only. Uses parameterized queries to prevent injection.

  • mssql_describe_table

    Deprecated alias for mssql_describe_table_columns.

  • mssql_read_table_rows

    Returns rows from a table with optional column projection, WHERE filtering, ORDER BY, and pagination. Read-only. Table and schema names are validated as safe identifiers. WHERE clause values MUST be passed via 'parameters' using @paramName placeholders. Pagination: limit (1-200, default 20) and offset. Example: tableName='Orders', schemaName='dbo', columns=['OrderId','Total'], limit=50

  • mssql_get_table_data

    Deprecated alias for mssql_read_table_rows. Use mssql_read_table_rows instead. ⚠️ whereClause must use @paramName placeholders for all values.

  • mssql_execute_stored_procedure

    Executes a stored procedure by name. ⚠️ May modify data — use only when an action is intended. Schema and procedure names are validated as safe identifiers. Pass all value parameters via 'parameters'.

  • mssql_execute_procedure

    Deprecated alias for mssql_execute_stored_procedure.

  • mssql_list_databases

    Lists all databases visible on the connected SQL Server instance with state and recovery information. Read-only. Supports pagination.

Dùng MCP MS SQL Server MCP Server với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối MS SQL Server MCP Server, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. Bạn có thể chạy MCP ngay trên thiết bị của mình hoặc kết nối qua URL của máy chủ MCP từ xa.

Cách 1: Dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm MS SQL Server MCP Server làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của MS SQL Server MCP Server.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "mssql-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "mssql-mcp"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của MS SQL Server MCP Server, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của MS SQL Server MCP Server.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng MS SQL Server MCP Server giúp tôi làm việc này không?
MS SQL Server MCP Server
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng MS SQL Server MCP Server.

Cách 2: Thêm URL máy chủ MCP

Dùng cách này khi MS SQL Server MCP Server đã được lưu trữ từ xa hoặc nhóm của bạn muốn có một trình kết nối dùng chung cho nhiều người dùng.

1

Mở mục Trình kết nối MCP

Trong TypingMind, vào Plugin, mở mục Trình kết nối MCP, rồi chọn Thêm URL.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Vào mục Plugin.
  3. Mở mục Trình kết nối MCP.
  4. Nhấp vào Thêm URL.
Biểu mẫu Thêm URL máy chủ MCP tùy chỉnh của TypingMind
2

Dán URL máy chủ

Nhập URL máy chủ MCP do nhà cung cấp cung cấp vào trường URL máy chủ. Thêm tên kết nối, mô tả, biểu tượng, header HTTP tùy chỉnh hoặc cài đặt ứng dụng khách OAuth nếu máy chủ yêu cầu.

  1. Dán URL máy chủ MCP do nhà cung cấp cung cấp vào trường URL máy chủ.
  2. Nhập tên kết nối cho MS SQL Server MCP Server.
  3. Thêm mô tả và biểu tượng nếu bạn muốn dễ nhận biết kết nối hơn.
  4. Thêm header HTTP tùy chỉnh hoặc thông tin ứng dụng khách OAuth nếu máy chủ yêu cầu xác thực.
3

Tạo kết nối

Nhấp vào Tạo kết nối, sau đó quay lại danh sách Plugin và xác nhận kết nối MCP mới đang hoạt động.

  1. Nhấp vào Tạo kết nối.
  2. Quay lại danh sách trình kết nối MCP.
  3. Xác nhận kết nối MS SQL Server MCP Server hiển thị trạng thái đang hoạt động.
  4. Làm mới danh sách plugin nếu kết nối chưa xuất hiện ngay.
4

Đổi mô hình mà không cần kết nối lại

Bắt đầu cuộc trò chuyện với mô hình bạn thích, bật các công cụ của MS SQL Server MCP Server trong mục Plugin và chuyển sang mô hình khác khi cần. Kết nối MCP vẫn sẵn dùng trong không gian làm việc TypingMind.

  1. Bắt đầu cuộc trò chuyện mới trong TypingMind.
  2. Chọn mô hình AI bạn muốn dùng.
  3. Bật các công cụ của MS SQL Server MCP Server trong mục Plugin.
  4. Yêu cầu mô hình dùng công cụ khi cần.
  5. Chuyển sang mô hình AI khác và dùng lại cùng kết nối MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng MS SQL Server MCP Server giúp tôi làm việc này không?
MS SQL Server MCP Server
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng MS SQL Server MCP Server.

Câu hỏi thường gặp

Máy chủ MCP MS SQL Server MCP Server dùng để làm gì?

MS SQL Server MCP Server là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP MS SQL Server MCP Server với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng MS SQL Server MCP Server với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP MS SQL Server MCP Server với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối MS SQL Server MCP Server, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP MS SQL Server MCP Server với TypingMind?

Bạn có thể kết nối MS SQL Server MCP Server trong TypingMind bằng trình kết nối MCP cục bộ hoặc bằng cách thêm URL máy chủ MCP từ xa. Dùng trình kết nối cục bộ khi máy chủ cần truy cập tệp, ứng dụng hoặc tài nguyên riêng trên thiết bị của bạn; dùng URL máy chủ khi máy chủ MCP được lưu trữ từ xa.

MCP MS SQL Server MCP Server cung cấp những công cụ nào trong TypingMind?

MS SQL Server MCP Server cung cấp 14 công cụ MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP MS SQL Server MCP Server không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu MS SQL Server MCP Server yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

connection-info

Current MSSQL connection status and configuration (no credentials exposed).

databases

Snapshot list of all databases on the SQL Server instance.

schemas

Snapshot list of all schemas in the current database.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇