mcp-mongo-server 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/index.js +15 -14
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -26,7 +26,7 @@ let isReadOnlyMode = false;
26
26
  */
27
27
  const server = new Server({
28
28
  name: "mongodb",
29
- version: "1.1.1",
29
+ version: "1.1.2",
30
30
  }, {
31
31
  capabilities: {
32
32
  resources: {},
@@ -39,7 +39,9 @@ const server = new Server({
39
39
  */
40
40
  async function connectToMongoDB(url, readOnly = false) {
41
41
  try {
42
- const options = readOnly ? { readPreference: ReadPreference.SECONDARY } : {};
42
+ const options = readOnly
43
+ ? { readPreference: ReadPreference.SECONDARY }
44
+ : {};
43
45
  client = new MongoClient(url, options);
44
46
  await client.connect();
45
47
  db = client.db();
@@ -63,7 +65,7 @@ server.setRequestHandler(PingRequestSchema, async () => {
63
65
  // Ping MongoDB to verify connection
64
66
  await db.command({ ping: 1 });
65
67
  return {
66
- readOnlyMode: isReadOnlyMode
68
+ readOnlyMode: isReadOnlyMode,
67
69
  };
68
70
  }
69
71
  catch (error) {
@@ -394,14 +396,14 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
394
396
  properties: {
395
397
  nameOnly: {
396
398
  type: "boolean",
397
- description: "Optional: If true, returns only the collection names instead of full collection info"
399
+ description: "Optional: If true, returns only the collection names instead of full collection info",
398
400
  },
399
401
  filter: {
400
402
  type: "object",
401
- description: "Optional: Filter to apply to the collections"
402
- }
403
- }
404
- }
403
+ description: "Optional: Filter to apply to the collections",
404
+ },
405
+ },
406
+ },
405
407
  },
406
408
  ],
407
409
  };
@@ -413,7 +415,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
413
415
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
414
416
  const collection = db.collection(request.params.arguments?.collection);
415
417
  // Define write operations that should be blocked in read-only mode
416
- const writeOperations = ['update', 'insert', 'createIndex'];
418
+ const writeOperations = ["update", "insert", "createIndex"];
417
419
  // Check if the operation is a write operation and we're in read-only mode
418
420
  if (isReadOnlyMode && writeOperations.includes(request.params.name)) {
419
421
  throw new Error(`ReadonlyError: Operation '${request.params.name}' is not allowed in read-only mode`);
@@ -640,8 +642,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
640
642
  status: {},
641
643
  connectionInfo: {
642
644
  readOnlyMode: isReadOnlyMode,
643
- readPreference: isReadOnlyMode ? 'secondary' : 'primary'
644
- }
645
+ readPreference: isReadOnlyMode ? "secondary" : "primary",
646
+ },
645
647
  };
646
648
  // Add server status information if requested
647
649
  if (serverStatus) {
@@ -1013,11 +1015,11 @@ Use these patterns to construct MongoDB queries.`,
1013
1015
  */
1014
1016
  async function main() {
1015
1017
  const args = process.argv.slice(2);
1016
- let connectionUrl = '';
1018
+ let connectionUrl = "";
1017
1019
  let readOnlyMode = false;
1018
1020
  // Parse command line arguments
1019
1021
  for (let i = 0; i < args.length; i++) {
1020
- if (args[i] === '--read-only' || args[i] === '-r') {
1022
+ if (args[i] === "--read-only" || args[i] === "-r") {
1021
1023
  readOnlyMode = true;
1022
1024
  }
1023
1025
  else if (!connectionUrl) {
@@ -1029,7 +1031,6 @@ async function main() {
1029
1031
  console.error("Usage: command <mongodb-url> [--read-only|-r]");
1030
1032
  process.exit(1);
1031
1033
  }
1032
- console.log(`Connecting to MongoDB${readOnlyMode ? ' in read-only mode' : ''}...`);
1033
1034
  const connected = await connectToMongoDB(connectionUrl, readOnlyMode);
1034
1035
  if (!connected) {
1035
1036
  console.error("Failed to connect to MongoDB");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-mongo-server",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "A Model Context Protocol server for MongoDB connections",
5
5
  "private": false,
6
6
  "type": "module",