Skip to content

Commit f0e064b

Browse files
fix: disable MCP auto start and instead request on first load and new connection attempts VSCODE-704 (#1132)
1 parent 3ed6d53 commit f0e064b

File tree

9 files changed

+1006
-334
lines changed

9 files changed

+1006
-334
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ constants.json
1111
.eslintcache
1212
.sbom
1313
src/test/ai-accuracy-tests/test-results.html
14+
.yalc
15+
yalc.lock

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@
13201320
},
13211321
"mdb.mcp.readOnly": {
13221322
"type": "boolean",
1323-
"default": false,
1323+
"default": true,
13241324
"description": "When set to true, MongoDB MCP server will only allow read, connect, and metadata operation types, disabling create/update/delete operations."
13251325
},
13261326
"mdb.mcp.indexCheck": {
@@ -1331,11 +1331,16 @@
13311331
"mdb.mcp.server": {
13321332
"type": "string",
13331333
"enum": [
1334-
"ask",
1335-
"enabled",
1336-
"disabled"
1334+
"prompt",
1335+
"autoStartEnabled",
1336+
"autoStartDisabled"
1337+
],
1338+
"enumItemLabels": [
1339+
"Ask",
1340+
"Auto Start Enabled",
1341+
"Auto Start Disabled"
13371342
],
1338-
"default": "ask",
1343+
"default": "prompt",
13391344
"description": "Controls whether MongoDB MCP server starts automatically with the extension and connects to the active connection. If automatic startup is disabled, the server can still be started using the 'MongoDB: Start MCP Server' command."
13401345
},
13411346
"mdb.mcp.exportsPath": {
@@ -1418,7 +1423,7 @@
14181423
"mongodb-connection-string-url": "^3.0.2",
14191424
"mongodb-data-service": "^22.30.1",
14201425
"mongodb-log-writer": "^2.4.1",
1421-
"mongodb-mcp-server": "^1.0.2-prerelease.1",
1426+
"mongodb-mcp-server": "^1.0.2-prerelease.2",
14221427
"mongodb-query-parser": "^4.4.2",
14231428
"mongodb-schema": "^12.6.2",
14241429
"node-machine-id": "1.1.12",
@@ -1435,6 +1440,7 @@
14351440
"devDependencies": {
14361441
"@babel/preset-typescript": "^7.25.7",
14371442
"@babel/types": "^7.25.8",
1443+
"@modelcontextprotocol/sdk": "^1.18.2",
14381444
"@mongodb-js/oidc-mock-provider": "^0.11.4",
14391445
"@mongodb-js/oidc-plugin": "^2.0.3",
14401446
"@mongodb-js/prettier-config-devtools": "^1.0.2",

src/connectionController.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,9 @@ export default class ConnectionController {
732732
return false;
733733
}
734734

735-
const originalDisconnect = this._activeDataService.disconnect.bind(this);
735+
const originalDisconnect = this._activeDataService.disconnect.bind(
736+
this._activeDataService,
737+
);
736738
this._activeDataService = null;
737739

738740
try {

src/mcp/mcpConnectionManager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class MCPConnectionManager extends ConnectionManager {
4141
this.getTelemetryAnonymousId = getTelemetryAnonymousId;
4242
}
4343

44-
connect(): Promise<AnyConnectionState> {
44+
override connect(): Promise<AnyConnectionState> {
4545
return Promise.reject(
4646
new Error(
4747
// eslint-disable-next-line no-multi-str
@@ -83,7 +83,7 @@ To connect, choose a connection from MongoDB VSCode extensions's sidepanel - htt
8383
}
8484
}
8585

86-
async disconnect(): Promise<ConnectionStateDisconnected> {
86+
override async disconnect(): Promise<ConnectionStateDisconnected> {
8787
try {
8888
await this.activeConnection?.provider?.close();
8989
} catch (error) {
@@ -100,6 +100,11 @@ To connect, choose a connection from MongoDB VSCode extensions's sidepanel - htt
100100
});
101101
}
102102

103+
override async close(): Promise<void> {
104+
await this.disconnect();
105+
this._events.emit('close', this.currentConnectionState);
106+
}
107+
103108
async updateConnection(
104109
connectParams: MCPConnectParams | undefined,
105110
): Promise<void> {

0 commit comments

Comments
 (0)