1
1
import config from "../../config.js" ;
2
2
import createClient , { Client , FetchOptions , Middleware } from "openapi-fetch" ;
3
3
import { AccessToken , ClientCredentials } from "simple-oauth2" ;
4
-
4
+ import { ApiClientError } from "./apiClientError.js" ;
5
5
import { paths , operations } from "./openapi.js" ;
6
6
7
7
const ATLAS_API_VERSION = "2025-03-12" ;
8
8
9
- export class ApiClientError extends Error {
10
- response ?: Response ;
11
-
12
- constructor ( message : string , response : Response | undefined = undefined ) {
13
- super ( message ) ;
14
- this . name = "ApiClientError" ;
15
- this . response = response ;
16
- }
17
-
18
- static async fromResponse ( response : Response , message ?: string ) : Promise < ApiClientError > {
19
- message ||= `error calling Atlas API` ;
20
- try {
21
- const text = await response . text ( ) ;
22
- return new ApiClientError ( `${ message } : [${ response . status } ${ response . statusText } ] ${ text } ` , response ) ;
23
- } catch {
24
- return new ApiClientError ( `${ message } : ${ response . status } ${ response . statusText } ` , response ) ;
25
- }
26
- }
27
- }
28
-
29
9
export interface ApiClientOptions {
30
10
credentials ?: {
31
11
clientId : string ;
@@ -79,15 +59,13 @@ export class ApiClient {
79
59
} ,
80
60
} ;
81
61
82
- constructor ( options : ApiClientOptions ) {
83
- const defaultOptions = {
84
- baseUrl : "https://cloud.mongodb.com/" ,
85
- userAgent : `AtlasMCP/${ config . version } (${ process . platform } ; ${ process . arch } ; ${ process . env . HOSTNAME || "unknown" } )` ,
86
- } ;
87
-
62
+ constructor ( options ?: ApiClientOptions ) {
88
63
this . options = {
89
- ...defaultOptions ,
90
64
...options ,
65
+ baseUrl : options ?. baseUrl || "https://cloud.mongodb.com/" ,
66
+ userAgent :
67
+ options ?. userAgent ||
68
+ `AtlasMCP/${ config . version } (${ process . platform } ; ${ process . arch } ; ${ process . env . HOSTNAME || "unknown" } )` ,
91
69
} ;
92
70
93
71
this . client = createClient < paths > ( {
@@ -138,38 +116,39 @@ export class ApiClient {
138
116
} > ;
139
117
}
140
118
141
- async listProjects ( options ?: FetchOptions < operations [ "listProjects" ] > ) {
142
- const { data } = await this . client . GET ( `/api/atlas/v2/groups` , options ) ;
119
+ // DO NOT EDIT. This is auto-generated code.
120
+ async listClustersForAllProjects ( options ?: FetchOptions < operations [ "listClustersForAllProjects" ] > ) {
121
+ const { data } = await this . client . GET ( "/api/atlas/v2/clusters" , options ) ;
143
122
return data ;
144
123
}
145
124
146
- async listProjectIpAccessLists ( options : FetchOptions < operations [ "listProjectIpAccessLists " ] > ) {
147
- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/accessList` , options ) ;
125
+ async listProjects ( options ? : FetchOptions < operations [ "listProjects " ] > ) {
126
+ const { data } = await this . client . GET ( " /api/atlas/v2/groups" , options ) ;
148
127
return data ;
149
128
}
150
129
151
- async createProjectIpAccessList ( options : FetchOptions < operations [ "createProjectIpAccessList " ] > ) {
152
- const { data } = await this . client . POST ( ` /api/atlas/v2/groups/{groupId}/accessList` , options ) ;
130
+ async createProject ( options : FetchOptions < operations [ "createProject " ] > ) {
131
+ const { data } = await this . client . POST ( " /api/atlas/v2/groups" , options ) ;
153
132
return data ;
154
133
}
155
134
156
135
async getProject ( options : FetchOptions < operations [ "getProject" ] > ) {
157
- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}` , options ) ;
136
+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}" , options ) ;
158
137
return data ;
159
138
}
160
139
161
- async listClusters ( options : FetchOptions < operations [ "listClusters " ] > ) {
162
- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/clusters` , options ) ;
140
+ async listProjectIpAccessLists ( options : FetchOptions < operations [ "listProjectIpAccessLists " ] > ) {
141
+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}/accessList" , options ) ;
163
142
return data ;
164
143
}
165
144
166
- async listClustersForAllProjects ( options ? : FetchOptions < operations [ "listClustersForAllProjects " ] > ) {
167
- const { data } = await this . client . GET ( ` /api/atlas/v2/clusters` , options ) ;
145
+ async createProjectIpAccessList ( options : FetchOptions < operations [ "createProjectIpAccessList " ] > ) {
146
+ const { data } = await this . client . POST ( " /api/atlas/v2/groups/{groupId}/accessList" , options ) ;
168
147
return data ;
169
148
}
170
149
171
- async getCluster ( options : FetchOptions < operations [ "getCluster " ] > ) {
172
- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/clusters/{clusterName}` , options ) ;
150
+ async listClusters ( options : FetchOptions < operations [ "listClusters " ] > ) {
151
+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}/clusters" , options ) ;
173
152
return data ;
174
153
}
175
154
@@ -178,13 +157,19 @@ export class ApiClient {
178
157
return data ;
179
158
}
180
159
181
- async createDatabaseUser ( options : FetchOptions < operations [ "createDatabaseUser " ] > ) {
182
- const { data } = await this . client . POST ( "/api/atlas/v2/groups/{groupId}/databaseUsers " , options ) ;
160
+ async getCluster ( options : FetchOptions < operations [ "getCluster " ] > ) {
161
+ const { data } = await this . client . GET ( "/api/atlas/v2/groups/{groupId}/clusters/{clusterName} " , options ) ;
183
162
return data ;
184
163
}
185
164
186
165
async listDatabaseUsers ( options : FetchOptions < operations [ "listDatabaseUsers" ] > ) {
187
- const { data } = await this . client . GET ( `/api/atlas/v2/groups/{groupId}/databaseUsers` , options ) ;
166
+ const { data } = await this . client . GET ( "/api/atlas/v2/groups/{groupId}/databaseUsers" , options ) ;
167
+ return data ;
168
+ }
169
+
170
+ async createDatabaseUser ( options : FetchOptions < operations [ "createDatabaseUser" ] > ) {
171
+ const { data } = await this . client . POST ( "/api/atlas/v2/groups/{groupId}/databaseUsers" , options ) ;
188
172
return data ;
189
173
}
174
+ // DO NOT EDIT. This is auto-generated code.
190
175
}
0 commit comments