feat(mongodb): support generic runCommand execution
This commit is contained in:
1 parent
2d00620fac
commit
9b24d962bb
27 files changed
+580
-18
No files matched your search
@@ -972,6 +972,9 @@ impl DbxBackend for WebBackend {
|
||||
Ok(scalar_query_result("version", Value::String(version)))
|
||||
}
|
||||
MongoCommand::Use { database } => Ok(scalar_query_result("database", Value::String(database.clone()))),
|
||||
MongoCommand::RunCommand { .. } => {
|
||||
Err("MongoDB runCommand is not available through the DBX MCP backend".to_string())
|
||||
}
|
||||
MongoCommand::Find { collection, filter, projection, sort, collation, skip, limit } => {
|
||||
let result = self
|
||||
.request(
|
||||
|
||||
@@ -1059,6 +1059,12 @@ fn validate_mongo_command(
|
||||
),
|
||||
)
|
||||
})?;
|
||||
if matches!(command, MongoCommand::RunCommand { .. }) {
|
||||
return Err(tool_error(
|
||||
"SQL_BLOCKED",
|
||||
"MongoDB runCommand is not available through MCP; review and execute it manually in DBX.",
|
||||
));
|
||||
}
|
||||
let permissions = mcp_permissions(connection, policy);
|
||||
let production_database = match &command {
|
||||
MongoCommand::Aggregate { pipeline, .. } => {
|
||||
@@ -1498,6 +1504,22 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mongo_run_command_is_never_exposed_through_mcp() {
|
||||
let mongo = connection("mongo", "mongo", "mongodb", "staging");
|
||||
let source = r#"db.runCommand({ping: 1})"#;
|
||||
|
||||
for policy in [
|
||||
McpGlobalPolicy { read_only: true, allow_dangerous_sql: false, allowed_connection_ids: None },
|
||||
McpGlobalPolicy { read_only: false, allow_dangerous_sql: false, allowed_connection_ids: None },
|
||||
McpGlobalPolicy { read_only: false, allow_dangerous_sql: true, allowed_connection_ids: None },
|
||||
] {
|
||||
let error = validate_mongo_command(&mongo, &policy, "staging", source).unwrap_err();
|
||||
assert!(result_text(&error).contains("SQL_BLOCKED"));
|
||||
assert!(result_text(&error).contains("runCommand"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn agent_results_preserve_stable_backend_policy_errors() {
|
||||
let result = agent_result(dbx_core::agent_events::ToolResult {
|
||||
|
||||
Reference in new issue
Block a user