microsoft / microsoft/vscode-mssql

[Bug]: MCP mssql_connect reuses existing connection instead of creating new one with specified profile credentials

Open
#21,545 0 comments 0 reactions 1 assignee View on GitHub

@caohai is already working on this.

Since Mar 12, 2026.

Area - GitHub Copilot Bug User-filed
Dominant language
TypeScript
Stars
1.9k
Forks
610
Avg merge
2d 3h
Merged PRs (30d)
97

Description

### Description

Extension: MS SQL Server (mssql) for VS Code

Environment:

VS Code (latest)
MSSQL Extension with MCP tools enabled
Windows
Description:

When multiple connection profiles target the same SQL Server instance but use different SQL Login credentials and databases, mssql_connect always reuses the first established connection instead of creating a new one with the requested profile's credentials.

### Steps to Reproduce

Steps to Reproduce:

Create two connection profiles pointing to the same server:

Profile_A: server myserver.example.com,1525, user UserA, database DatabaseA
Profile_B: server myserver.example.com,1525, user UserB, database DatabaseB
Connect using Profile_A (either explicitly or implicitly via a prior session)

Call mssql_connect with:

Run SELECT DB_NAME() AS current_database, SUSER_NAME() AS login_name on the returned connection

Expected Result:

current_database = DatabaseB
login_name = UserB
Actual Result:

current_database = DatabaseA
login_name = UserA
The tool returns success: true and a new connectionId, giving no indication that the wrong profile was used
Additional Notes:

The tool always returns a successful connection with a unique connectionId, giving no indication that the wrong profile was used.
mssql_change_database also fails with "Failed to connect to database: DatabaseB", likely because UserA has no access to DatabaseB.
Cross-database queries (DatabaseB.dbo.table) fail with: "The server principal 'UserA' is not able to access the database 'DatabaseB' under the current security context."
Disconnecting the existing connection and reconnecting with Profile_B still yields the same result — UserA on DatabaseA.
This only happens when both profiles point to the same server. It appears the MCP tool layer is matching/reusing connections by server name, ignoring the different credentials and database.

### Affected Area

- [ ] Connection dialog (SQL Server | Azure browse/Fabric browse)
- [ ] Query editor
- [ ] Query results panel
- [ ] Object Explorer
- [x] GitHub Copilot integration
- [ ] Preview/Edit data
- [ ] Table Designer
- [ ] Schema Designer
- [ ] Schema Compare
- [ ] Local SQL Server Container provisioning
- [ ] SQL database in Fabric provisioning
- [ ] DACPAC/BACPAC export/import
- [ ] SQL Database projects
- [ ] Query Plan Visualizer
- [x] Other (please describe below)

### If you selected "Other", please describe the affected area

Using CoPilot and Opus 4.6

### Environment Information

Version: 1.111.0 (user setup)
Commit: ce099c1ed25d9eb3076c11e4a280f3eb52b4fbeb
Date: 2026-03-06T23:06:10Z
Electron: 39.6.0
ElectronBuildId: 13330601
Chromium: 142.0.7444.265
Node.js: 22.22.0
V8: 14.2.231.22-electron.0
OS: Windows_NT x64 10.0.22631
SQL-Server: Microsoft SQL Server 2017 (RTM-CU31-GDR) - 14.0.3515.1 - Standard Edition (64-bit)
Copilot: 0.39 (2026-03-09)

### Confirmation

- [x] I have searched existing issues and couldn't find a match
- [x] I want to work on this issue

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.