mcp-mongo-server 1.0.0 → 1.1.0

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.
package/build/index.js CHANGED
@@ -22,7 +22,7 @@ let db = null;
22
22
  */
23
23
  const server = new Server({
24
24
  name: "mongodb",
25
- version: "1.0.0",
25
+ version: "1.1.0",
26
26
  }, {
27
27
  capabilities: {
28
28
  resources: {},
@@ -378,6 +378,23 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
378
378
  required: ["collection"],
379
379
  },
380
380
  },
381
+ {
382
+ name: "listCollections",
383
+ description: "List all collections in the MongoDB database",
384
+ inputSchema: {
385
+ type: "object",
386
+ properties: {
387
+ nameOnly: {
388
+ type: "boolean",
389
+ description: "Optional: If true, returns only the collection names instead of full collection info"
390
+ },
391
+ filter: {
392
+ type: "object",
393
+ description: "Optional: Filter to apply to the collections"
394
+ }
395
+ }
396
+ }
397
+ },
381
398
  ],
382
399
  };
383
400
  });
@@ -816,8 +833,34 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
816
833
  throw new Error(`Failed to count documents in collection ${collection.collectionName}: Unknown error`);
817
834
  }
818
835
  }
836
+ case "listCollections": {
837
+ const { nameOnly, filter } = request.params.arguments || {};
838
+ try {
839
+ // Get the list of collections
840
+ const options = filter ? { filter } : {};
841
+ const collections = await db.listCollections(options).toArray();
842
+ // If nameOnly is true, return only the collection names
843
+ const result = nameOnly
844
+ ? collections.map((collection) => collection.name)
845
+ : collections;
846
+ return {
847
+ content: [
848
+ {
849
+ type: "text",
850
+ text: JSON.stringify(result, null, 2),
851
+ },
852
+ ],
853
+ };
854
+ }
855
+ catch (error) {
856
+ if (error instanceof Error) {
857
+ throw new Error(`Failed to list collections: ${error.message}`);
858
+ }
859
+ throw new Error("Failed to list collections: Unknown error");
860
+ }
861
+ }
819
862
  default:
820
- throw new Error("Unknown tool");
863
+ throw new Error(`Unknown tool: ${request.params.name}`);
821
864
  }
822
865
  });
823
866
  /**
package/build/types.js CHANGED
@@ -4,11 +4,13 @@ import { CallToolRequestSchema, ToolSchema, ResourceSchema, TextResourceContents
4
4
  export const MongoCollectionSchema = ResourceSchema.extend({
5
5
  collectionName: z.string(),
6
6
  databaseName: z.string(),
7
- indexes: z.array(z.object({
7
+ indexes: z
8
+ .array(z.object({
8
9
  name: z.string(),
9
10
  keys: z.record(z.union([z.number(), z.string()])),
10
11
  unique: z.optional(z.boolean()),
11
- })).optional(),
12
+ }))
13
+ .optional(),
12
14
  });
13
15
  // MongoDB Document Schema
14
16
  export const MongoDocumentSchema = TextResourceContentsSchema.extend({
@@ -40,14 +42,16 @@ export const MongoSortSchema = z.record(z.union([z.literal(1), z.literal(-1)]));
40
42
  export const MongoQueryToolSchema = ToolSchema.extend({
41
43
  inputSchema: z.object({
42
44
  type: z.literal("object"),
43
- properties: z.object({
45
+ properties: z
46
+ .object({
44
47
  collection: z.string(),
45
48
  filter: z.record(z.union([z.unknown(), MongoQueryOperatorSchema])),
46
49
  projection: z.record(z.union([z.literal(0), z.literal(1)])).optional(),
47
50
  sort: MongoSortSchema.optional(),
48
51
  limit: z.number().int().positive().optional(),
49
52
  skip: z.number().int().nonnegative().optional(),
50
- }).passthrough(),
53
+ })
54
+ .passthrough(),
51
55
  required: z.array(z.literal("collection")),
52
56
  }),
53
57
  });
@@ -55,10 +59,12 @@ export const MongoQueryToolSchema = ToolSchema.extend({
55
59
  export const MongoAggregateToolSchema = ToolSchema.extend({
56
60
  inputSchema: z.object({
57
61
  type: z.literal("object"),
58
- properties: z.object({
62
+ properties: z
63
+ .object({
59
64
  collection: z.string(),
60
65
  pipeline: z.array(z.record(z.unknown())),
61
- }).passthrough(),
66
+ })
67
+ .passthrough(),
62
68
  required: z.array(z.literal("collection")),
63
69
  }),
64
70
  });
@@ -66,10 +72,14 @@ export const MongoAggregateToolSchema = ToolSchema.extend({
66
72
  export const MongoCountToolSchema = ToolSchema.extend({
67
73
  inputSchema: z.object({
68
74
  type: z.literal("object"),
69
- properties: z.object({
75
+ properties: z
76
+ .object({
70
77
  collection: z.string(),
71
- filter: z.record(z.union([z.unknown(), MongoQueryOperatorSchema])).optional(),
72
- }).passthrough(),
78
+ filter: z
79
+ .record(z.union([z.unknown(), MongoQueryOperatorSchema]))
80
+ .optional(),
81
+ })
82
+ .passthrough(),
73
83
  required: z.array(z.literal("collection")),
74
84
  }),
75
85
  });
@@ -77,18 +87,32 @@ export const MongoCountToolSchema = ToolSchema.extend({
77
87
  export const MongoDistinctToolSchema = ToolSchema.extend({
78
88
  inputSchema: z.object({
79
89
  type: z.literal("object"),
80
- properties: z.object({
90
+ properties: z
91
+ .object({
81
92
  collection: z.string(),
82
93
  field: z.string(),
83
- filter: z.record(z.union([z.unknown(), MongoQueryOperatorSchema])).optional(),
84
- }).passthrough(),
94
+ filter: z
95
+ .record(z.union([z.unknown(), MongoQueryOperatorSchema]))
96
+ .optional(),
97
+ })
98
+ .passthrough(),
85
99
  required: z.array(z.literal("collection")),
86
100
  }),
87
101
  });
88
102
  // MongoDB Call Tool Request Schema
89
103
  export const MongoCallToolRequestSchema = CallToolRequestSchema.extend({
90
104
  params: z.object({
91
- name: z.enum(["query", "aggregate", "count", "distinct"]),
105
+ name: z.enum([
106
+ "query",
107
+ "aggregate",
108
+ "update",
109
+ "serverInfo",
110
+ "insert",
111
+ "createIndex",
112
+ "count",
113
+ "distinct",
114
+ "listCollections",
115
+ ]),
92
116
  arguments: z.union([
93
117
  MongoQueryToolSchema.shape.inputSchema,
94
118
  MongoAggregateToolSchema.shape.inputSchema,
@@ -136,8 +160,10 @@ export const MongoFieldSchemaSchema = z.object({
136
160
  export const MongoCollectionSchemaSchema = z.object({
137
161
  name: z.string(),
138
162
  fields: z.record(MongoFieldSchemaSchema),
139
- options: z.object({
163
+ options: z
164
+ .object({
140
165
  timestamps: z.boolean().optional(),
141
166
  strict: z.boolean().optional(),
142
- }).optional(),
167
+ })
168
+ .optional(),
143
169
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-mongo-server",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A Model Context Protocol server for MongoDB connections",
5
5
  "private": false,
6
6
  "type": "module",