@@ -11,15 +11,28 @@ export class CreateDBUserTool extends AtlasToolBase {
1111 projectId : z . string ( ) . describe ( "Atlas project ID" ) ,
1212 username : z . string ( ) . describe ( "Username for the new user" ) ,
1313 password : z . string ( ) . describe ( "Password for the new user" ) ,
14- roles : z . array ( z . object ( {
15- roleName : z . string ( ) . describe ( "Role name" ) ,
16- databaseName : z . string ( ) . describe ( "Database name" ) . default ( "admin" ) ,
17- collectionName : z . string ( ) . describe ( "Collection name" ) . optional ( ) ,
18- } ) ) . describe ( "Roles for the new user" ) ,
19- clusters : z . array ( z . string ( ) ) . describe ( "Clusters to assign the user to, leave empty for access to all clusters" ) . optional ( ) ,
14+ roles : z
15+ . array (
16+ z . object ( {
17+ roleName : z . string ( ) . describe ( "Role name" ) ,
18+ databaseName : z . string ( ) . describe ( "Database name" ) . default ( "admin" ) ,
19+ collectionName : z . string ( ) . describe ( "Collection name" ) . optional ( ) ,
20+ } )
21+ )
22+ . describe ( "Roles for the new user" ) ,
23+ clusters : z
24+ . array ( z . string ( ) )
25+ . describe ( "Clusters to assign the user to, leave empty for access to all clusters" )
26+ . optional ( ) ,
2027 } ;
2128
22- protected async execute ( { projectId, username, password, roles, clusters } : ToolArgs < typeof this . argsShape > ) : Promise < CallToolResult > {
29+ protected async execute ( {
30+ projectId,
31+ username,
32+ password,
33+ roles,
34+ clusters,
35+ } : ToolArgs < typeof this . argsShape > ) : Promise < CallToolResult > {
2336 await this . ensureAuthenticated ( ) ;
2437
2538 const input = {
@@ -32,18 +45,18 @@ export class CreateDBUserTool extends AtlasToolBase {
3245 username,
3346 password,
3447 roles : roles as unknown as DatabaseUserRole [ ] ,
35- scopes : clusters ?. length ? clusters . map ( cluster => ( {
36- type : "CLUSTER" ,
37- name : cluster ,
38- } ) ) : undefined ,
48+ scopes : clusters ?. length
49+ ? clusters . map ( ( cluster ) => ( {
50+ type : "CLUSTER" ,
51+ name : cluster ,
52+ } ) )
53+ : undefined ,
3954 } as CloudDatabaseUser ;
40-
55+
4156 await this . apiClient ! . createDatabaseUser ( projectId , input ) ;
4257
4358 return {
44- content : [
45- { type : "text" , text : `User "${ username } " created sucessfully.` } ,
46- ] ,
59+ content : [ { type : "text" , text : `User "${ username } " created sucessfully.` } ] ,
4760 } ;
4861 }
4962}
@@ -52,12 +65,14 @@ function formatRoles(roles?: DatabaseUserRole[]) {
5265 if ( ! roles ?. length ) {
5366 return "N/A" ;
5467 }
55- return roles . map ( role => `${ role . roleName } @${ role . databaseName } ${ role . collectionName ? `:${ role . collectionName } ` : "" } ` ) . join ( ", " ) ;
68+ return roles
69+ . map ( ( role ) => `${ role . roleName } @${ role . databaseName } ${ role . collectionName ? `:${ role . collectionName } ` : "" } ` )
70+ . join ( ", " ) ;
5671}
5772
5873function formatScopes ( scopes ?: UserScope [ ] ) {
5974 if ( ! scopes ?. length ) {
6075 return "All" ;
6176 }
62- return scopes . map ( scope => `${ scope . type } :${ scope . name } ` ) . join ( ", " ) ;
77+ return scopes . map ( ( scope ) => `${ scope . type } :${ scope . name } ` ) . join ( ", " ) ;
6378}
0 commit comments