Skip to content

Commit 9ffcd8f

Browse files
committed
v1.1.2
1 parent aea7457 commit 9ffcd8f

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

.github/workflows/publish-github-packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
packages: write
3030

3131
env:
32-
STATIC_VERSION: "1.1.1"
32+
STATIC_VERSION: "1.1.2"
3333
BUILD_ID: ${{ github.run_number }}
3434

3535
steps:

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcp-mongo-server",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "A Model Context Protocol server for MongoDB connections",
55
"private": false,
66
"type": "module",

src/index.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let isReadOnlyMode = false;
4141
const 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
*/
5858
async 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
*/
458461
server.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
*/
12021207
async 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

Comments
 (0)