atlas-list-db-users
Retrieve and display database users for a specific MongoDB Atlas project to manage access permissions and security settings.
Instructions
List MongoDB Atlas database users
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | Atlas project ID to filter DB users |
Implementation Reference
- The main handler function that fetches database users from MongoDB Atlas API for the specified project ID, processes the data, and returns a formatted result.protected async execute({ projectId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { const data = await this.session.apiClient.listDatabaseUsers({ params: { path: { groupId: projectId, }, }, }); if (!data?.results?.length) { return { content: [{ type: "text", text: " No database users found" }], }; } const users = data.results.map((user) => ({ username: user.username, roles: user.roles?.map((role) => ({ roleName: role.roleName, databaseName: role.databaseName, collectionName: role.collectionName, })) ?? [], scopes: user.scopes?.map((scope) => ({ type: scope.type, name: scope.name, })) ?? [], })); return { content: formatUntrustedData( `Found ${data.results.length} database users in project ${projectId}`, JSON.stringify(users) ), }; }
- Input schema definition using Zod for validating the projectId argument.export const ListDBUsersArgs = { projectId: AtlasArgs.projectId().describe("Atlas project ID to filter DB users"), }; export class ListDBUsersTool extends AtlasToolBase { public name = "atlas-list-db-users"; protected description = "List MongoDB Atlas database users"; static operationType: OperationType = "read"; protected argsShape = { ...ListDBUsersArgs, };
- src/tools/atlas/read/listDBUsers.ts:11-14 (registration)The tool class registration with name, description, operation type, and args shape used by the MCP framework to register and invoke the tool.export class ListDBUsersTool extends AtlasToolBase { public name = "atlas-list-db-users"; protected description = "List MongoDB Atlas database users"; static operationType: OperationType = "read";
- src/tools/atlas/tools.ts:7-7 (registration)Re-export of the tool class for aggregation in the atlas tools module.export { ListDBUsersTool } from "./read/listDBUsers.js";
- src/tools/index.ts:7-11 (registration)Central registry where all tool classes, including AtlasTools containing ListDBUsersTool, are collected into AllTools array for use in MCP.export const AllTools: ToolClass[] = Object.values({ ...MongoDbTools, ...AtlasTools, ...AtlasLocalTools, });