> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corsair.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB Atlas plugin

> The Atlas Administration API v2 (489 operations): organizations, projects, clusters and flex clusters, database users and custom roles, IP access lists, backups, snapshots and restores, Atlas Search indexes and nodes, Stream Processing, Data Federation, online archive, private endpoints and peering, monitoring, logs, performance advisor, alerts, teams, users, service accounts and API keys, invoices and more.

Use **MongoDB Atlas** through Corsair: one client, typed API calls.

Connect with a service account (Organization > Access Manager >
Applications > Service Accounts): store it as `clientId:clientSecret`
(`mdb_sa_id_...:mdb_sa_sk_...`) or as the JSON
`{ "clientId": "mdb_sa_id_...", "clientSecret": "mdb_sa_sk_..." }`. The plugin trades it at `/api/oauth/token` for a bearer
token (cached until a minute before it expires). A programmatic API key
works too, as `publicKey:privateKey`; Atlas wants those with HTTP Digest
authentication, which the plugin does. Add the IP addresses the calls come
from to the credential's API access list if your organization requires
one, and give it the roles the calls need (Organization Owner or Project
Owner covers most).

* **Ids.** Atlas calls a project a group: `groupId` is the project id
  (`projects.listGroups`), `orgId` the organization's
  (`organizations.listOrgs`). Clusters, users and indexes go by name.
* **Versions.** Every Atlas route is versioned by media type; each
  operation is pinned to the newest version the spec offers and sends it as
  `Accept: application/vnd.atlas.<date>+json`.
* **Lists** page with `pageNum` (1-based) and `itemsPerPage` (the plugin
  sends 100 when it is left out) and return `{ results, totalCount, links }`.
* **Downloads** (database logs, invoices as CSV) come back as files.
* **Risk.** Reads are `read`. Deletes, anything that starts billed
  infrastructure (clusters, search nodes, stream workspaces and processors,
  data federation, private endpoints, peering, online archive, snapshots),
  restores, failover and outage tests, invitations, new keys and service
  accounts, and organization-level changes are `destructive`; other writes
  are `write`.
* Not wrapped: the 53 operations the spec marks deprecated (each has a
  newer replacement in the plugin).

**What you get:**

* 489 typed API operations

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/mongodbatlas better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/mongodbatlas better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/mongodbatlas better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/mongodbatlas better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { mongodbatlas } from '@corsair-dev/mongodbatlas';

export const corsair = createCorsair({
	plugins: [
		mongodbatlas(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the MongoDB Atlas API key before the first call: `pnpm corsair setup --plugin=mongodbatlas --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> mongodbatlas()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'mongodbatlas',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**List the clusters in a project**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.mongodbatlas.api.clusters.listClusters({ groupId: '5f43e7f0a1b2c3d4e5f60718' });
```

**Allow an IP range to reach a project**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.mongodbatlas.api.projectIpAccessList.createAccessListEntry({
	groupId: '5f43e7f0a1b2c3d4e5f60718',
	body: [{ cidrBlock: '203.0.113.0/24', comment: 'Office' }],
});
```

See the full list on the [API](https://docs.corsair.dev/plugins/mongodbatlas/api.md) page.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/mongodbatlas/api.md)
>
> Every `mongodbatlas.api.*` operation with input and output types.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.