22 ConnectionManager ,
33 type AnyConnectionState ,
44 type CompositeLogger ,
5- type MCPConnectParams ,
65 type ConnectionStateDisconnected ,
76} from 'mongodb-mcp-server' ;
87import {
@@ -13,20 +12,32 @@ import type { ServiceProvider } from '@mongosh/service-provider-core';
1312import { isAtlasStream } from 'mongodb-build-info' ;
1413import { MCPLogIds } from './mcpLogIds' ;
1514
16- export interface VSCodeMCPConnectParams extends MCPConnectParams {
15+ export interface VSCodeMCPConnectParams {
1716 connectionId : string ;
17+ connectionString : string ;
1818 connectOptions : DevtoolsConnectOptions ;
1919}
2020
21- export class VSCodeMCPConnectionManager extends ConnectionManager < VSCodeMCPConnectParams > {
21+ export class VSCodeMCPConnectionManager extends ConnectionManager {
2222 private activeConnectionId : string | null = null ;
2323 private activeConnectionProvider : ServiceProvider | null = null ;
2424
2525 constructor ( private readonly logger : CompositeLogger ) {
2626 super ( ) ;
2727 }
2828
29- async connect (
29+ connect ( ) : Promise < AnyConnectionState > {
30+ return Promise . reject (
31+ new Error (
32+ [
33+ 'MongoDB MCP Server in MongoDB VSCode extension makes use of the connection that the MongoDB VSCode extension is connected to.' ,
34+ "To connect, choose a connection from MongoDB VSCode extensions's sidepanel - https://www.mongodb.com/docs/mongodb-vscode/connect/#connect-to-your-mongodb-deployment" ,
35+ ] . join ( ' ' ) ,
36+ ) ,
37+ ) ;
38+ }
39+
40+ async connectToVSCodeConnection (
3041 connectParams : VSCodeMCPConnectParams ,
3142 ) : Promise < AnyConnectionState > {
3243 try {
@@ -35,6 +46,7 @@ export class VSCodeMCPConnectionManager extends ConnectionManager<VSCodeMCPConne
3546 connectParams . connectionString ,
3647 connectParams . connectOptions ,
3748 ) ) ;
49+ await serviceProvider . runCommand ( 'admin' , { hello : 1 } ) ;
3850 this . activeConnectionId = connectParams . connectionId ;
3951 return this . changeState ( 'connection-succeeded' , {
4052 tag : 'connected' ,
@@ -106,7 +118,7 @@ export class VSCodeMCPConnectionManager extends ConnectionManager<VSCodeMCPConne
106118 return ;
107119 }
108120
109- await this . connect ( {
121+ await this . connectToVSCodeConnection ( {
110122 connectionString,
111123 connectOptions,
112124 connectionId,
0 commit comments