Skip to content

Commit 9e14b69

Browse files
committed
Merge branch 'release/7.2.2'
2 parents 26c0a1b + 61f3454 commit 9e14b69

4 files changed

Lines changed: 63 additions & 61 deletions

File tree

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,24 @@
112112

113113
- [Overview](#other-features-overview)
114114
- [New Database Metadata](#other-features-new-database-metadata)
115-
- [MongoDB Version Compatibility](#other-features-mongodb-version-compatibility)
116115

117116
#### Other Features: Overview
118117

119-
MongoDB Lens includes several additional features:
120-
121-
- **Configuration File**: Custom configuration via `~/.mongodb-lens.json`
122-
- **Connection Resilience**: Automatic reconnection with exponential backoff
123-
- **Component Disabling**: Selectively disable specific tools, prompts or resources
124-
- **JSONRPC Error Handling**: Comprehensive error handling with proper error codes
125-
- **Smart Caching**: Optimized caching for schemas, indexes, fields, collections and more
126-
- **Memory Management**: Automatic memory monitoring and cleanup for large operations
118+
MongoDB Lens includes numerous other features:
119+
120+
- **[Config File](#configuration-config-file)**: Custom configuration via `~/.mongodb-lens.[jsonc|json]`
121+
- **[Env Var Overrides](#configuration-environment-variable-overrides)**: Override config settings via `process.env.CONFIG_*`
122+
- **[Confirmation System](#data-protection-confirmation-for-destructive-operations)**: Two-step verification for destructive operations
123+
- **[Multiple Connections](#configuration-multiple-mongodb-connections)**: Define and switch between named URI aliases
124+
- **[Component Disabling](#disabling-tools)**: Selectively disable tools, prompts or resources
125+
- **Connection Resilience**: Auto-reconnection with exponential backoff
126+
- **Query Safeguards**: Configurable limits and performance protections
127+
- **Error Handling**: Comprehensive JSONRPC error codes and messages
128+
- **Schema Inference**: Efficient schema analysis with intelligent sampling
129+
- **Credential Protection**: Connection string password obfuscation in logs
130+
- **Memory Management**: Auto-monitoring and cleanup for large operations
131+
- **Smart Caching**: Optimized caching for schema, indexes, fields and collections
132+
- **Backwards Compatible**: Support both modern and legacy MongoDB versions
127133

128134
#### Other Features: New Database Metadata
129135

@@ -172,10 +178,6 @@ Once you've added your own collections to your new database, you can safely remo
172178
- _"Drop the new database's metadata collection"_<br>
173179
<sup>➥ Uses `drop-collection` tool (with confirmation)</sup>
174180

175-
#### Other Features: MongoDB Version Compatibility
176-
177-
MongoDB Lens implements a backward compatibility layer to work reliably with both older MongoDB deployments and latest versions, providing consistent behavior without requiring version-specific configuration.
178-
179181
## Installation
180182

181183
MongoDB Lens can be installed and run in several ways:

mongodb-lens.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,8 +1877,8 @@ const registerTools = (server) => {
18771877
streaming: createBooleanSchema('Enable streaming for large result sets', 'false')
18781878
},
18791879
async ({ collection, filter, projection, limit, skip, sort, streaming }) => {
1880-
try {
1881-
log(`Tool: Finding documents in collection '${collection}'`)
1880+
return withErrorHandling(async () => {
1881+
log(`Tool: Finding documents in collection '${collection}'...`)
18821882
log(`Tool: Using filter: ${filter}`)
18831883
if (projection) log(`Tool: Using projection: ${projection}`)
18841884
if (sort) log(`Tool: Using sort: ${sort}`)
@@ -1896,21 +1896,7 @@ const registerTools = (server) => {
18961896
text: formatDocuments(documents, limit)
18971897
}]
18981898
}
1899-
} catch (error) {
1900-
log(`Error finding documents: ${error.message}`, true)
1901-
return {
1902-
content: [{
1903-
type: 'text',
1904-
text: `Error finding documents: ${error.message}`
1905-
}],
1906-
isError: true,
1907-
error: {
1908-
code: JSONRPC_ERROR_CODES.MONGODB_QUERY_ERROR,
1909-
message: error.message,
1910-
data: { type: error.name }
1911-
}
1912-
}
1913-
}
1899+
}, `Error finding documents in collection '${collection}'`)
19141900
}
19151901
)
19161902
}
@@ -2074,8 +2060,8 @@ const registerTools = (server) => {
20742060
limit: z.number().int().min(1).default(1000).describe('Maximum number of results to return when streaming')
20752061
},
20762062
async ({ collection, pipeline, streaming, limit }) => {
2077-
try {
2078-
log(`Tool: Running aggregation on collection '${collection}'`)
2063+
return withErrorHandling(async () => {
2064+
log(`Tool: Running aggregation on collection '${collection}'...`)
20792065
log(`Tool: Using pipeline: ${pipeline}`)
20802066
log(`Tool: Streaming: ${streaming}, Limit: ${limit}`)
20812067

@@ -2090,21 +2076,7 @@ const registerTools = (server) => {
20902076
text: formatDocuments(results, 100)
20912077
}]
20922078
}
2093-
} catch (error) {
2094-
log(`Error running aggregation: ${error.message}`, true)
2095-
return {
2096-
content: [{
2097-
type: 'text',
2098-
text: `Error running aggregation: ${error.message}`
2099-
}],
2100-
isError: true,
2101-
error: {
2102-
code: JSONRPC_ERROR_CODES.MONGODB_QUERY_ERROR,
2103-
message: error.message,
2104-
data: { type: error.name }
2105-
}
2106-
}
2107-
}
2079+
}, `Error running aggregation on collection '${collection}'`)
21082080
}
21092081
)
21102082
}
@@ -3144,17 +3116,36 @@ const withErrorHandling = async (operation, errorMessage, defaultValue = null) =
31443116
log(formattedError, true)
31453117

31463118
let errorCode = JSONRPC_ERROR_CODES.SERVER_ERROR_START
3119+
let errorType = error.name || 'Error'
31473120

31483121
if (error.name === 'MongoError' || error.name === 'MongoServerError') {
3149-
if (error.code === 13) errorCode = JSONRPC_ERROR_CODES.RESOURCE_ACCESS_DENIED
3150-
else if (error.code === 59 || error.code === 61) errorCode = JSONRPC_ERROR_CODES.MONGODB_CONNECTION_ERROR
3151-
else if (error.code === 121) errorCode = JSONRPC_ERROR_CODES.MONGODB_SCHEMA_ERROR
3152-
else errorCode = JSONRPC_ERROR_CODES.MONGODB_QUERY_ERROR
3153-
} else if (error.message.includes('not found') || error.message.includes('does not exist')) {
3122+
switch(error.code) {
3123+
case 13:
3124+
errorCode = JSONRPC_ERROR_CODES.RESOURCE_ACCESS_DENIED; break
3125+
case 59: case 61:
3126+
errorCode = JSONRPC_ERROR_CODES.MONGODB_CONNECTION_ERROR; break
3127+
case 121:
3128+
errorCode = JSONRPC_ERROR_CODES.MONGODB_SCHEMA_ERROR; break
3129+
case 11000:
3130+
errorCode = JSONRPC_ERROR_CODES.MONGODB_DUPLICATE_KEY; break
3131+
case 112: case 16500:
3132+
errorCode = JSONRPC_ERROR_CODES.MONGODB_WRITE_ERROR; break
3133+
case 50: case 57:
3134+
errorCode = JSONRPC_ERROR_CODES.MONGODB_TIMEOUT_ERROR; break
3135+
default:
3136+
errorCode = JSONRPC_ERROR_CODES.MONGODB_QUERY_ERROR
3137+
}
3138+
} else if (error.message.match(/not found|does not exist|cannot find/i)) {
31543139
errorCode = JSONRPC_ERROR_CODES.RESOURCE_NOT_FOUND
3140+
} else if (error.message.match(/already exists|duplicate/i)) {
3141+
errorCode = JSONRPC_ERROR_CODES.RESOURCE_ALREADY_EXISTS
3142+
} else if (error.message.match(/permission|access denied|unauthorized/i)) {
3143+
errorCode = JSONRPC_ERROR_CODES.RESOURCE_ACCESS_DENIED
3144+
} else if (error.message.match(/timeout|timed out/i)) {
3145+
errorCode = JSONRPC_ERROR_CODES.MONGODB_TIMEOUT_ERROR
31553146
}
31563147

3157-
const errorResponse = {
3148+
return {
31583149
content: [{
31593150
type: 'text',
31603151
text: formattedError
@@ -3163,11 +3154,12 @@ const withErrorHandling = async (operation, errorMessage, defaultValue = null) =
31633154
error: {
31643155
code: errorCode,
31653156
message: error.message,
3166-
data: { type: error.name }
3157+
data: {
3158+
type: errorType,
3159+
details: error.code ? `MongoDB error code: ${error.code}` : undefined
3160+
}
31673161
}
31683162
}
3169-
3170-
return errorResponse
31713163
}
31723164
}
31733165

@@ -6007,18 +5999,26 @@ const confirmationTokens = {
60075999
}
60086000

60096001
const JSONRPC_ERROR_CODES = {
6002+
// Standard JSON-RPC error codes (keep for compatibility)
60106003
PARSE_ERROR: -32700,
60116004
INVALID_REQUEST: -32600,
60126005
METHOD_NOT_FOUND: -32601,
60136006
INVALID_PARAMS: -32602,
60146007
INTERNAL_ERROR: -32603,
60156008
SERVER_ERROR_START: -32000,
6016-
SERVER_ERROR_END: -32099,
6009+
6010+
// MongoDB-specific error codes (expanded)
60176011
MONGODB_CONNECTION_ERROR: -32050,
60186012
MONGODB_QUERY_ERROR: -32051,
60196013
MONGODB_SCHEMA_ERROR: -32052,
6014+
MONGODB_WRITE_ERROR: -32053,
6015+
MONGODB_DUPLICATE_KEY: -32054,
6016+
MONGODB_TIMEOUT_ERROR: -32055,
6017+
6018+
// Resource-related error codes
60206019
RESOURCE_NOT_FOUND: -32040,
6021-
RESOURCE_ACCESS_DENIED: -32041
6020+
RESOURCE_ACCESS_DENIED: -32041,
6021+
RESOURCE_ALREADY_EXISTS: -32042
60226022
}
60236023

60246024
const instructions = `

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": "mongodb-lens",
3-
"version": "7.2.1",
3+
"version": "7.2.2",
44
"author": "James Furey (https://about.me/jamesfurey)",
55
"description": "MongoDB Lens: Full Featured MCP Server for MongoDB Databases",
66
"license": "MIT",

0 commit comments

Comments
 (0)