Repository: keephq/keep
Pull request: feat: Add mongodb as a provider
fix #624
/claim #624

Problem statement:
Add mongodb as a provider
**Is your feature request related to a problem? Please describe.**
I'm looking to read data from mongodb in my workflow.

**Describe the solution you'd like**
In my workflow, i have few configurable parameters which are stored in mongodb. I want to fetch them against an evernt (like trigger interval, or email address etc) and use in workflow

**Describe alternatives you've considered**
as our configuraiton needs to be externalized, i'm not able to think of any other alternative. I'm open for discussion regarding this.

**Additional context**

Hints from issue discussion:
/bounty 50
@shahargl 

We want to connect mongodb using `pymongo` https://www.w3schools.com/python/python_mongodb_create_db.asp,  right?
yea you can use `pymongo` for that. notice that you need also `scopes` and `validate_scopes` (you can see datadog provider for example). also note that this should support self hosted mongo so the URL is also necessary. @rishi-raj-jain 
@shahargl 

Awesome, that sounds great. I think the URL part is already handled by the below whether it's localhost or a production URL.

```
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
```

> you need also scopes and validate_scopes

I did see the datadog provider but that seems too heavy to parse, do we have a guide on what are these scopes and validate_scopes?
So look at `mysql_provider`, much easier
💡 @rishi-raj-jain submitted a [pull request](https://github.com/keephq/keep/pull/625) that claims the bounty. You can [visit your bounty board](https://console.algora.io/org/keephq/bounties) to reward.

Commit message: Create mongodb-provider.mdx

Signed-off-by: Rishi Raj Jain <rishi18304@iiitd.ac.in>

Patch to review:
diff --git a/docs/providers/documentation/mongodb-provider.mdx b/docs/providers/documentation/mongodb-provider.mdx
new file mode 100644
index 0000000000..ac9c16378e
--- /dev/null
+++ b/docs/providers/documentation/mongodb-provider.mdx
@@ -0,0 +1,45 @@
+---
+title: "MongoDB"
+sidebarTitle: "MongoDB Provider"
+description: "MongoDB Provider is a provider used to query MongoDB databases"
+---
+
+## Inputs
+
+The `query` function of `MongoDBProvider` takes the following arguments:
+
+- `query` (str): A string containing the query to be executed against the MongoDB database.
+- `single_row` (bool, optional): If `True`, the function will return only the first result.
+
+## Outputs
+
+The `query` function returns either a `list` or a `tuple` of results, depending on whether `single_row` was set to `True` or not. If `single_row` was `True`, then the function returns a single result.
+
+## Authentication Parameters
+
+The following authentication parameters are used to connect to the MongoDB database:
+
+- `uri` (str, optional): The MongoDB connection URI. If provided, other authentication parameters will be ignored.
+- `username` (str): The MongoDB username.
+- `password` (str): The MongoDB password.
+- `host` (str): The MongoDB hostname.
+- `database` (str): The name of the MongoDB database.
+
+## Connecting with the Provider
+
+In order to connect to the MongoDB database, you can use either a connection URI or individual parameters. Here's how you can provide authentication information:
+
+1. If using a connection URI, provide the `uri` parameter with the MongoDB connection string.
+2. If using individual parameters, provide the following:
+   - `username`: MongoDB username.
+   - `password`: MongoDB password.
+   - `host`: MongoDB hostname.
+   - `database`: MongoDB database name.
+
+## Notes
+
+- Ensure that the provided user has the necessary privileges to execute queries on the specified MongoDB database.
+
+## Useful Links
+
+- [MongoDB Documentation](https://docs.mongodb.com/)
diff --git a/keep-ui/public/icons/mongodb-icon.png b/keep-ui/public/icons/mongodb-icon.png
new file mode 100644
index 0000000000..12a8010749
Binary files /dev/null and b/keep-ui/public/icons/mongodb-icon.png differ
diff --git a/keep-ui/public/mongodb.svg b/keep-ui/public/mongodb.svg
new file mode 100644
index 0000000000..11d49544d2
--- /dev/null
+++ b/keep-ui/public/mongodb.svg
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="512px" height="135px" viewBox="0 0 512 135" version="1.1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid">
+    <title>MongoDB</title>
+    <g>
+        <path d="M39.6886352,13.8097294 C34.4885087,7.63993662 30.0105819,1.37374611 29.0957796,0.0723023901 C28.9994542,-0.0241007967 28.8549661,-0.0241007967 28.7586888,0.0723023901 C27.8438384,1.37374611 23.3659597,7.63993662 18.165785,13.8097294 C-26.4687064,70.7355472 25.1956606,109.152421 25.1956606,109.152421 L25.6289804,109.441686 C26.0141375,115.370183 26.9771506,123.90207 26.9771506,123.90207 L28.9031288,123.90207 L30.8291069,123.90207 C30.8291069,123.90207 31.7921201,115.418394 32.1773253,109.441686 L32.6106451,109.10421 C32.6587596,109.152421 84.3233195,70.7355472 39.6886352,13.8097294 Z M28.9031288,108.284624 C28.9031288,108.284624 26.5919936,106.308458 25.966023,105.296511 L25.966023,105.199607 L28.7586888,43.2127031 C28.7586888,43.0198594 29.0476169,43.0198594 29.0476169,43.2127031 L31.8402346,105.199607 L31.8402346,105.296511 C31.2143122,106.308458 28.9031288,108.284624 28.9031288,108.284624 Z" fill="#01EC64"></path>
+        <path d="M125.58994,95.6355243 L104.060871,43.0529321 L104.01266,42.9077208 L87.2622573,42.9077208 L87.2622573,46.4422563 L89.9654437,46.4422563 C90.7859936,46.4422563 91.5583326,46.7811791 92.1378278,47.3622171 C92.716841,47.943207 93.0065887,48.7181011 93.0065887,49.5410616 L92.5239973,102.462673 C92.5239973,104.108594 91.1726452,105.464285 89.5310633,105.512978 L86.7796659,105.561189 L86.7796659,109.047321 L103.095688,109.047321 L103.095688,105.561189 L101.405896,105.512978 C99.7647957,105.464285 98.4129615,104.108594 98.4129615,102.462673 L98.4129615,52.5913666 L121.87336,109.047321 C122.210837,109.870281 122.983176,110.403012 123.852419,110.403012 C124.72118,110.403012 125.493519,109.870281 125.831477,109.047321 L148.760592,53.8501538 L149.09855,102.462673 C149.09855,104.157287 147.746716,105.512978 146.057405,105.561189 L144.319402,105.561189 L144.319402,109.047321 L163.435032,109.047321 L163.435032,105.561189 L160.828268,105.561189 C159.187168,105.561189 157.835334,104.157287 157.787123,102.510884 L157.64249,49.5892725 C157.64249,47.8948032 158.993842,46.5390639 160.635424,46.4906601 L163.435032,46.4422563 L163.435032,42.9077208 L147.11901,42.9077208 L125.58994,95.6355243 Z M275.703325,104.639878 C275.170594,104.106665 274.880364,103.379163 274.880364,102.506063 L274.880364,76.5088051 C274.880364,71.5618824 273.428733,67.6813853 270.524508,64.916971 C267.669457,62.1520746 263.700734,60.745762 258.764417,60.745762 C251.843257,60.745762 246.374692,63.5588693 242.551084,69.08818 C242.502873,69.1850839 242.357758,69.233777 242.212643,69.233777 C242.067046,69.233777 241.970625,69.1363909 241.970625,68.991276 L240.179589,62.0551706 L237.178941,62.0551706 L229.483996,66.4688806 L229.483996,68.89389 L231.468357,68.89389 C232.38774,68.89389 233.162007,69.1363909 233.694738,69.6218749 C234.226986,70.1068768 234.517216,70.8343796 234.517216,71.8525943 L234.517216,102.45737 C234.517216,103.33047 234.226986,104.057972 233.694738,104.591667 C233.162007,105.12488 232.436433,105.416074 231.565261,105.416074 L229.629111,105.416074 L229.629111,108.956684 L247.342286,108.956684 L247.342286,105.416074 L245.406617,105.416074 C244.535446,105.416074 243.809389,105.12488 243.277141,104.591667 C242.744892,104.057972 242.45418,103.33047 242.45418,102.45737 L242.45418,82.1837128 C242.45418,79.6131064 243.035122,77.0425 244.100101,74.5201046 C245.212809,72.0468843 246.858248,69.9612798 249.036417,68.3606772 C251.214105,66.7600745 253.827619,65.9838787 256.828267,65.9838787 C260.216048,65.9838787 262.781351,67.0507864 264.378097,69.1850839 C265.975325,71.3193815 266.798285,74.0837957 266.798285,77.3819049 L266.798285,102.409159 C266.798285,103.281777 266.507573,104.009279 265.975325,104.542974 C265.443076,105.076669 264.71702,105.367381 263.845848,105.367381 L261.91018,105.367381 L261.91018,108.907991 L279.623355,108.907991 L279.623355,105.367381 L277.687686,105.367381 C276.96163,105.464767 276.283784,105.173573 275.703325,104.639878 Z M437.536302,46.8667535 C432.640001,44.259555 427.167579,42.9077208 421.263187,42.9077208 L398.222224,42.9077208 L398.222224,46.4322285 L400.478495,46.4322285 C401.342434,46.4322285 402.110434,46.7702352 402.878434,47.5427188 C403.598706,48.2668469 403.982465,49.0878789 403.982465,49.9566397 L403.982465,101.907765 C403.982465,102.776526 403.598706,103.597558 402.878434,104.321686 C402.158645,105.045814 401.342434,105.431984 400.478495,105.431984 L398.222224,105.431984 L398.222224,108.956684 L421.263187,108.956684 C427.167579,108.956684 432.640001,107.60485 437.536302,104.997603 C442.432121,102.390357 446.416754,98.5276975 449.296875,93.6034339 C452.176995,88.6786882 453.664784,82.7400668 453.664784,75.9804134 C453.664784,69.2212421 452.176995,63.3308316 449.296875,58.357875 C446.368543,53.3367075 442.432121,49.5222593 437.536302,46.8667535 Z M444.400573,75.8839916 C444.400573,82.0641497 443.296543,87.2781609 441.136212,91.4787786 C438.976362,95.6793962 436.09576,98.8174452 432.543579,100.845679 C428.99188,102.87343 425.055459,103.887306 420.831218,103.887306 L416.175007,103.887306 C415.311067,103.887306 414.543067,103.549347 413.775067,102.776526 C413.054796,102.052398 412.671037,101.231848 412.671037,100.362605 L412.671037,51.357167 C412.671037,50.4879241 413.007067,49.7155851 413.775067,48.942764 C414.494856,48.218636 415.311067,47.8324183 416.175007,47.8324183 L420.831218,47.8324183 C425.055459,47.8324183 428.99188,48.8463422 432.543579,50.8740936 C436.09576,52.9018449 438.976362,56.040376 441.136212,60.2405115 C443.296543,64.4893401 444.400573,69.7520444 444.400573,75.8839916 Z M508.128663,79.4086921 C505.99774,76.9460782 501.885349,74.8701159 497.049793,73.7593362 C503.727006,70.4279615 507.159623,65.7447525 507.159623,59.7097093 C507.159623,56.4265455 506.291827,53.4813402 504.546591,50.9705154 C502.806177,48.4601727 500.337778,46.4322285 497.194426,45.0320386 C494.046253,43.631897 490.367759,42.9077208 486.207157,42.9077208 L460.126012,42.9077208 L460.126012,46.4322285 L462.206795,46.4322285 C463.077485,46.4322285 463.851752,46.7702352 464.626019,47.5427188 C465.352076,48.2668469 465.73921,49.0878789 465.73921,49.9566397 L465.73921,101.907765 C465.73921,102.776526 465.352076,103.597558 464.626019,104.321686 C463.900445,105.045814 463.077485,105.431984 462.206795,105.431984 L459.932204,105.431984 L459.932204,108.956684 L488.241658,108.956684 C492.546893,108.956684 496.562863,108.232556 500.193145,106.783818 C503.823428,105.335562 506.725725,103.211389 508.808437,100.410816 C510.934539,97.6107258 512,94.1824471 512,90.2233662 C511.951789,85.9745376 510.693484,82.3534152 508.128663,79.4086921 Z M475.659089,102.824737 C474.933032,102.100609 474.545899,101.280059 474.545899,100.410816 L474.545899,77.090711 L488.000603,77.090711 C492.739737,77.090711 496.370019,78.2979125 498.886629,80.7118333 C501.403239,83.1262363 502.661544,86.2642852 502.661544,90.1269443 C502.661544,92.4444434 502.078192,94.7137315 501.017552,96.7896938 C499.90388,98.9143491 498.255066,100.604142 496.032543,101.907765 C493.853409,103.211389 491.143955,103.887306 488.000603,103.887306 L478.078313,103.887306 C477.207624,103.887306 476.433356,103.549347 475.659089,102.824737 Z M474.594592,72.1177543 L474.594592,51.4053779 C474.594592,50.536135 474.933032,49.763796 475.7073,48.9909749 C476.433356,48.2668469 477.255835,47.8806774 478.127006,47.8806774 L484.514953,47.8806774 C489.109454,47.8806774 492.498682,49.039668 494.629605,51.260263 C496.755706,53.5295512 497.821168,56.4265455 497.821168,59.9994569 C497.821168,63.6687902 496.803917,66.6139954 494.822448,68.8345905 C492.836158,71.0074568 489.837439,72.1177543 485.86968,72.1177543 L474.594592,72.1177543 Z M208.270708,63.8254757 C204.57293,61.8044738 200.443183,60.745762 195.977405,60.745762 C191.629148,60.745762 187.55376,61.7037785 183.973319,63.6643155 L183.684102,63.8254757 C179.986324,65.8459955 177.057028,68.7810764 174.896215,72.4860858 C172.735401,76.1910951 171.630889,80.5218823 171.630889,85.3333323 C171.630889,90.1447824 172.735401,94.4755695 174.896215,98.1805789 C177.057028,101.885588 179.986324,104.820669 183.684102,106.841671 C187.381879,108.862191 191.511627,109.920903 195.977405,109.920903 C200.325662,109.920903 204.401049,108.962886 207.981491,107.002794 L208.270708,106.841671 C211.968486,104.820669 214.897781,101.885588 217.058595,98.1805789 C219.219408,94.4755695 220.323921,90.1447824 220.323921,85.3333323 C220.323921,80.5218823 219.219408,76.1910951 217.058595,72.4860858 C214.897781,68.7810764 211.968486,65.8459955 208.270708,63.8254757 Z M211.824335,85.3333323 C211.824335,91.2517051 210.383793,96.0631552 207.502226,99.5275921 C204.669352,102.992029 200.779695,104.772458 195.977405,104.772458 C191.261344,104.772458 187.424682,103.055048 184.605356,99.7115754 L184.452584,99.5275921 C181.571017,96.0631552 180.130475,91.2517051 180.130475,85.3333323 C180.130475,79.5225663 181.51911,74.7788372 184.296837,71.3293763 L184.452584,71.1390726 C187.285458,67.6746357 191.175597,65.8942064 195.977405,65.8942064 C200.779695,65.8942064 204.669352,67.6746357 207.502226,71.1390726 C210.383793,74.6035095 211.824335,79.4149595 211.824335,85.3333323 Z M378.455263,63.8254757 C374.757486,61.8044738 370.627738,60.745762 366.16196,60.745762 C361.813703,60.745762 357.738316,61.7037785 354.157874,63.6643155 L353.868657,63.8254757 C350.170879,65.8459955 347.241584,68.7810764 345.08077,72.4860858 C342.919957,76.1910951 341.815445,80.5218823 341.815445,85.3333323 C341.815445,90.1447824 342.919957,94.4755695 345.08077,98.1805789 C347.241584,101.885588 350.170879,104.820669 353.868657,106.841671 C357.566435,108.862191 361.696183,109.920903 366.16196,109.920903 C370.510218,109.920903 374.585605,108.962886 378.166046,107.002794 L378.455263,106.841671 C382.153041,104.820669 385.082337,101.885588 387.24315,98.1805789 C389.403964,94.4755695 390.508476,90.1447824 390.508476,85.3333323 C390.508476,80.5218823 389.403964,76.1910951 387.24315,72.4860858 C385.082337,68.7810764 382.10483,65.8459955 378.455263,63.8254757 Z M382.00889,85.3333323 C382.00889,91.2517051 380.567866,96.0631552 377.686781,99.5275921 C374.853425,102.992029 370.963768,104.772458 366.16196,104.772458 C361.445425,104.772458 357.60922,103.055048 354.789911,99.7115754 L354.637139,99.5275921 C351.755572,96.0631552 350.31503,91.2517051 350.31503,85.3333323 C350.31503,79.4752319 351.703665,74.777116 354.481392,71.3293294 L354.637139,71.1390726 C357.470013,67.6746357 361.35967,65.8942064 366.16196,65.8942064 C370.963768,65.8942064 374.853425,67.6746357 377.686781,71.1390726 C380.520137,74.6035095 382.00889,79.4149595 382.00889,85.3333323 Z M309.822677,60.745762 C305.953268,60.745762 302.423264,61.5672761 299.231219,63.2107864 C296.039174,64.8542968 293.524492,67.0782666 291.734903,69.9299427 C289.945795,72.7334078 289.026895,75.8757957 289.026895,79.2110273 C289.026895,82.2078182 289.703777,84.9630724 291.106232,87.428579 C292.460477,89.7971816 294.298277,91.7786505 296.619633,93.4221609 L289.703777,102.800149 C288.833087,103.960104 288.736665,105.506711 289.365336,106.763569 C290.042217,108.068639 291.299558,108.842424 292.750707,108.842424 L294.733622,108.842424 C292.87953,110.093116 291.380984,111.565636 290.322846,113.30284 L290.187332,113.530937 C288.929991,115.609309 288.301321,117.784586 288.301321,120.008074 C288.301321,124.091066 290.074072,127.47463 293.573442,130.021288 L293.766029,130.159366 C297.345208,132.721294 302.374571,134.026364 308.709968,134.026364 C313.111144,134.026364 317.318511,133.301272 321.139226,131.899298 C324.897612,130.537849 327.971293,128.53719 330.271877,125.942843 L330.472861,125.71239 C332.84291,123.005347 334.05204,119.718326 334.05204,115.94775 C334.05204,111.98433 332.600891,109.180383 329.21552,106.473822 C326.314187,104.201641 321.767897,102.993475 316.109381,102.993475 L296.764748,102.993475 C296.735822,102.993475 296.706722,102.975946 296.68807,102.961922 L296.667844,102.944782 L296.667844,102.944782 L296.659411,102.924542 C296.648166,102.89362 296.633408,102.834586 296.667844,102.800149 L301.69769,96.0327823 C303.051935,96.6609706 304.309275,97.0476222 305.421501,97.2891589 C306.581938,97.5311778 307.887972,97.6275996 309.338639,97.6275996 C313.401373,97.6275996 317.076974,96.8060855 320.268537,95.1625752 C323.460582,93.5190648 326.023957,91.2955771 327.861757,88.4434189 C329.699076,85.6399538 330.617976,82.498048 330.617976,79.1628164 C330.617976,75.585566 328.877079,69.0597355 324.137464,65.7245039 C324.137464,65.6955774 324.154993,65.6840068 324.169017,65.6793785 L324.186157,65.676293 L324.186157,65.676293 L334.583806,66.8362478 L334.583806,62.0508317 L317.947181,62.0508317 C315.335596,61.2293175 312.627588,60.745762 309.822677,60.745762 Z M315.625825,91.0053473 C313.788025,91.9719763 311.80511,92.5037428 309.822677,92.5037428 C306.58242,92.5037428 303.728816,91.343788 301.310556,89.0720894 C298.892778,86.7999086 297.683648,83.464677 297.683648,79.2110273 C297.683648,74.9573776 298.892778,71.6216639 301.310556,69.3499653 C303.728816,67.0782666 306.58242,65.9178297 309.822677,65.9178297 C311.769172,65.9178297 313.626671,66.3619285 315.395598,67.2921339 L315.625825,67.4162252 C317.463626,68.3833363 318.962985,69.8817318 320.172115,71.8636828 C321.332552,73.8456338 321.961223,76.3106582 321.961223,79.2110273 C321.961223,82.1596073 321.380763,84.6246318 320.172115,86.5583719 C319.011196,88.5403229 317.463626,90.0387183 315.625825,91.0053473 Z M302.519686,108.793731 L315.625825,108.793731 C319.253215,108.793731 321.574571,109.518824 323.122142,111.065912 C324.669712,112.612518 325.443497,114.690891 325.443497,117.108187 C325.443497,120.636744 324.041042,123.537113 321.23613,125.71239 C318.430737,127.887667 314.658714,128.999411 310.016002,128.999411 C305.953268,128.999411 302.567897,128.080993 300.101426,126.340579 C297.634955,124.600646 296.377615,121.941814 296.377615,118.558371 C296.377615,116.431306 296.958074,114.449355 298.118993,112.709422 C299.27943,110.969008 300.681886,109.712149 302.519686,108.793731 Z" fill="#001E2B"></path>
+    </g>
+</svg>
diff --git a/keep/providers/mongodb_provider/__init__.py b/keep/providers/mongodb_provider/__init__.py
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/keep/providers/mongodb_provider/__init__.py
@@ -0,0 +1 @@
+
diff --git a/keep/providers/mongodb_provider/mongodb_provider.py b/keep/providers/mongodb_provider/mongodb_provider.py
new file mode 100644
index 0000000000..be0ba50875
--- /dev/null
+++ b/keep/providers/mongodb_provider/mongodb_provider.py
@@ -0,0 +1,126 @@
+import os
+from pymongo import MongoClient
+from keep.contextmanager.contextmanager import ContextManager
+from keep.providers.base.base_provider import BaseProvider
+from keep.providers.models.provider_config import ProviderConfig, ProviderScope
+import pydantic
+import dataclasses
+
+@pydantic.dataclasses.dataclass
+class MongoDBProviderAuthConfig:
+    uri: str | None = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB connection URI"}
+    )
+    username: str = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB username"}
+    )
+    password: str = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB password", "sensitive": True}
+    )
+    host: str = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB hostname"}
+    )
+    database: str = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB database name"}
+    )
+
+class MongoDBProvider(BaseProvider):
+    """Enrich alerts with data from MongoDB."""
+
+    PROVIDER_SCOPES = [
+        ProviderScope(
+            name="connect_to_server",
+            description="The user can connect to the server",
+            mandatory=True,
+            alias="Connect to the server",
+        )
+    ]
+
+    def __init__(
+        self, context_manager: ContextManager, provider_id: str, config: ProviderConfig
+    ):
+        super().__init__(context_manager, provider_id, config)
+        self.client = None
+
+    def validate_scopes(self):
+        """
+        Validates that the user has the required scopes to use the provider.
+        """
+        try:
+            client = self.__generate_client()
+            client.close()
+            scopes = {
+                "connect_to_server": True,
+            }
+        except Exception as e:
+            self.logger.exception("Error validating scopes")
+            scopes = {
+                "connect_to_server": str(e),
+            }
+        return scopes
+
+    def __generate_client(self):
+        """
+        Generates a MongoDB client.
+
+        Returns:
+            pymongo.MongoClient: MongoDB Client
+        """
+        if self.authentication_config.uri:
+            client = MongoClient(self.authentication_config.uri)
+        else:
+            client = MongoClient(
+                f"mongodb://{self.authentication_config.username}:{self.authentication_config.password}@{self.authentication_config.host}/{self.authentication_config.database}"
+            )
+        return client
+
+    def dispose(self):
+        try:
+            self.client.close()
+        except Exception:
+            self.logger.exception("Error closing MongoDB connection")
+
+    def validate_config(self):
+        """
+        Validates required configuration for MongoDB's provider.
+        """
+        self.authentication_config = MongoDBProviderAuthConfig(
+            **self.config.authentication
+        )
+
+    def _query(
+        self, query="", as_dict=False, single_row=False, **kwargs: dict
+    ) -> list | tuple:
+        """
+        Executes a query against the MongoDB database.
+
+        Returns:
+            list | tuple: list of results or single result if single_row is True
+        """
+        client = self.__generate_client()
+        database = client[self.authentication_config.database]
+        results = list(database.eval(query))
+
+        if single_row:
+            return results[0] if results else None
+
+        return results
+
+
+if __name__ == "__main__":
+    config = ProviderConfig(
+        authentication={
+            "uri": os.environ.get("MONGODB_URI"),
+            "username": os.environ.get("MONGODB_USER"),
+            "password": os.environ.get("MONGODB_PASSWORD"),
+            "host": os.environ.get("MONGODB_HOST"),
+            "database": os.environ.get("MONGODB_DATABASE"),
+        }
+    )
+    context_manager = ContextManager(
+        tenant_id="singletenant",
+        workflow_id="test",
+    )
+    mongodb_provider = MongoDBProvider(context_manager, "mongodb-prod", config)
+    results = mongodb_provider.query(query="db.collection.find({}).limit(1)")
+    print(results)


Code review comments:
diff_hunk: @@ -0,0 +1,126 @@
+import os
+from pymongo import MongoClient
+from keep.contextmanager.contextmanager import ContextManager
+from keep.providers.base.base_provider import BaseProvider
+from keep.providers.models.provider_config import ProviderConfig, ProviderScope
+import pydantic
+import dataclasses
+
+@pydantic.dataclasses.dataclass
+class MongoDBProviderAuthConfig:
+    uri: str | None = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB connection URI"}
+    )
+    username: str = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB username"}
+    )
+    password: str = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB password", "sensitive": True}
+    )
+    host: str = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB hostname"}
+    )
+    database: str = dataclasses.field(
+        metadata={"required": False, "description": "MongoDB database name"}
+    )
+
+class MongoDBProvider(BaseProvider):
+    """Enrich alerts with data from MongoDB."""
+
+    PROVIDER_SCOPES = [
+        ProviderScope(
+            name="connect_to_server",
+            description="The user can connect to the server",
+            mandatory=True,
+            alias="Connect to the server",
+        )
+    ]
+
+    def __init__(
+        self, context_manager: ContextManager, provider_id: str, config: ProviderConfig
+    ):
+        super().__init__(context_manager, provider_id, config)
+        self.client = None
+
+    def validate_scopes(self):
+        """
+        Validates that the user has the required scopes to use the provider.
+        """
+        try:
+            client = self.__generate_client()
+            client.close()
+            scopes = {
+                "connect_to_server": True,
+            }
+        except Exception as e:
+            self.logger.exception("Error validating scopes")
+            scopes = {
+                "connect_to_server": str(e),
+            }
+        return scopes
+
+    def __generate_client(self):
+        """
+        Generates a MongoDB client.
+
+        Returns:
+            pymongo.MongoClient: MongoDB Client
+        """
+        if self.authentication_config.uri:
+            client = MongoClient(self.authentication_config.uri)
+        else:
+            client = MongoClient(
+                f"mongodb://{self.authentication_config.username}:{self.authentication_config.password}@{self.authentication_config.host}/{self.authentication_config.database}"
+            )
+        return client
+
+    def dispose(self):
+        try:
+            self.client.close()
+        except Exception:
+            self.logger.exception("Error closing MongoDB connection")
+
+    def validate_config(self):
+        """
+        Validates required configuration for MongoDB's provider.
+        """
+        self.authentication_config = MongoDBProviderAuthConfig(
+            **self.config.authentication
+        )
+
+    def _query(
+        self, query="", as_dict=False, single_row=False, **kwargs: dict
+    ) -> list | tuple:
+        """
+        Executes a query against the MongoDB database.
+
+        Returns:
+            list | tuple: list of results or single result if single_row is True
+        """
+        client = self.__generate_client()
+        database = client[self.authentication_config.database]
+        results = list(database.eval(query))
path: keep/providers/mongodb_provider/mongodb_provider.py
text: @user1:
https://www.mongodb.com/docs/v4.2/reference/method/db.eval/ Eval is not supported on latest mongodb versions?