@@ -41,7 +41,7 @@ let isReadOnlyMode = false;
4141const server = new Server (
4242 {
4343 name : "mongodb" ,
44- version : "1.1.1 " ,
44+ version : "1.1.2 " ,
4545 } ,
4646 {
4747 capabilities : {
@@ -57,7 +57,9 @@ const server = new Server(
5757 */
5858async function connectToMongoDB ( url : string , readOnly : boolean = false ) {
5959 try {
60- const options = readOnly ? { readPreference : ReadPreference . SECONDARY } : { } ;
60+ const options = readOnly
61+ ? { readPreference : ReadPreference . SECONDARY }
62+ : { } ;
6163 client = new MongoClient ( url , options ) ;
6264 await client . connect ( ) ;
6365 db = client . db ( ) ;
@@ -83,7 +85,7 @@ server.setRequestHandler(PingRequestSchema, async () => {
8385 await db . command ( { ping : 1 } ) ;
8486
8587 return {
86- readOnlyMode : isReadOnlyMode
88+ readOnlyMode : isReadOnlyMode ,
8789 } ;
8890 } catch ( error ) {
8991 if ( error instanceof Error ) {
@@ -438,14 +440,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
438440 properties : {
439441 nameOnly : {
440442 type : "boolean" ,
441- description : "Optional: If true, returns only the collection names instead of full collection info"
443+ description :
444+ "Optional: If true, returns only the collection names instead of full collection info" ,
442445 } ,
443446 filter : {
444- type : "object" ,
445- description : "Optional: Filter to apply to the collections"
446- }
447- }
448- }
447+ type : "object" ,
448+ description : "Optional: Filter to apply to the collections" ,
449+ } ,
450+ } ,
451+ } ,
449452 } ,
450453 ] ,
451454 } ;
@@ -457,13 +460,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
457460 */
458461server . setRequestHandler ( CallToolRequestSchema , async ( request ) => {
459462 const collection = db . collection ( request . params . arguments ?. collection ) ;
460-
463+
461464 // Define write operations that should be blocked in read-only mode
462- const writeOperations = [ ' update' , ' insert' , ' createIndex' ] ;
463-
465+ const writeOperations = [ " update" , " insert" , " createIndex" ] ;
466+
464467 // Check if the operation is a write operation and we're in read-only mode
465468 if ( isReadOnlyMode && writeOperations . includes ( request . params . name ) ) {
466- throw new Error ( `ReadonlyError: Operation '${ request . params . name } ' is not allowed in read-only mode` ) ;
469+ throw new Error (
470+ `ReadonlyError: Operation '${ request . params . name } ' is not allowed in read-only mode` ,
471+ ) ;
467472 }
468473
469474 switch ( request . params . name ) {
@@ -732,8 +737,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
732737 status : { } ,
733738 connectionInfo : {
734739 readOnlyMode : isReadOnlyMode ,
735- readPreference : isReadOnlyMode ? ' secondary' : ' primary'
736- }
740+ readPreference : isReadOnlyMode ? " secondary" : " primary" ,
741+ } ,
737742 } ;
738743
739744 // Add server status information if requested
@@ -1025,17 +1030,17 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
10251030
10261031 case "listCollections" : {
10271032 const { nameOnly, filter } = request . params . arguments || { } ;
1028-
1033+
10291034 try {
10301035 // Get the list of collections
10311036 const options = filter ? { filter } : { } ;
10321037 const collections = await db . listCollections ( options ) . toArray ( ) ;
1033-
1038+
10341039 // If nameOnly is true, return only the collection names
10351040 const result = nameOnly
10361041 ? collections . map ( ( collection : any ) => collection . name )
10371042 : collections ;
1038-
1043+
10391044 return {
10401045 content : [
10411046 {
@@ -1201,21 +1206,21 @@ Use these patterns to construct MongoDB queries.`,
12011206 */
12021207async function main ( ) {
12031208 const args = process . argv . slice ( 2 ) ;
1204- let connectionUrl = '' ;
1209+ let connectionUrl = "" ;
12051210 let readOnlyMode = false ;
1206-
1211+
12071212 // Parse command line arguments
12081213 for ( let i = 0 ; i < args . length ; i ++ ) {
1209- if ( args [ i ] === ' --read-only' || args [ i ] === '-r' ) {
1214+ if ( args [ i ] === " --read-only" || args [ i ] === "-r" ) {
12101215 readOnlyMode = true ;
12111216 } else if ( ! connectionUrl ) {
12121217 connectionUrl = args [ i ] ;
12131218 }
12141219 }
1215-
1220+
12161221 if ( ! connectionUrl ) {
12171222 console . error (
1218- "Please provide a MongoDB connection URL as a command-line argument"
1223+ "Please provide a MongoDB connection URL as a command-line argument" ,
12191224 ) ;
12201225 console . error ( "Usage: command <mongodb-url> [--read-only|-r]" ) ;
12211226 process . exit ( 1 ) ;
0 commit comments