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,14 +59,12 @@ export class ApiClient {
79
59
} ) ;
80
60
81
61
constructor ( options ?: ApiClientOptions ) {
82
- const defaultOptions = {
83
- baseUrl : "https://cloud.mongodb.com/" ,
84
- userAgent : `AtlasMCP/${ config . version } (${ process . platform } ; ${ process . arch } ; ${ process . env . HOSTNAME || "unknown" } )` ,
85
- } ;
86
-
87
62
this . options = {
88
- ...defaultOptions ,
89
63
...options ,
64
+ baseUrl : options ?. baseUrl || "https://cloud.mongodb.com/" ,
65
+ userAgent :
66
+ options ?. userAgent ||
67
+ `AtlasMCP/${ config . version } (${ process . platform } ; ${ process . arch } ; ${ process . env . HOSTNAME || "unknown" } )` ,
90
68
} ;
91
69
92
70
this . client = createClient < paths > ( {
@@ -136,38 +114,39 @@ export class ApiClient {
136
114
} ;
137
115
}
138
116
139
- async listProjects ( options ?: FetchOptions < operations [ "listProjects" ] > ) {
140
- const { data } = await this . client . GET ( `/api/atlas/v2/groups` , options ) ;
117
+ // DO NOT EDIT. This is auto-generated code.
118
+ async listClustersForAllProjects ( options ?: FetchOptions < operations [ "listClustersForAllProjects" ] > ) {
119
+ const { data } = await this . client . GET ( "/api/atlas/v2/clusters" , options ) ;
141
120
return data ;
142
121
}
143
122
144
- async listProjectIpAccessLists ( options : FetchOptions < operations [ "listProjectIpAccessLists " ] > ) {
145
- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/accessList` , options ) ;
123
+ async listProjects ( options ? : FetchOptions < operations [ "listProjects " ] > ) {
124
+ const { data } = await this . client . GET ( " /api/atlas/v2/groups" , options ) ;
146
125
return data ;
147
126
}
148
127
149
- async createProjectIpAccessList ( options : FetchOptions < operations [ "createProjectIpAccessList " ] > ) {
150
- const { data } = await this . client . POST ( ` /api/atlas/v2/groups/{groupId}/accessList` , options ) ;
128
+ async createProject ( options : FetchOptions < operations [ "createProject " ] > ) {
129
+ const { data } = await this . client . POST ( " /api/atlas/v2/groups" , options ) ;
151
130
return data ;
152
131
}
153
132
154
133
async getProject ( options : FetchOptions < operations [ "getProject" ] > ) {
155
- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}` , options ) ;
134
+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}" , options ) ;
156
135
return data ;
157
136
}
158
137
159
- async listClusters ( options : FetchOptions < operations [ "listClusters " ] > ) {
160
- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/clusters` , options ) ;
138
+ async listProjectIpAccessLists ( options : FetchOptions < operations [ "listProjectIpAccessLists " ] > ) {
139
+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}/accessList" , options ) ;
161
140
return data ;
162
141
}
163
142
164
- async listClustersForAllProjects ( options ? : FetchOptions < operations [ "listClustersForAllProjects " ] > ) {
165
- const { data } = await this . client . GET ( ` /api/atlas/v2/clusters` , options ) ;
143
+ async createProjectIpAccessList ( options : FetchOptions < operations [ "createProjectIpAccessList " ] > ) {
144
+ const { data } = await this . client . POST ( " /api/atlas/v2/groups/{groupId}/accessList" , options ) ;
166
145
return data ;
167
146
}
168
147
169
- async getCluster ( options : FetchOptions < operations [ "getCluster " ] > ) {
170
- const { data } = await this . client . GET ( ` /api/atlas/v2/groups/{groupId}/clusters/{clusterName}` , options ) ;
148
+ async listClusters ( options : FetchOptions < operations [ "listClusters " ] > ) {
149
+ const { data } = await this . client . GET ( " /api/atlas/v2/groups/{groupId}/clusters" , options ) ;
171
150
return data ;
172
151
}
173
152
@@ -176,13 +155,19 @@ export class ApiClient {
176
155
return data ;
177
156
}
178
157
179
- async createDatabaseUser ( options : FetchOptions < operations [ "createDatabaseUser " ] > ) {
180
- const { data } = await this . client . POST ( "/api/atlas/v2/groups/{groupId}/databaseUsers " , options ) ;
158
+ async getCluster ( options : FetchOptions < operations [ "getCluster " ] > ) {
159
+ const { data } = await this . client . GET ( "/api/atlas/v2/groups/{groupId}/clusters/{clusterName} " , options ) ;
181
160
return data ;
182
161
}
183
162
184
163
async listDatabaseUsers ( options : FetchOptions < operations [ "listDatabaseUsers" ] > ) {
185
- const { data } = await this . client . GET ( `/api/atlas/v2/groups/{groupId}/databaseUsers` , options ) ;
164
+ const { data } = await this . client . GET ( "/api/atlas/v2/groups/{groupId}/databaseUsers" , options ) ;
165
+ return data ;
166
+ }
167
+
168
+ async createDatabaseUser ( options : FetchOptions < operations [ "createDatabaseUser" ] > ) {
169
+ const { data } = await this . client . POST ( "/api/atlas/v2/groups/{groupId}/databaseUsers" , options ) ;
186
170
return data ;
187
171
}
172
+ // DO NOT EDIT. This is auto-generated code.
188
173
}
0 commit comments